Class 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 Detail

      • 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.
      • 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 object
        op2 - A Number object
        Returns:
        A new NumberProperty object holding an object which represents op1 mod op2.
        Throws:
        PropertyException - If either operand is null.