public interface TokenParser
T-Plan Robot Enterprise, (C) 2009-2022 T-Plan Limited. All rights reserved.
Modifier and Type | Field and Description |
---|---|
static String |
FILE_PATH_SEPARATOR
Common OS-independent file path separator.
|
Modifier and Type | Method and Description |
---|---|
String |
buttonToString(int button)
Convert a
MouseEvent button constant to a TPR string one. |
String |
colorArrayToString(Color[] c)
Convert an array of colors to a semicolon separated list of HTML-style
color representation.
|
String |
colorToString(Color c)
Convert color to HTML-style RGB string.
|
String |
dimensionToString(Dimension d)
Convert dimensions to a string.
|
Object |
evaluateNumericExpression(String expression,
Class resultType)
Evaluate a numeric or boolean expression.
|
Object |
evaluateNumericExpression(String expression,
Class resultType,
ScriptingContext context)
Evaluate a numeric or boolean expression.
|
String |
fileListToString(File[] files)
Convert a list of files to the semicolon separated string format
understood by TPR scripts.
|
String |
fileListToString(File[] files,
File defaultPath)
Convert a list of files to the semicolon separated string format
understood by TPR scripts.
|
String |
fileListToString(File[] files,
File defaultPath,
boolean forceRelative)
Convert a list of files to the semicolon separated string format
understood by TPR scripts.
|
ExpressionEvaluator |
getEvaluator()
Get the numeric and boolean expression evaluator.
|
String |
modifiersToString(int modifiers)
Convert extended key event modifiers to the TPR format.
|
Map<String,String> |
parse(String params)
Parse the argument string into a map of [param, value] pairs.
|
Map<String,String> |
parse(String params,
List<String> v)
Parse the argument string into a map of [param, value] pairs.
|
Map<String,String> |
parse(String params,
List<String> v,
boolean throwExceptionOnErrors,
int[] errorOffset)
Parse the argument string for parameters and parameter-value pairs.
|
Map<String,String> |
parse(String params,
List<String> v,
boolean throwExceptionOnErrors,
int[] errorOffset,
boolean originalValues)
Parse the argument string for parameters and parameter-value pairs.
|
Map<String,String> |
parse(String params,
List<String> v,
List<int[]> l) |
LinkedHashMap<String,Object> |
parse2map(String command) |
Boolean |
parseBoolean(Object obj,
String paramName)
Parse a boolean number.
|
Color |
parseColor(String s)
Parse an HTML-style RGB color.
|
Color[] |
parseColorArray(String s)
Parse a list of semicolon separated colors in the HTML format.
|
String |
parseCommandName(String command)
Get the command name (the first word) from the argument command line.
|
Dimension |
parseDimension(Object obj,
Dimension defaults,
String paramName,
ScriptingContext ctx)
Parse dimension (the [width, height] value pair) from the argument
object.
|
File[] |
parseFileList(String fileList)
Parse file list from the TPR semicolon separated format.
|
File[] |
parseFileList(String fileList,
File defaultPath)
Parse file list from the TPR semicolon separated format.
|
List<String> |
parseForValues(String values)
Parse a white space separated list of values (tokens).
|
Number |
parseInteger(Object obj,
String paramName)
Parse an integer number.
|
Number |
parseInteger(Object obj,
String paramName,
ScriptingContext ctx)
Parse an integer number.
|
int |
parseKeyLocation(String location)
Convert TPR specified key location to the
KeyEvent one. |
int |
parseModifiers(String modifiers)
Parse the key modifiers.
|
int |
parseMouseButton(String button)
Parse the mouse button.
|
Number |
parseNumber(Object obj,
String paramName)
Parse a number.
|
Number |
parseNumber(Object obj,
String paramName,
ScriptingContext ctx)
Parse a number.
|
Map<String,String> |
parseParameters(String command)
Parse parameters from a command line.
|
Map<String,String> |
parseParameters(String command,
List v)
Parse parameters from a command line.
|
Map<String,String> |
parseParameters(String command,
List v,
boolean returnOriginalValues)
Parse parameters from a command line.
|
String |
parseParameterString(String command)
Get the parameter substring from a command line.
|
Number |
parsePercentage(Object obj,
String paramName)
Parse a percentage such as "23.5%".
|
Number |
parsePercentage(Object obj,
String paramName,
ScriptingContext ctx)
Parse a number which may be terminated with a percent sign '%'.
|
RelativePoint |
parsePoint(Object obj,
String paramName)
Parse a point from the argument object.
|
RelativePoint |
parsePoint(Object obj,
String paramName,
ScriptingContext ctx)
Parse a point from the argument object.
|
Map<String,String> |
parsePointParams(String s,
String paramName)
Parse point parameters from the argument object.
|
Rectangle |
parseRectangle(Object obj,
Rectangle defaults,
String paramName)
Parse a rectangle from the argument object.
|
Rectangle |
parseRectangle(Object obj,
Rectangle defaults,
String paramName,
ScriptingContext ctx)
Parse a rectangle from the argument object.
|
Rectangle |
parseRectangle(Object obj,
String paramName)
Parse a rectangle from the argument object.
|
Map<String,String> |
parseRectangleParams(String s,
String paramName)
Parse rectangle parameters from the argument object.
|
Number |
parseTime(Object obj,
String paramName)
Parse time from a string.The method always returns the time value in
milliseconds.
|
Number |
parseTime(Object obj,
String paramName,
Object[] components)
Parse time from a string.The method always returns the time value in
milliseconds.
|
Number |
parseTime(Object obj,
String paramName,
Object[] components,
ScriptingContext ctx)
Parse a time value.
|
String |
pointToString(Point p)
Convert the argument point to a string.
|
String |
readToken(char[] ca,
int beg)
This will read a string in quotes or just a single string.Reading stops
when the final quote is reached (quoted string) or when a space or equal
sign is reached (unquoted string).
|
String |
rectToString(Rectangle r)
Convert the argument rectangle to a string.
|
static final String FILE_PATH_SEPARATOR
Map<String,String> parse(String params)
params
- a string containing parameters.String readToken(char[] ca, int beg)
This will read a string in quotes or just a single string.Reading stops when the final quote is reached (quoted string) or when a space or equal sign is reached (unquoted string).
Examples:
ca
- the input string characters.beg
- the start offset.Map<String,String> parse(String params, List<String> v)
params
- a string containing parameters.v
- optional list to store the parameter names to. The parameters
will be stored in the same order as they are parsed.Map<String,String> parse(String params, List<String> v, boolean throwExceptionOnErrors, int[] errorOffset)
params
- the string to parse.v
- a list to store the parameter names to.throwExceptionOnErrors
- whether to throw an error on syntax error,
for example on an unescaped or a missing enclosing double quote.errorOffset
- optional output array of length=1 to store the index
of the error to. It is used only when throwExceptionOnErrors
is true.Map<String,String> parse(String params, List<String> v, boolean throwExceptionOnErrors, int[] errorOffset, boolean originalValues)
params
- the string to parse.v
- a list to store the parameter names to.throwExceptionOnErrors
- whether to throw an error on syntax error,
for example on an unescaped or a missing enclosing double quote.errorOffset
- optional output array of length=1 to store the index
of the error to. It is used only when throwExceptionOnErrors
is true.originalValues
- a flag indicating whether to fix obvious errors in
the values such as unescaped quotes.LinkedHashMap<String,Object> parse2map(String command)
Number parseNumber(Object obj, String paramName) throws SyntaxErrorException
obj
- the value to parse.paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".SyntaxErrorException
- when the value is not a number.Number parseNumber(Object obj, String paramName, ScriptingContext ctx) throws SyntaxErrorException
obj
- the value to parse.paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".ctx
- scripting context (optional). This parameter is available
since the 2.3.3 release. If the context is not null and it is a
compilation one, the method reports no error when the value contains one
or more calls of variables which are not known.SyntaxErrorException
- when the value is not a number or the
context is an execution one and the value contains an unresolved variable
call.Number parseInteger(Object obj, String paramName) throws SyntaxErrorException
obj
- the value to parse.paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".SyntaxErrorException
- when the value is not an integer.Number parseInteger(Object obj, String paramName, ScriptingContext ctx) throws SyntaxErrorException
obj
- the value to parse.paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".ctx
- scripting context (optional). This parameter is available
since the 2.3.3 release. If the context is not null and it is a
compilation one, the method reports no error when the value contains one
or more calls of variables which are not known.SyntaxErrorException
- when the value is not an integer or the
context is an execution one and the value contains an unresolved variable
call.Boolean parseBoolean(Object obj, String paramName) throws SyntaxErrorException
obj
- the value to parse.paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".SyntaxErrorException
- when the value is not a boolean.Number parsePercentage(Object obj, String paramName) throws SyntaxErrorException
obj
- the value to parse.paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".SyntaxErrorException
- when the value is not a valid percentage.Number parsePercentage(Object obj, String paramName, ScriptingContext ctx) throws SyntaxErrorException
obj
- the value to parse.paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".ctx
- scripting context (optional). This parameter is available
since the 2.3.3 release. If the context is not null and it is a
compilation one, the method reports no error when the value contains one
or more calls of variables which are not known.SyntaxErrorException
- when the value is not a number or the
context is an execution one and the value contains an unresolved variable
call.Number parseTime(Object obj, String paramName) throws SyntaxErrorException
obj
- an object containing time (it may be a String or Number). See
the
parseTime(java.lang.Object, java.lang.String, java.lang.Object[], com.tplan.robot.scripting.ScriptingContext)
method for details on the supported time formats.paramName
- parameter name (to be mentioned in the eventually thrown
exception)SyntaxErrorException
- when the argument
has a wrong syntax.NumberFormatException
- when the string doesn't comply with the
format.Number parseTime(Object obj, String paramName, Object[] components) throws SyntaxErrorException
obj
- an object containing time (it may be a String or Number). See
the
parseTime(java.lang.Object, java.lang.String, java.lang.Object[], com.tplan.robot.scripting.ScriptingContext)
method for details on the supported time formats.paramName
- parameter name (to be mentioned in the eventually thrown
exception)components
- optional input-output array (length=3 or higher) to
store the parsed number (components[0]), time unit (components[1]) and
the unit factor used to convert the number to milliseconds
(components[2]).SyntaxErrorException
- on a syntax error.NumberFormatException
- when the string doesn't comply with the
format.Number parseTime(Object obj, String paramName, Object[] components, ScriptingContext ctx) throws SyntaxErrorException
obj
- the value to parse.paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".components
- optional input-output array (length=3 or higher) to
store the parsed number (components[0]), time unit (components[1]) and
the unit factor used to convert the number to milliseconds
(components[2]).ctx
- scripting context (optional). This parameter is available
since the 2.3.3 release. If the context is not null and it is a
compilation one, the method reports no error when the value contains one
or more calls of variables which are not known.SyntaxErrorException
- when the value is not a valid time value or
the context is an execution one and the value contains an unresolved
variable call.Map<String,String> parsePointParams(String s, String paramName) throws SyntaxErrorException
s
- a value to parse from, for example "x:0,y:36".paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".SyntaxErrorException
- when the value is not a valid point.RelativePoint parsePoint(Object obj, String paramName) throws SyntaxErrorException
obj
- a value to parse from, for example "x:0,y:36".paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".SyntaxErrorException
- when the value is not a valid point.RelativePoint parsePoint(Object obj, String paramName, ScriptingContext ctx) throws SyntaxErrorException
obj
- a value to parse from, for example "x:0,y:36".paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".ctx
- a script context.SyntaxErrorException
- when the value is not a valid point.Map<String,String> parseRectangleParams(String s, String paramName) throws SyntaxErrorException
s
- a value to parse from, for example "x:0,y:0,w:100,h:100".paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".SyntaxErrorException
- when the value is not a valid rectangle.Rectangle parseRectangle(Object obj, Rectangle defaults, String paramName) throws SyntaxErrorException
obj
- a value to parse from, for example "x:0,y:0,w:100,h:100".defaults
- optional screen dimensions. They are used to evaluate
percentage values. For example, if "defaults=x:0,y:0,w:600,h:800" and the
argument rectangle is "x:10%,y:0,w:50%,h:800" it will be resolved as
"x:60,y:0,w:300,h:800".paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".SyntaxErrorException
- when the value is not a valid rectangle.
variable call.Rectangle parseRectangle(Object obj, Rectangle defaults, String paramName, ScriptingContext ctx) throws SyntaxErrorException
obj
- a value to parse from, for example "x:0,y:0,w:100,h:100".defaults
- optional screen dimensions. They are used to evaluate
percentage values. For example, if "defaults=x:0,y:0,w:600,h:800" and the
argument rectangle is "x:10%,y:0,w:50%,h:800" it will be resolved as
"x:60,y:0,w:300,h:800".paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".ctx
- scripting context (optional). This parameter is available
since the 2.3.3 release. If the context is not null and it is a
compilation one, the method reports no error when the value contains one
or more calls of variables which are not known.SyntaxErrorException
- when the value is not a valid rectangle or
the context is an execution one and the value contains an unresolved
variable call.Rectangle parseRectangle(Object obj, String paramName) throws SyntaxErrorException
obj
- a value to parse from, for example "x:0,y:0,w:100,h:100".paramName
- parameter name (optional). If it is specified and
parsing fails the method will throw an exception saying something like
"Parameter 'paramname' parsing failed".SyntaxErrorException
- when the value is not a valid rectangle.
variable call.Dimension parseDimension(Object obj, Dimension defaults, String paramName, ScriptingContext ctx) throws SyntaxErrorException
obj
- an object to parse from.defaults
- the default dimensions to use if the argument object uses
percentages.paramName
- name of the parameter (will be used in the text of
eventually thrown exception).ctx
- a context (optional).SyntaxErrorException
- when the argument object does not represent
valid dimensions.int parseMouseButton(String button) throws SyntaxErrorException
button
- the button to parse. The TPR language supports three button
types which will be parsed as follows:
MouseEvent.BUTTON1
,MouseEvent.BUTTON2
,MouseEvent.BUTTON3
.MouseEvent
compliant mouse button code.SyntaxErrorException
- when the argument is not a valid button
type.int parseModifiers(String modifiers) throws SyntaxErrorException
modifiers
- the value to parse. The TPR language supports three
modifiers which will be parsed as follows:
InputEvent.ALT_MASK
,InputEvent.SHIFT_MASK
,InputEvent.CTRL_MASK
.InputEvent.ALT_MASK
| InputEvent.SHIFT_MASK
.InputEvent
compatible modifier mask.SyntaxErrorException
- when the argument is not a valid modifier or
a combination of modifiers.String rectToString(Rectangle r)
r
- a rectangle.String dimensionToString(Dimension d)
d
- dimensions.String pointToString(Point p)
p
- the point to convert to string.String parseCommandName(String command)
command
- a command line (command plus arguments and parameters).String parseParameterString(String command)
command
- a command line (command plus arguments and parameters).Map<String,String> parseParameters(String command)
command
- a command line (command plus arguments and parameters).Map<String,String> parseParameters(String command, List v)
command
- a command line (command plus arguments and parameters).v
- if not null it will be populated with the parameter names in the
order they are parsed.Map<String,String> parseParameters(String command, List v, boolean returnOriginalValues)
command
- a command line (command plus arguments and parameters).v
- if not null it will be populated with the parameter names in the
order they are parsed.returnOriginalValues
- a flag indicating whether to fix obvious
errors in the values such as unescaped quotes.Object evaluateNumericExpression(String expression, Class resultType, ScriptingContext context)
expression
- a numeric or a boolean expression.resultType
- the desired result type such as Boolean.class,
Double.class or Integer.class.context
- a script context.Object evaluateNumericExpression(String expression, Class resultType)
expression
- a numeric or a boolean expression.resultType
- the desired result type such as Boolean.class,
Double.class or Integer.class.String modifiersToString(int modifiers)
modifiers
- modifiers returned by
InputEvent.getModifiersEx()
.int parseKeyLocation(String location) throws SyntaxErrorException
KeyEvent
one.location
- a TPR location constant, one of "location, standard,
numpad, left".KeyEvent
location constant.SyntaxErrorException
- on an unknown argument.String buttonToString(int button)
MouseEvent
button constant to a TPR string one.button
- a button returned by MouseEvent.getButton()
.String fileListToString(File[] files, File defaultPath, boolean forceRelative)
files
- one or more file paths.defaultPath
- if populated the method converts files to relative
paths.forceRelative
- if true and the default path is provided the method
will convert all file paths to relative ones. If false and the path is
provided it will convert to relative only files contained within that
path.String fileListToString(File[] files, File defaultPath)
files
- one or more file paths.defaultPath
- if populated the method converts files contained
within that path to relative paths.String fileListToString(File[] files)
files
- one or more file paths.File[] parseFileList(String fileList)
fileList
- a TPR file list.File[] parseFileList(String fileList, File defaultPath)
fileList
- a TPR file list.defaultPath
- if provided then any relative paths in the argument
list will be resolved against it.String colorToString(Color c)
c
- a color.String colorArrayToString(Color[] c)
c
- a color array.colorToString(java.awt.Color)
method for details on the color
format.Color parseColor(String s)
s
- HTM-style color argument. Each of the R, G, B components must be
specified as 2-character hexadecimal number in this specific order. The
string may be optionally prefixed with the hash character '#'. Examples
of valid colors are "ffffff" or "#ffffff" (white), "ff0000" or "#ff0000"
(red), "000000" or "#000000" (black) etc. If the argument doesn't meet
the required format, the method throws an IllegalArgumentException.Color[] parseColorArray(String s)
s
- semicolon separated list of colors. See the
parseColor(java.lang.String)
method for details on the color
format.List<String> parseForValues(String values)
Parse a white space separated list of values (tokens). A token containing spaces must be enclosed in escaped double quotes. Any double escaped double quote will be converted to a double quote. For example, an argument like "USA \"South Africa\" \"\" \"United Kingdom (\\\"UK\\\")\"" will produce [ "USA", "South Africa", "", "United Kingdom (\"UK\")" ].
This method was introduced in 3.0.1 to support conversion of the TPR 'for' statement iterating over a set of values to Java.
values
- a list of values.ExpressionEvaluator getEvaluator()