Package org.apache.fop.fo.expr
Class PropertyParser
- java.lang.Object
-
- org.apache.fop.fo.expr.PropertyTokenizer
-
- org.apache.fop.fo.expr.PropertyParser
-
public final class PropertyParser extends PropertyTokenizer
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
Fields Modifier and Type Field Description private static java.util.HashMap
FUNCTION_TABLE
private PropertyInfo
propInfo
private static java.lang.String
RELUNIT
-
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
Constructors Modifier Constructor Description private
PropertyParser(java.lang.String propExpr, PropertyInfo pInfo)
Private constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private Property
evalAddition(Numeric op1, Numeric op2)
Evaluate an addition operation.private Property
evalDivide(Numeric op1, Numeric op2)
Evaluate a division operation.private Property
evalModulo(java.lang.Number op1, java.lang.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
expectRpar()
Checks that the current token is a right parenthesis and throws an exception if this isn't the case.static Property
parse(java.lang.String expr, PropertyInfo propInfo)
Public entrypoint to the Property expression parser.private Property
parseAdditiveExpr()
Try to parse an addition or subtraction expression and return the resulting Property.(package private) Property[]
parseArgs(Function function)
Parse a comma separated list of function arguments.private Property
parseMultiplicativeExpr()
Try to parse a multiply, divide or modulo expression and return the resulting Property.private Property
parsePrimaryExpr()
Try to parse a primary expression and return the resulting Property.private Property
parseProperty()
Parse the property expression described in the instance variables.private Property
parseUnaryExpr()
Try to parse a unary minus expression and return the resulting Property.-
Methods inherited from class org.apache.fop.fo.expr.PropertyTokenizer
next
-
-
-
-
Field Detail
-
propInfo
private PropertyInfo propInfo
-
RELUNIT
private static final java.lang.String RELUNIT
- See Also:
- Constant Field Values
-
FUNCTION_TABLE
private static final java.util.HashMap FUNCTION_TABLE
-
-
Constructor Detail
-
PropertyParser
private PropertyParser(java.lang.String propExpr, PropertyInfo pInfo)
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 Detail
-
parse
public static Property parse(java.lang.String expr, PropertyInfo propInfo) throws PropertyException
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
private Property parseProperty() throws PropertyException
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
private Property parseAdditiveExpr() throws PropertyException
Try to parse an addition or subtraction expression and return the resulting Property.- Throws:
PropertyException
-
parseMultiplicativeExpr
private Property parseMultiplicativeExpr() throws PropertyException
Try to parse a multiply, divide or modulo expression and return the resulting Property.- Throws:
PropertyException
-
parseUnaryExpr
private Property parseUnaryExpr() throws PropertyException
Try to parse a unary minus expression and return the resulting Property.- Throws:
PropertyException
-
expectRpar
private void expectRpar() throws PropertyException
Checks that the current token is a right parenthesis and throws an exception if this isn't the case.- Throws:
PropertyException
-
parsePrimaryExpr
private Property parsePrimaryExpr() throws PropertyException
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
Property[] parseArgs(Function function) throws PropertyException
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
private Property evalAddition(Numeric op1, Numeric op2) throws PropertyException
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
private Property evalSubtraction(Numeric op1, Numeric op2) throws PropertyException
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
private Property evalNegate(Numeric op) throws PropertyException
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
private Property evalMultiply(Numeric op1, Numeric op2) throws PropertyException
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
private Property evalDivide(Numeric op1, Numeric op2) throws PropertyException
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
private Property evalModulo(java.lang.Number op1, java.lang.Number op2) throws PropertyException
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.
-
-