Package org.apache.fop.fo.expr
Class PropertyParser
java.lang.Object
org.apache.fop.fo.expr.PropertyTokenizer
org.apache.fop.fo.expr.PropertyParser
Class to parse XSL-FO property expressions.
This class is heavily based on the epxression parser in James Clark's
XT, an XSLT processor.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final HashMap
private PropertyInfo
private static final String
Fields inherited from class org.apache.fop.fo.expr.PropertyTokenizer
currentToken, currentTokenValue, currentUnitLength, TOK_COLORSPEC, TOK_COMMA, TOK_DIV, TOK_EOF, TOK_FLOAT, TOK_FUNCTION_LPAR, TOK_INTEGER, TOK_LITERAL, TOK_LPAR, TOK_MINUS, TOK_MOD, TOK_MULTIPLY, TOK_NCNAME, TOK_NUMBER, TOK_NUMERIC, TOK_PERCENT, TOK_PLUS, TOK_RPAR
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
PropertyParser
(String propExpr, PropertyInfo pInfo) Private constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate Property
evalAddition
(Numeric op1, Numeric op2) Evaluate an addition operation.private Property
evalDivide
(Numeric op1, Numeric op2) Evaluate a division operation.private Property
evalModulo
(Number op1, Number op2) Evaluate a modulo operation.private Property
evalMultiply
(Numeric op1, Numeric op2) Evaluate a multiplication operation.private Property
evalNegate
(Numeric op) Evaluate a unary minus operation.private Property
evalSubtraction
(Numeric op1, Numeric op2) Evaluate a subtraction operation.private void
Checks that the current token is a right parenthesis and throws an exception if this isn't the case.static Property
parse
(String expr, PropertyInfo propInfo) Public entrypoint to the Property expression parser.private Property
Try to parse an addition or subtraction expression and return the resulting Property.(package private) Property[]
Parse a comma separated list of function arguments.private Property
Try to parse a multiply, divide or modulo expression and return the resulting Property.private Property
Try to parse a primary expression and return the resulting Property.private Property
Parse the property expression described in the instance variables.private Property
Try to parse a unary minus expression and return the resulting Property.Methods inherited from class org.apache.fop.fo.expr.PropertyTokenizer
next
-
Field Details
-
propInfo
-
RELUNIT
- See Also:
-
FUNCTION_TABLE
-
-
Constructor Details
-
PropertyParser
Private constructor. Called by the static parse() method.- Parameters:
propExpr
- The specified value (attribute on the xml element).pInfo
- A PropertyInfo object representing the context in which the property expression is to be evaluated.
-
-
Method Details
-
parse
Public entrypoint to the Property expression parser.- Parameters:
expr
- The specified value (attribute on the xml element).propInfo
- A PropertyInfo object representing the context in which the property expression is to be evaluated.- Returns:
- A Property object holding the parsed result.
- Throws:
PropertyException
- If the "expr" cannot be parsed as a Property.
-
parseProperty
Parse the property expression described in the instance variables. Note: If the property expression String is empty, a StringProperty object holding an empty String is returned.- Returns:
- A Property object holding the parsed result.
- Throws:
PropertyException
- If the "expr" cannot be parsed as a Property.
-
parseAdditiveExpr
Try to parse an addition or subtraction expression and return the resulting Property.- Throws:
PropertyException
-
parseMultiplicativeExpr
Try to parse a multiply, divide or modulo expression and return the resulting Property.- Throws:
PropertyException
-
parseUnaryExpr
Try to parse a unary minus expression and return the resulting Property.- Throws:
PropertyException
-
expectRpar
Checks that the current token is a right parenthesis and throws an exception if this isn't the case.- Throws:
PropertyException
-
parsePrimaryExpr
Try to parse a primary expression and return the resulting Property. A primary expression is either a parenthesized expression or an expression representing a primitive Property datatype, such as a string literal, an NCname, a number or a unit expression, or a function call expression.- Throws:
PropertyException
-
parseArgs
Parse a comma separated list of function arguments. Each argument may itself be an expression. This method consumes the closing right parenthesis of the argument list.- Parameters:
function
- The function object for which the arguments are collected.- Returns:
- An array of Property objects representing the arguments found.
- Throws:
PropertyException
- If the number of arguments found isn't equal to the number expected or if another argument parsing error occurs.
-
evalAddition
Evaluate an addition operation. If either of the arguments is null, this means that it wasn't convertible to a Numeric value.- Parameters:
op1
- A Numeric object (Number or Length-type object)op2
- A Numeric object (Number or Length-type object)- Returns:
- A new NumericProperty object holding an object which represents the sum of the two operands.
- Throws:
PropertyException
- If either operand is null.
-
evalSubtraction
Evaluate a subtraction operation. If either of the arguments is null, this means that it wasn't convertible to a Numeric value.- Parameters:
op1
- A Numeric object (Number or Length-type object)op2
- A Numeric object (Number or Length-type object)- Returns:
- A new NumericProperty object holding an object which represents the difference of the two operands.
- Throws:
PropertyException
- If either operand is null.
-
evalNegate
Evaluate a unary minus operation. If the argument is null, this means that it wasn't convertible to a Numeric value.- Parameters:
op
- A Numeric object (Number or Length-type object)- Returns:
- A new NumericProperty object holding an object which represents the negative of the operand (multiplication by *1).
- Throws:
PropertyException
- If the operand is null.
-
evalMultiply
Evaluate a multiplication operation. If either of the arguments is null, this means that it wasn't convertible to a Numeric value.- Parameters:
op1
- A Numeric object (Number or Length-type object)op2
- A Numeric object (Number or Length-type object)- Returns:
- A new NumericProperty object holding an object which represents the product of the two operands.
- Throws:
PropertyException
- If either operand is null.
-
evalDivide
Evaluate a division operation. If either of the arguments is null, this means that it wasn't convertible to a Numeric value.- Parameters:
op1
- A Numeric object (Number or Length-type object)op2
- A Numeric object (Number or Length-type object)- Returns:
- A new NumericProperty object holding an object which represents op1 divided by op2.
- Throws:
PropertyException
- If either operand is null.
-
evalModulo
Evaluate a modulo operation. If either of the arguments is null, this means that it wasn't convertible to a Number value.- Parameters:
op1
- A Number objectop2
- A Number object- Returns:
- A new NumberProperty object holding an object which represents op1 mod op2.
- Throws:
PropertyException
- If either operand is null.
-