Class DOMParserUtil


  • public class DOMParserUtil
    extends java.lang.Object
    Class used to provide parsing methods
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static java.util.stream.Stream<org.w3c.dom.Node> asStream​(org.w3c.dom.NodeList nodeList)
      Return a Stream out of the given NodeList.
      static java.lang.String cleanupNodes​(java.lang.String fullXml, java.lang.String containerNodeName, java.lang.String nodeToRemoveName)
      This method remove the nodeToRemoveName Nodes from all the containerNodeName Elements found inside the given fullXml
      static void cleanupNodes​(org.w3c.dom.Document document, java.lang.String containerNodeName, java.lang.String nodeToRemoveName)
      This method remove the nodeToRemoveName Nodes from all the containerNodeName Elements found inside the given fullXml
      static java.util.Map<org.w3c.dom.Node,​org.w3c.dom.Node> createNestedNodes​(org.w3c.dom.Document document, java.lang.String mainContainerNodeName, java.lang.String containerNodeName, java.lang.String childNodeName, java.lang.String nodeContent)
      Create childNodeName nodes in all containerNodeNames presents in all mainContainerNodes of the document
      static org.w3c.dom.Node createNodeAndAppend​(org.w3c.dom.Node containerNode, java.lang.String nodeToCreateName, java.lang.String nodeContent)
      Create a nodeToCreateName Node and appends it inside containerNode.
      static org.w3c.dom.Node createNodeAtPosition​(org.w3c.dom.Node containerNode, java.lang.String nodeToCreateName, java.lang.String nodeContent, java.lang.Integer position)
      Create a nodeToCreateName Node inside containerNode.
      static java.util.Map<org.w3c.dom.Node,​org.w3c.dom.Node> createNodes​(org.w3c.dom.Document document, java.lang.String containerNodeName, java.lang.String childNodeName, java.lang.String nodeContent)
      Create childNodeName nodes in all containerNodeName presents in the document
      static java.lang.String getAttributeValue​(org.w3c.dom.Node containerNode, java.lang.String attributeName)  
      static java.util.Map<org.w3c.dom.Node,​java.lang.String> getAttributeValues​(org.w3c.dom.Document document, java.lang.String attributeName)
      Return a Map where the key is any Node inside the given document and the value is the node value of the attribute with the given attributeName
      static java.util.Map<org.w3c.dom.Node,​java.lang.String> getAttributeValues​(org.w3c.dom.Document document, java.lang.String containerNodeName, java.lang.String attributeName)
      Return a Map where the key is the Node with the given containerNodeName and the value is the node value of the attribute with the given attributeName It returns an empty map if such attribute does not exists
      static java.util.List<org.w3c.dom.Node> getChildrenNodesList​(org.w3c.dom.Node node, java.lang.String childNodeName)  
      static java.util.Map<org.w3c.dom.Node,​java.util.List<org.w3c.dom.Node>> getChildrenNodesMap​(java.lang.String fullXml, java.lang.String containerNodeName, java.lang.String childNodeName)
      Get all childNodeName nodes in all containerNodeNames presents in fullXml
      static java.util.Map<org.w3c.dom.Node,​java.util.List<org.w3c.dom.Node>> getChildrenNodesMap​(org.w3c.dom.Document document, java.lang.String containerNodeName, java.lang.String childNodeName)
      Get all childNodeName nodes in all containerNodeNames presents in document
      static java.util.Map<org.w3c.dom.Node,​java.util.List<org.w3c.dom.Node>> getChildrenNodesMap​(org.w3c.dom.Node node, java.lang.String containerNodeName, java.lang.String childNodeName)  
      static org.w3c.dom.Document getDocument​(java.lang.String xml)  
      static java.util.List<org.w3c.dom.Node> getNestedChildrenNodesList​(org.w3c.dom.Document document, java.lang.String grandParentNodeName, java.lang.String parentNodeName, java.lang.String childNodeName)  
      static java.util.List<org.w3c.dom.Node> getNestedChildrenNodesList​(org.w3c.dom.Node node, java.lang.String containerName, java.lang.String childNodeName)  
      static java.util.Map<org.w3c.dom.Node,​java.util.List<org.w3c.dom.Node>> getNestedChildrenNodesMap​(org.w3c.dom.Document document, java.lang.String mainContainerNodeName, java.lang.String containerNodeName, java.lang.String childNodeName)
      Get all childNodeName nodes in all containerNodeNames presents in all mainContainerNodeNames of the document
      static java.lang.String getString​(org.w3c.dom.Document toRead)  
      protected static void populateAttributeValuesMap​(org.w3c.dom.Node node, java.lang.String attributeName, java.util.Map<org.w3c.dom.Node,​java.lang.String> toPopulate)
      Recursively populate the given Map
      static java.lang.String replaceNodeName​(org.w3c.dom.Document document, java.lang.String containerNodeName, java.lang.String childNodeNameToReplace, java.lang.String childNodeNameReplacement)
      Replace all childNodeNameToReplace nodes in all containerNodeNames presents in document with childNodeNameReplacement
      static void replaceNodeText​(org.w3c.dom.Document document, java.lang.String containerNodeName, java.lang.String nodeName, java.lang.String toReplace, java.lang.String replacement)
      Replace the text content of the given nodeName inside the given containerNodeName.
      static void setAttributeValue​(org.w3c.dom.Document document, java.lang.String containerNodeName, java.lang.String attributeName, java.lang.String attributeValue)  
      • Methods inherited from class java.lang.Object

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

      • cleanupNodes

        public static java.lang.String cleanupNodes​(java.lang.String fullXml,
                                                    java.lang.String containerNodeName,
                                                    java.lang.String nodeToRemoveName)
                                             throws java.lang.Exception
        This method remove the nodeToRemoveName Nodes from all the containerNodeName Elements found inside the given fullXml
        Parameters:
        fullXml -
        containerNodeName -
        nodeToRemoveName -
        Returns:
        Throws:
        java.lang.Exception
      • cleanupNodes

        public static void cleanupNodes​(org.w3c.dom.Document document,
                                        java.lang.String containerNodeName,
                                        java.lang.String nodeToRemoveName)
        This method remove the nodeToRemoveName Nodes from all the containerNodeName Elements found inside the given fullXml
        Parameters:
        document -
        containerNodeName -
        nodeToRemoveName -
      • replaceNodeText

        public static void replaceNodeText​(org.w3c.dom.Document document,
                                           java.lang.String containerNodeName,
                                           java.lang.String nodeName,
                                           java.lang.String toReplace,
                                           java.lang.String replacement)
        Replace the text content of the given nodeName inside the given containerNodeName. The replace happen only if the given nodeName text is equals to toReplace
        Parameters:
        document -
        containerNodeName -
        nodeName -
        toReplace -
        replacement -
      • replaceNodeName

        public static java.lang.String replaceNodeName​(org.w3c.dom.Document document,
                                                       java.lang.String containerNodeName,
                                                       java.lang.String childNodeNameToReplace,
                                                       java.lang.String childNodeNameReplacement)
                                                throws javax.xml.transform.TransformerException
        Replace all childNodeNameToReplace nodes in all containerNodeNames presents in document with childNodeNameReplacement
        Parameters:
        document -
        containerNodeName -
        childNodeNameToReplace -
        childNodeNameReplacement -
        Returns:
        Throws:
        javax.xml.transform.TransformerException
      • getAttributeValue

        public static java.lang.String getAttributeValue​(org.w3c.dom.Node containerNode,
                                                         java.lang.String attributeName)
      • getAttributeValues

        public static java.util.Map<org.w3c.dom.Node,​java.lang.String> getAttributeValues​(org.w3c.dom.Document document,
                                                                                                java.lang.String containerNodeName,
                                                                                                java.lang.String attributeName)
        Return a Map where the key is the Node with the given containerNodeName and the value is the node value of the attribute with the given attributeName It returns an empty map if such attribute does not exists
        Parameters:
        document -
        containerNodeName -
        attributeName -
        Returns:
      • getAttributeValues

        public static java.util.Map<org.w3c.dom.Node,​java.lang.String> getAttributeValues​(org.w3c.dom.Document document,
                                                                                                java.lang.String attributeName)
        Return a Map where the key is any Node inside the given document and the value is the node value of the attribute with the given attributeName

        It returns an empty map no Node contains such attribute

        Parameters:
        document -
        attributeName -
        Returns:
      • setAttributeValue

        public static void setAttributeValue​(org.w3c.dom.Document document,
                                             java.lang.String containerNodeName,
                                             java.lang.String attributeName,
                                             java.lang.String attributeValue)
      • createNodes

        public static java.util.Map<org.w3c.dom.Node,​org.w3c.dom.Node> createNodes​(org.w3c.dom.Document document,
                                                                                         java.lang.String containerNodeName,
                                                                                         java.lang.String childNodeName,
                                                                                         java.lang.String nodeContent)
        Create childNodeName nodes in all containerNodeName presents in the document
        Parameters:
        document -
        containerNodeName -
        childNodeName -
        nodeContent -
        Returns:
      • createNestedNodes

        public static java.util.Map<org.w3c.dom.Node,​org.w3c.dom.Node> createNestedNodes​(org.w3c.dom.Document document,
                                                                                               java.lang.String mainContainerNodeName,
                                                                                               java.lang.String containerNodeName,
                                                                                               java.lang.String childNodeName,
                                                                                               java.lang.String nodeContent)
        Create childNodeName nodes in all containerNodeNames presents in all mainContainerNodes of the document
        Parameters:
        document -
        containerNodeName -
        childNodeName -
        nodeContent -
        Returns:
      • createNodeAndAppend

        public static org.w3c.dom.Node createNodeAndAppend​(org.w3c.dom.Node containerNode,
                                                           java.lang.String nodeToCreateName,
                                                           java.lang.String nodeContent)
        Create a nodeToCreateName Node and appends it inside containerNode.
        Parameters:
        containerNode -
        nodeToCreateName -
        nodeContent -
        Returns:
      • createNodeAtPosition

        public static org.w3c.dom.Node createNodeAtPosition​(org.w3c.dom.Node containerNode,
                                                            java.lang.String nodeToCreateName,
                                                            java.lang.String nodeContent,
                                                            java.lang.Integer position)
        Create a nodeToCreateName Node inside containerNode. If nodeContent is not null, add it as text content. If position is not null, put the created node at position 0
        Parameters:
        containerNode -
        nodeToCreateName -
        nodeContent -
        position -
        Returns:
      • getChildrenNodesMap

        public static java.util.Map<org.w3c.dom.Node,​java.util.List<org.w3c.dom.Node>> getChildrenNodesMap​(java.lang.String fullXml,
                                                                                                                 java.lang.String containerNodeName,
                                                                                                                 java.lang.String childNodeName)
                                                                                                          throws java.lang.Exception
        Get all childNodeName nodes in all containerNodeNames presents in fullXml
        Parameters:
        fullXml -
        containerNodeName -
        childNodeName -
        Returns:
        Throws:
        java.lang.Exception
      • getChildrenNodesMap

        public static java.util.Map<org.w3c.dom.Node,​java.util.List<org.w3c.dom.Node>> getChildrenNodesMap​(org.w3c.dom.Document document,
                                                                                                                 java.lang.String containerNodeName,
                                                                                                                 java.lang.String childNodeName)
        Get all childNodeName nodes in all containerNodeNames presents in document
        Parameters:
        document -
        containerNodeName -
        childNodeName -
        Returns:
      • getChildrenNodesMap

        public static java.util.Map<org.w3c.dom.Node,​java.util.List<org.w3c.dom.Node>> getChildrenNodesMap​(org.w3c.dom.Node node,
                                                                                                                 java.lang.String containerNodeName,
                                                                                                                 java.lang.String childNodeName)
      • getChildrenNodesList

        public static java.util.List<org.w3c.dom.Node> getChildrenNodesList​(org.w3c.dom.Node node,
                                                                            java.lang.String childNodeName)
      • getNestedChildrenNodesMap

        public static java.util.Map<org.w3c.dom.Node,​java.util.List<org.w3c.dom.Node>> getNestedChildrenNodesMap​(org.w3c.dom.Document document,
                                                                                                                       java.lang.String mainContainerNodeName,
                                                                                                                       java.lang.String containerNodeName,
                                                                                                                       java.lang.String childNodeName)
        Get all childNodeName nodes in all containerNodeNames presents in all mainContainerNodeNames of the document
        Parameters:
        document -
        mainContainerNodeName -
        containerNodeName -
        childNodeName -
        Returns:
      • getNestedChildrenNodesList

        public static java.util.List<org.w3c.dom.Node> getNestedChildrenNodesList​(org.w3c.dom.Document document,
                                                                                  java.lang.String grandParentNodeName,
                                                                                  java.lang.String parentNodeName,
                                                                                  java.lang.String childNodeName)
      • getNestedChildrenNodesList

        public static java.util.List<org.w3c.dom.Node> getNestedChildrenNodesList​(org.w3c.dom.Node node,
                                                                                  java.lang.String containerName,
                                                                                  java.lang.String childNodeName)
      • getDocument

        public static org.w3c.dom.Document getDocument​(java.lang.String xml)
                                                throws javax.xml.parsers.ParserConfigurationException,
                                                       java.io.IOException,
                                                       org.xml.sax.SAXException
        Throws:
        javax.xml.parsers.ParserConfigurationException
        java.io.IOException
        org.xml.sax.SAXException
      • getString

        public static java.lang.String getString​(org.w3c.dom.Document toRead)
                                          throws javax.xml.transform.TransformerException
        Throws:
        javax.xml.transform.TransformerException
      • populateAttributeValuesMap

        protected static void populateAttributeValuesMap​(org.w3c.dom.Node node,
                                                         java.lang.String attributeName,
                                                         java.util.Map<org.w3c.dom.Node,​java.lang.String> toPopulate)
        Recursively populate the given Map
        Parameters:
        node -
        attributeName -
        toPopulate -
      • asStream

        protected static java.util.stream.Stream<org.w3c.dom.Node> asStream​(org.w3c.dom.NodeList nodeList)
        Return a Stream out of the given NodeList. It nodeList is null, returns an empty stream
        Parameters:
        nodeList -
        Returns: