Class DOMParserUtil
- java.lang.Object
-
- org.drools.scenariosimulation.backend.util.DOMParserUtil
-
public class DOMParserUtil extends Object
Class used to provide parsing methods
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static Stream<Node>asStream(NodeList nodeList)Return aStreamout of the givenNodeList.static StringcleanupNodes(String fullXml, String containerNodeName, String nodeToRemoveName)This method remove the nodeToRemoveNameNodes from all the containerNodeName Elements found inside the given fullXmlstatic voidcleanupNodes(Document document, String containerNodeName, String nodeToRemoveName)This method remove the nodeToRemoveNameNodes from all the containerNodeName Elements found inside the given fullXmlstatic 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 documentstatic NodecreateNodeAndAppend(Node containerNode, String nodeToCreateName, String nodeContent)Create a nodeToCreateNameNodeand appends it inside containerNode.static NodecreateNodeAtPosition(Node containerNode, String nodeToCreateName, String nodeContent, Integer position)Create a nodeToCreateNameNodeinside containerNode.static Map<Node,Node>createNodes(Document document, String containerNodeName, String childNodeName, String nodeContent)Create childNodeName nodes in all containerNodeName presents in the documentstatic StringgetAttributeValue(Node containerNode, String attributeName)static Map<Node,String>getAttributeValues(Document document, String attributeName)Return aMapwhere thekeyis anyNodeinside the given document and the value is the node value of the attribute with the given attributeNamestatic Map<Node,String>getAttributeValues(Document document, String containerNodeName, String attributeName)Return aMapwhere thekeyis theNodewith 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 existsstatic List<Node>getChildrenNodesList(Node node, String childNodeName)static Map<Node,List<Node>>getChildrenNodesMap(String fullXml, String containerNodeName, String childNodeName)Get all childNodeName nodes in all containerNodeNames presents in fullXmlstatic Map<Node,List<Node>>getChildrenNodesMap(Document document, String containerNodeName, String childNodeName)Get all childNodeName nodes in all containerNodeNames presents in documentstatic Map<Node,List<Node>>getChildrenNodesMap(Node node, String containerNodeName, String childNodeName)static DocumentgetDocument(String xml)static List<Node>getNestedChildrenNodesList(Document document, String grandParentNodeName, String parentNodeName, String childNodeName)static List<Node>getNestedChildrenNodesList(Node node, String containerName, String childNodeName)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 documentstatic StringgetString(Document toRead)protected static voidpopulateAttributeValuesMap(Node node, String attributeName, Map<Node,String> toPopulate)Recursively populate the givenMapstatic StringreplaceNodeName(Document document, String containerNodeName, String childNodeNameToReplace, String childNodeNameReplacement)Replace all childNodeNameToReplace nodes in all containerNodeNames presents in document with childNodeNameReplacementstatic voidreplaceNodeText(Document document, String containerNodeName, String nodeName, String toReplace, String replacement)Replace the text content of the given nodeName inside the givencontainerNodeName.static voidsetAttributeValue(Document document, String containerNodeName, String attributeName, String attributeValue)
-
-
-
Method Detail
-
cleanupNodes
public static String cleanupNodes(String fullXml, String containerNodeName, String nodeToRemoveName) throws Exception
This method remove the nodeToRemoveNameNodes 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 nodeToRemoveNameNodes 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 givencontainerNodeName. 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
-
getAttributeValues
public static Map<Node,String> getAttributeValues(Document document, String containerNodeName, String attributeName)
Return aMapwhere thekeyis theNodewith 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 aMapwhere thekeyis anyNodeinside the given document and the value is the node value of the attribute with the given attributeNameIt returns an empty map no
Nodecontains 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 nodeToCreateNameNodeand appends it inside containerNode.- Parameters:
containerNode-nodeToCreateName-nodeContent-- Returns:
-
createNodeAtPosition
public static Node createNodeAtPosition(Node containerNode, String nodeToCreateName, String nodeContent, Integer position)
Create a nodeToCreateNameNodeinside 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:
-
getChildrenNodesMap
public static Map<Node,List<Node>> getChildrenNodesMap(Node node, String containerNodeName, String childNodeName)
-
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)
-
getDocument
public static Document getDocument(String xml) throws ParserConfigurationException, IOException, SAXException
-
getString
public static String getString(Document toRead) throws TransformerException
- Throws:
TransformerException
-
populateAttributeValuesMap
protected static void populateAttributeValuesMap(Node node, String attributeName, Map<Node,String> toPopulate)
Recursively populate the givenMap- Parameters:
node-attributeName-toPopulate-
-
-