Class XPathImpl

  • All Implemented Interfaces:
    IXPath

    public class XPathImpl
    extends java.lang.Object
    implements IXPath
    IXPath that uses XPath to select nodes and get their value.
    Since:
    8.1.0
    Version:
    $Revision$ $Date$
    • Constructor Summary

      Constructors 
      Constructor Description
      XPathImpl​(org.w3c.dom.Node document)
      Constructor that receives the document in context
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Map<java.lang.String,​java.lang.Object> getMap​(java.lang.String xpath)
      Selects a node with the given XPath and converts it to a Map, by using IXPath.toMap(Node).
      java.util.Map<java.lang.String,​java.lang.Object> getMap​(java.lang.String xpath, org.w3c.dom.Node context)
      Selects a node with the given XPath and converts it to a Map, by using IXPath.toMap(Node).
      java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> getMaps​(java.lang.String xpath)
      Selects nodes with the given XPath and converts them to a List of Map, by using IXPath.toMap(Node) in each of these nodes.
      java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> getMaps​(java.lang.String xpath, org.w3c.dom.Node context)
      Selects nodes with the given XPath and converts them to a List of Map, by using IXPath.toMap(Node) in each of these nodes.
      java.util.List<org.w3c.dom.Node> selectNodes​(java.lang.String xpath)
      Returns a node list with the selected nodes by the given XPath using the document in context.
      java.util.List<org.w3c.dom.Node> selectNodes​(java.lang.String xpath, org.w3c.dom.Node context)
      Returns a node list with the selected nodes by the given XPath in the given context.
      org.w3c.dom.Node selectSingleNode​(java.lang.String xpath)
      Returns a single node selected by the given XPath expression using the document in context.
      org.w3c.dom.Node selectSingleNode​(java.lang.String xpath, org.w3c.dom.Node context)
      Returns a single node selected by the given XPath expression in the given context.
      java.util.Map<java.lang.String,​java.lang.Object> toMap​(org.w3c.dom.Node node)
      Returns a Map object based on the given node.
      java.lang.String valueOf​(java.lang.String xpath, org.w3c.dom.Node context)
      Returns the string representation of the evaluated XPath in the given context.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XPathImpl

        public XPathImpl​(org.w3c.dom.Node document)
        Constructor that receives the document in context
        Parameters:
        document -
        Since:
        8.1.0
    • Method Detail

      • valueOf

        public java.lang.String valueOf​(java.lang.String xpath,
                                        org.w3c.dom.Node context)
        Description copied from interface: IXPath
        Returns the string representation of the evaluated XPath in the given context.
        Specified by:
        valueOf in interface IXPath
        Parameters:
        xpath - the XPath expression.
        context - the context node.
        Returns:
        the string representation of the evaluated XPath in the given context.
      • selectNodes

        public java.util.List<org.w3c.dom.Node> selectNodes​(java.lang.String xpath,
                                                            org.w3c.dom.Node context)
        Description copied from interface: IXPath
        Returns a node list with the selected nodes by the given XPath in the given context.
        Specified by:
        selectNodes in interface IXPath
        Parameters:
        xpath - the XPath expression.
        context - the context node.
        Returns:
        a node list with the selected nodes by the given XPath.
      • selectNodes

        public java.util.List<org.w3c.dom.Node> selectNodes​(java.lang.String xpath)
        Description copied from interface: IXPath
        Returns a node list with the selected nodes by the given XPath using the document in context.
        Specified by:
        selectNodes in interface IXPath
        Parameters:
        xpath - the XPath expression.
        Returns:
        a node list with the selected nodes by the given XPath.
      • selectSingleNode

        public org.w3c.dom.Node selectSingleNode​(java.lang.String xpath,
                                                 org.w3c.dom.Node context)
        Description copied from interface: IXPath
        Returns a single node selected by the given XPath expression in the given context. If more than one node is selected, the first one is returned. If there's no such node, null is returned.
        Specified by:
        selectSingleNode in interface IXPath
        Parameters:
        xpath - the XPath expression.
        context - the context node.
        Returns:
        a single node selected by the given XPath expression
      • selectSingleNode

        public org.w3c.dom.Node selectSingleNode​(java.lang.String xpath)
        Description copied from interface: IXPath
        Returns a single node selected by the given XPath expression using the document in context. If more than one node is selected, the first one is returned. If there's no such node, null is returned.
        Specified by:
        selectSingleNode in interface IXPath
        Parameters:
        xpath - the XPath expression.
        Returns:
        a single node selected by the given XPath expression
      • toMap

        public java.util.Map<java.lang.String,​java.lang.Object> toMap​(org.w3c.dom.Node node)
        Description copied from interface: IXPath
        Returns a Map object based on the given node.

        The conversion rules are as follows:

        Elements
        A XML element node will behave depending on its nature.
        If the element node is a simple element node, then its value will become available under the node name.
        For example, the given XML node:
        <myNode>Some text<![CDATA[other text]]>another text</myNode> If the node is referenced like var myValue = myMap.myNode;, the variable myValue will have the value Some textother textanother text.
        It is important to notice that no white space will be automatically included between text and CDATA nodes.

        If the element node is a simple element node with attributes, then its value will become available under the $ object, inside the node object.
        For example, the given XML node:

        <myNode myAttribute="1">Some text<![CDATA[other text]]>another text</myNode> If the node is referenced like var myValue = myMap.myNode.$;, the variable myValue will have the value Some textother textanother text.
        It is important to notice that no white space will be automatically included between text and CDATA nodes.

        If the node is a complex node then its text (inner CDATA sections and text nodes) will not be accessible. This kind of node is simply a container for inner nodes.
        For example, the given XML node:

        <myNode>Some text<![CDATA[other text]]>another text<myOtherNode>Other node text</myOtherNode></myNode> The text of node myNode will not be accessible at all and the text of node myOtherNode will be accessible using myMap.myNode.myOtherNode.

        Another aspect of element nodes is when they are automatically wrapped in arrays. It happens in the following situations:

        • If some element node has at least one sibling node with the very same name.
        • If an element node has the attribute lumIsArray with the value true.
        • If the parent node of some element node has a name that is the concatenation of the child node with the "s" suffix and the child element node either doesn't have the lumIsArray attribute or the value of lumIsArray attribute is not false.
        • If the element node has the name row and its parent node name is data and the child element node either doesn't have the lumIsArray attribute or the value of lumIsArray attribute is not false.
        Attributes
        A XML element node attribute named myAttribute becomes available using the name $myAttribute. For example, the given XML node:
        <myNode myAttribute="someValue"/> Makes the attribute myAttribute available using myNode.$myAttribute.

        Simple element node
        Simple element node is a node that has the following aspects:
        • Has no attributes.
        • All of inner nodes are either CDATA sections or text nodes (comments are ignored).
        Simple element node with attributes
        Simple element node with attributes is a node that has the following aspects:
        • Has at least one attribute.
        • All of inner nodes are either CDATA sections or text nodes (comments are ignored).
        Simple element node value
        The value of a simple element node is the concatenation of all inner CDATA sections and text nodes.
        Complex node
        A complex node is a node that has at least one inner node that is neither a CDATA section nor a text node.
        Specified by:
        toMap in interface IXPath
        Parameters:
        node - the node to be transformed in Map.
        Returns:
        a object based on the given node.
      • getMap

        public java.util.Map<java.lang.String,​java.lang.Object> getMap​(java.lang.String xpath,
                                                                             org.w3c.dom.Node context)
        Description copied from interface: IXPath
        Selects a node with the given XPath and converts it to a Map, by using IXPath.toMap(Node). If no node could be resolved with the given XPath, null will be returned.
        Specified by:
        getMap in interface IXPath
        Parameters:
        xpath - the XPath.
        context - the context the given XPath is resolved from.
        Returns:
        the found node's map representation or null if no node matches the given XPath.
      • getMap

        public java.util.Map<java.lang.String,​java.lang.Object> getMap​(java.lang.String xpath)
        Description copied from interface: IXPath
        Selects a node with the given XPath and converts it to a Map, by using IXPath.toMap(Node). If no node could be resolved with the given XPath, null will be returned.
        Specified by:
        getMap in interface IXPath
        Parameters:
        xpath - the XPath.
        Returns:
        the found node's map representation or null if no node matches the given XPath.
      • getMaps

        public java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> getMaps​(java.lang.String xpath,
                                                                                              org.w3c.dom.Node context)
        Description copied from interface: IXPath
        Selects nodes with the given XPath and converts them to a List of Map, by using IXPath.toMap(Node) in each of these nodes. If no node could be resolved with the given XPath, an empty list will be returned.
        Specified by:
        getMaps in interface IXPath
        Parameters:
        xpath - the XPath.
        context - the context the given XPath is resolved from.
        Returns:
        the found nodes' list of maps representation.
      • getMaps

        public java.util.List<java.util.Map<java.lang.String,​java.lang.Object>> getMaps​(java.lang.String xpath)
        Description copied from interface: IXPath
        Selects nodes with the given XPath and converts them to a List of Map, by using IXPath.toMap(Node) in each of these nodes. If no node could be resolved with the given XPath, an empty list will be returned.
        Specified by:
        getMaps in interface IXPath
        Parameters:
        xpath - the XPath.
        Returns:
        the found nodes' list of maps representation.