Class DefaultXPath

    • Constructor Summary

      Constructors 
      Constructor Description
      DefaultXPath(java.lang.String text)
      Construct an XPath
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean booleanValueOf(java.lang.Object context)
      Retrieve a boolean-value interpretation of this XPath expression when evaluated against a given context.
      java.lang.Object evaluate(java.lang.Object context)
      evaluate evaluates an XPath expression and returns the result as an Object.
      protected java.lang.Object getCompareValue(Node node)
      DOCUMENT ME!
      org.jaxen.FunctionContext getFunctionContext()
      DOCUMENT ME!
      org.jaxen.NamespaceContext getNamespaceContext()
      DOCUMENT ME!
      java.lang.String getText()
      Retrieve the textual XPath string used to initialize this Object
      org.jaxen.VariableContext getVariableContext()
      DOCUMENT ME!
      protected void handleJaxenException(org.jaxen.JaxenException exception)  
      boolean matches(Node node)
      matches returns true if the given node matches the XPath expression.
      java.lang.Number numberValueOf(java.lang.Object context)
      numberValueOf evaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results is a number, or null if the result is not a number.
      protected static org.jaxen.XPath parse(java.lang.String text)  
      protected void removeDuplicates(java.util.List<Node> list, java.util.Map<Node,java.lang.Object> sortValues)
      Removes items from the list which have duplicate values
      java.util.List<Node> selectNodes(java.lang.Object context)
      selectNodes performs this XPath expression on the given Nodeor Listof Nodes instances appending all the results together into a single list.
      java.util.List<Node> selectNodes(java.lang.Object context, XPath sortXPath)
      selectNodes evaluates the XPath expression on the given Nodeor Listof Nodes and returns the result as a List of Node s sorted by the sort XPath expression.
      java.util.List<Node> selectNodes(java.lang.Object context, XPath sortXPath, boolean distinct)
      selectNodes evaluates the XPath expression on the given Nodeor Listof Nodes and returns the result as a List of Node s sorted by the sort XPath expression.
      java.lang.Object selectObject(java.lang.Object context)
      selectObject evaluates an XPath expression and returns the result as an Object.
      Node selectSingleNode(java.lang.Object context)
      selectSingleNode evaluates this XPath expression on the given Nodeor Listof Nodes and returns the result as a single Node instance.
      void setFunctionContext(org.jaxen.FunctionContext functionContext)
      Sets the function context to be used when evaluating XPath expressions
      void setNamespaceContext(org.jaxen.NamespaceContext namespaceContext)
      Sets the namespace context to be used when evaluating XPath expressions
      void setNamespaceURIs(java.util.Map<java.lang.String,java.lang.String> map)
      Sets the current NamespaceContext from a Map where the keys are the String namespace prefixes and the values are the namespace URIs.
      protected void setNSContext(java.lang.Object context)  
      void setVariableContext(org.jaxen.VariableContext variableContext)
      Sets the variable context to be used when evaluating XPath expressions
      void sort(java.util.List<Node> list)
      sort sorts the given List of Nodes using this XPath expression as a Comparator.
      void sort(java.util.List<Node> list, boolean distinct)
      sort sorts the given List of Nodes using this XPath expression as a Comparatorand optionally removing duplicates.
      protected void sort(java.util.List<Node> list, java.util.Map<Node,java.lang.Object> sortValues)
      Sorts the list based on the sortValues for each node
      java.lang.String toString()  
      java.lang.String valueOf(java.lang.Object context)
      valueOf evaluates this XPath expression and returns the textual representation of the results using the XPath string() function.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getText

        public java.lang.String getText()
        Retrieve the textual XPath string used to initialize this Object
        Specified by:
        getText in interface XPath
        Returns:
        The XPath string
      • getFunctionContext

        public org.jaxen.FunctionContext getFunctionContext()
        Description copied from interface: XPath
        DOCUMENT ME!
        Specified by:
        getFunctionContext in interface XPath
        Returns:
        the current function context
      • setFunctionContext

        public void setFunctionContext(org.jaxen.FunctionContext functionContext)
        Description copied from interface: XPath
        Sets the function context to be used when evaluating XPath expressions
        Specified by:
        setFunctionContext in interface XPath
        Parameters:
        functionContext - DOCUMENT ME!
      • getNamespaceContext

        public org.jaxen.NamespaceContext getNamespaceContext()
        Description copied from interface: XPath
        DOCUMENT ME!
        Specified by:
        getNamespaceContext in interface XPath
        Returns:
        the current namespace context
      • setNamespaceURIs

        public void setNamespaceURIs(java.util.Map<java.lang.String,java.lang.String> map)
        Description copied from interface: XPath
        Sets the current NamespaceContext from a Map where the keys are the String namespace prefixes and the values are the namespace URIs. For example:
         Map uris = new HashMap();
         uris.put("SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
         uris.put("m", "urn:xmethodsBabelFish");
         XPath xpath = document
                 .createXPath("SOAP-ENV:Envelope/SOAP-ENV:Body/m:BabelFish");
         xpath.setNamespaceURIs(uris);
         Node babelfish = xpath.selectSingleNode(document);
         
        Specified by:
        setNamespaceURIs in interface XPath
        Parameters:
        map - the map containing the namespace mappings
      • setNamespaceContext

        public void setNamespaceContext(org.jaxen.NamespaceContext namespaceContext)
        Description copied from interface: XPath
        Sets the namespace context to be used when evaluating XPath expressions
        Specified by:
        setNamespaceContext in interface XPath
        Parameters:
        namespaceContext - DOCUMENT ME!
      • getVariableContext

        public org.jaxen.VariableContext getVariableContext()
        Description copied from interface: XPath
        DOCUMENT ME!
        Specified by:
        getVariableContext in interface XPath
        Returns:
        the current variable context
      • setVariableContext

        public void setVariableContext(org.jaxen.VariableContext variableContext)
        Description copied from interface: XPath
        Sets the variable context to be used when evaluating XPath expressions
        Specified by:
        setVariableContext in interface XPath
        Parameters:
        variableContext - DOCUMENT ME!
      • evaluate

        public java.lang.Object evaluate(java.lang.Object context)
        Description copied from interface: XPath
        evaluate evaluates an XPath expression and returns the result as an Object. The object returned can either be a List of Nodeinstances, a Nodeinstance, a String or a Numberinstance depending on the XPath expression.
        Specified by:
        evaluate in interface XPath
        Parameters:
        context - is either a node or a list of nodes on which to evalute the XPath
        Returns:
        the value of the XPath expression as a Listof Node instances, a Nodeinstance, a Stringor a Numberinstance depending on the XPath expression.
      • selectObject

        public java.lang.Object selectObject(java.lang.Object context)
        Description copied from interface: XPath
        selectObject evaluates an XPath expression and returns the result as an Object. The object returned can either be a List of Nodeinstances, a Nodeinstance, a String or a Numberinstance depending on the XPath expression.
        Specified by:
        selectObject in interface XPath
        Parameters:
        context - is either a node or a list of nodes on which to evalute the XPath
        Returns:
        the value of the XPath expression as a Listof Node instances, a Nodeinstance, a Stringor a Numberinstance depending on the XPath expression.
      • selectNodes

        public java.util.List<Node> selectNodes(java.lang.Object context)
        Description copied from interface: XPath
        selectNodes performs this XPath expression on the given Nodeor Listof Nodes instances appending all the results together into a single list.
        Specified by:
        selectNodes in interface XPath
        Parameters:
        context - is either a node or a list of nodes on which to evalute the XPath
        Returns:
        the results of all the XPath evaluations as a single list
      • selectNodes

        public java.util.List<Node> selectNodes(java.lang.Object context,
                                                XPath sortXPath)
        Description copied from interface: XPath
        selectNodes evaluates the XPath expression on the given Nodeor Listof Nodes and returns the result as a List of Node s sorted by the sort XPath expression.
        Specified by:
        selectNodes in interface XPath
        Parameters:
        context - is either a node or a list of nodes on which to evalute the XPath
        sortXPath - is the XPath expression to sort by
        Returns:
        a list of Node instances
      • selectNodes

        public java.util.List<Node> selectNodes(java.lang.Object context,
                                                XPath sortXPath,
                                                boolean distinct)
        Description copied from interface: XPath
        selectNodes evaluates the XPath expression on the given Nodeor Listof Nodes and returns the result as a List of Node s sorted by the sort XPath expression.
        Specified by:
        selectNodes in interface XPath
        Parameters:
        context - is either a node or a list of nodes on which to evalute the XPath
        sortXPath - is the XPath expression to sort by
        distinct - specifies whether or not duplicate values of the sort expression are allowed. If this parameter is true then only distinct sort expressions values are included in the result
        Returns:
        a list of Node instances
      • selectSingleNode

        public Node selectSingleNode(java.lang.Object context)
        Description copied from interface: XPath
        selectSingleNode evaluates this XPath expression on the given Nodeor Listof Nodes and returns the result as a single Node instance.
        Specified by:
        selectSingleNode in interface XPath
        Parameters:
        context - is either a node or a list of nodes on which to evalute the XPath
        Returns:
        a single matching Node instance
      • valueOf

        public java.lang.String valueOf(java.lang.Object context)
        Description copied from interface: XPath
        valueOf evaluates this XPath expression and returns the textual representation of the results using the XPath string() function.
        Specified by:
        valueOf in interface XPath
        Parameters:
        context - is either a node or a list of nodes on which to evalute the XPath
        Returns:
        the string representation of the results of the XPath expression
      • numberValueOf

        public java.lang.Number numberValueOf(java.lang.Object context)
        Description copied from interface: XPath
        numberValueOf evaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results is a number, or null if the result is not a number.
        Specified by:
        numberValueOf in interface XPath
        Parameters:
        context - is either a node or a list of nodes on which to evalute the XPath
        Returns:
        the numeric result of the XPath expression or null if the result is not a number.
      • booleanValueOf

        public boolean booleanValueOf(java.lang.Object context)
        Description copied from interface: XPath
        Retrieve a boolean-value interpretation of this XPath expression when evaluated against a given context. The boolean-value of the expression is determined per the boolean(..) core function as defined in the XPath specification. This means that an expression that selects zero nodes will return false, while an expression that selects one-or-more nodes will return true.
        Specified by:
        booleanValueOf in interface XPath
        Parameters:
        context - The node, nodeset or Context object for evaluation. This value can be null
        Returns:
        The boolean-value interpretation of this expression.
      • sort

        public void sort(java.util.List<Node> list)

        sort sorts the given List of Nodes using this XPath expression as a Comparator.

        Specified by:
        sort in interface XPath
        Parameters:
        list - is the list of Nodes to sort
      • sort

        public void sort(java.util.List<Node> list,
                         boolean distinct)

        sort sorts the given List of Nodes using this XPath expression as a Comparatorand optionally removing duplicates.

        Specified by:
        sort in interface XPath
        Parameters:
        list - is the list of Nodes to sort
        distinct - if true then duplicate values (using the sortXPath for comparisions) will be removed from the List
      • matches

        public boolean matches(Node node)
        Description copied from interface: XPath
        matches returns true if the given node matches the XPath expression. To be more precise when evaluating this XPath expression on the given node the result set must include the node.
        Specified by:
        matches in interface NodeFilter
        Specified by:
        matches in interface XPath
        Parameters:
        node - DOCUMENT ME!
        Returns:
        true if the given node matches this XPath expression
      • sort

        protected void sort(java.util.List<Node> list,
                            java.util.Map<Node,java.lang.Object> sortValues)
        Sorts the list based on the sortValues for each node
        Parameters:
        list - DOCUMENT ME!
        sortValues - DOCUMENT ME!
      • removeDuplicates

        protected void removeDuplicates(java.util.List<Node> list,
                                        java.util.Map<Node,java.lang.Object> sortValues)
        Removes items from the list which have duplicate values
        Parameters:
        list - DOCUMENT ME!
        sortValues - DOCUMENT ME!
      • getCompareValue

        protected java.lang.Object getCompareValue(Node node)
        DOCUMENT ME!
        Parameters:
        node - DOCUMENT ME!
        Returns:
        the node expression used for sorting comparisons
      • parse

        protected static org.jaxen.XPath parse(java.lang.String text)
      • setNSContext

        protected void setNSContext(java.lang.Object context)
      • handleJaxenException

        protected void handleJaxenException(org.jaxen.JaxenException exception)
                                     throws XPathException
        Throws:
        XPathException