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 HashMapprivate PropertyInfoprivate static final StringFields inherited from class 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
ConstructorsModifierConstructorDescriptionprivatePropertyParser(String propExpr, PropertyInfo pInfo) Private constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate PropertyevalAddition(Numeric op1, Numeric op2) Evaluate an addition operation.private PropertyevalDivide(Numeric op1, Numeric op2) Evaluate a division operation.private PropertyevalModulo(Number op1, Number op2) Evaluate a modulo operation.private PropertyevalMultiply(Numeric op1, Numeric op2) Evaluate a multiplication operation.private PropertyevalNegate(Numeric op) Evaluate a unary minus operation.private PropertyevalSubtraction(Numeric op1, Numeric op2) Evaluate a subtraction operation.private voidChecks that the current token is a right parenthesis and throws an exception if this isn't the case.static Propertyparse(String expr, PropertyInfo propInfo) Public entrypoint to the Property expression parser.private PropertyTry to parse an addition or subtraction expression and return the resulting Property.(package private) Property[]Parse a comma separated list of function arguments.private PropertyTry to parse a multiply, divide or modulo expression and return the resulting Property.private PropertyTry to parse a primary expression and return the resulting Property.private PropertyParse the property expression described in the instance variables.private PropertyTry to parse a unary minus expression and return the resulting Property.Methods inherited from class 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.
-