Class DOMParserUtil
- java.lang.Object
-
- org.drools.scenariosimulation.backend.util.DOMParserUtil
-
public class DOMParserUtil extends java.lang.ObjectClass 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 aStreamout of the givenNodeList.static java.lang.StringcleanupNodes(java.lang.String fullXml, java.lang.String containerNodeName, java.lang.String nodeToRemoveName)This method remove the nodeToRemoveNameNodes from all the containerNodeName Elements found inside the given fullXmlstatic voidcleanupNodes(org.w3c.dom.Document document, java.lang.String containerNodeName, java.lang.String nodeToRemoveName)This method remove the nodeToRemoveNameNodes from all the containerNodeName Elements found inside the given fullXmlstatic 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 documentstatic org.w3c.dom.NodecreateNodeAndAppend(org.w3c.dom.Node containerNode, java.lang.String nodeToCreateName, java.lang.String nodeContent)Create a nodeToCreateNameNodeand appends it inside containerNode.static org.w3c.dom.NodecreateNodeAtPosition(org.w3c.dom.Node containerNode, java.lang.String nodeToCreateName, java.lang.String nodeContent, java.lang.Integer position)Create a nodeToCreateNameNodeinside 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 documentstatic java.lang.StringgetAttributeValue(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 aMapwhere thekeyis anyNodeinside the given document and the value is the node value of the attribute with the given attributeNamestatic 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 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 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 fullXmlstatic 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 documentstatic 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.DocumentgetDocument(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 documentstatic java.lang.StringgetString(org.w3c.dom.Document toRead)protected static voidpopulateAttributeValuesMap(org.w3c.dom.Node node, java.lang.String attributeName, java.util.Map<org.w3c.dom.Node,java.lang.String> toPopulate)Recursively populate the givenMapstatic java.lang.StringreplaceNodeName(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 childNodeNameReplacementstatic voidreplaceNodeText(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 givencontainerNodeName.static voidsetAttributeValue(org.w3c.dom.Document document, java.lang.String containerNodeName, java.lang.String attributeName, java.lang.String attributeValue)
-
-
-
Method Detail
-
cleanupNodes
public static java.lang.String cleanupNodes(java.lang.String fullXml, java.lang.String containerNodeName, java.lang.String nodeToRemoveName) throws java.lang.ExceptionThis method remove the nodeToRemoveNameNodes 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 nodeToRemoveNameNodes 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 givencontainerNodeName. 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.TransformerExceptionReplace 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 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 java.util.Map<org.w3c.dom.Node,java.lang.String> getAttributeValues(org.w3c.dom.Document document, java.lang.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(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 nodeToCreateNameNodeand 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 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 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.ExceptionGet 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.ParserConfigurationExceptionjava.io.IOExceptionorg.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 givenMap- Parameters:
node-attributeName-toPopulate-
-
asStream
protected static java.util.stream.Stream<org.w3c.dom.Node> asStream(org.w3c.dom.NodeList nodeList)
Return aStreamout of the givenNodeList. It nodeList isnull, returns an empty stream- Parameters:
nodeList-- Returns:
-
-