Class DOMParserUtil


  • public class DOMParserUtil
    extends Object
    Class used to provide parsing methods
    • Method Detail

      • cleanupNodes

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

        public static void cleanupNodes​(Document document,
                                        String containerNodeName,
                                        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​(Document document,
                                           String containerNodeName,
                                           String nodeName,
                                           String toReplace,
                                           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 String replaceNodeName​(Document document,
                                             String containerNodeName,
                                             String childNodeNameToReplace,
                                             String childNodeNameReplacement)
                                      throws TransformerException
        Replace all childNodeNameToReplace nodes in all containerNodeNames presents in document with childNodeNameReplacement
        Parameters:
        document -
        containerNodeName -
        childNodeNameToReplace -
        childNodeNameReplacement -
        Returns:
        Throws:
        TransformerException
      • getAttributeValue

        public static String getAttributeValue​(Node containerNode,
                                               String attributeName)
      • getAttributeValues

        public static Map<Node,​String> getAttributeValues​(Document document,
                                                                String containerNodeName,
                                                                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 Map<Node,​String> getAttributeValues​(Document document,
                                                                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​(Document document,
                                             String containerNodeName,
                                             String attributeName,
                                             String attributeValue)
      • createNodes

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

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

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

        public static Node createNodeAtPosition​(Node containerNode,
                                                String nodeToCreateName,
                                                String nodeContent,
                                                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 Map<Node,​List<Node>> getChildrenNodesMap​(String fullXml,
                                                                     String containerNodeName,
                                                                     String childNodeName)
                                                              throws Exception
        Get all childNodeName nodes in all containerNodeNames presents in fullXml
        Parameters:
        fullXml -
        containerNodeName -
        childNodeName -
        Returns:
        Throws:
        Exception
      • getChildrenNodesMap

        public static Map<Node,​List<Node>> getChildrenNodesMap​(Document document,
                                                                     String containerNodeName,
                                                                     String childNodeName)
        Get all childNodeName nodes in all containerNodeNames presents in document
        Parameters:
        document -
        containerNodeName -
        childNodeName -
        Returns:
      • getChildrenNodesList

        public static List<Node> getChildrenNodesList​(Node node,
                                                      String childNodeName)
      • getNestedChildrenNodesMap

        public static Map<Node,​List<Node>> getNestedChildrenNodesMap​(Document document,
                                                                           String mainContainerNodeName,
                                                                           String containerNodeName,
                                                                           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 List<Node> getNestedChildrenNodesList​(Document document,
                                                            String grandParentNodeName,
                                                            String parentNodeName,
                                                            String childNodeName)
      • getNestedChildrenNodesList

        public static List<Node> getNestedChildrenNodesList​(Node node,
                                                            String containerName,
                                                            String childNodeName)
      • populateAttributeValuesMap

        protected static void populateAttributeValuesMap​(Node node,
                                                         String attributeName,
                                                         Map<Node,​String> toPopulate)
        Recursively populate the given Map
        Parameters:
        node -
        attributeName -
        toPopulate -
      • asStream

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