@StableMinor(version="12.4", sinceVersion="4.0") public class XmlUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
XML_HEADER |
Constructor and Description |
---|
XmlUtil() |
Modifier and Type | Method and Description |
---|---|
static Node |
addNode(Node xmlParentNode,
String newNodeName) |
static Node |
addNode(Node xmlParentNode,
String xpathExpressionParentNode,
String newNodeName) |
static Attr |
addNodeAttr(Node xmlParentNode,
String attributeName) |
static Attr |
addNodeAttr(Node xmlParentNode,
String attributeName,
String value) |
static Node |
addNodeFromXmlString(Node node,
String xmlString) |
static Element |
addTextNode(Node xmlParentNode,
String newNodeName,
String newNodeText) |
static Element |
addTextNode(Node xmlParentNode,
String xpathExpressionParentNode,
String newNodeName,
String newNodeText) |
static Node[] |
addTextNodes(Node xmlParentNode,
String newNodesName,
String[] newNodesValue) |
static Node[] |
addTextNodes(Node xmlParentNode,
String xpathExpressionParentNode,
String newNodesName,
String[] newNodesValue) |
static boolean |
checkCondition(Node conditionNode,
String condition) |
protected static boolean |
checkCondition(String leftValue,
String rightValue,
String conditionOperator) |
static boolean |
checkSingleCondition(Node conditionNode,
String condition) |
static byte[] |
convertToUTFBytes(byte[] content)
Deprecated.
Since 4.2.0, this method is no longer used
and may be removed in the future.
|
static Node |
copyNode(Node xmlNodeFrom,
Node xmlNodeTo) |
static Node |
copyNode(Node xmlNodeFrom,
Node xmlNodeTo,
String xpathExpressionTo) |
static Node |
copyNode(Node xmlNodeFrom,
String xpathExpressionFrom,
Node xmlNodeTo) |
static Node |
copyNode(Node xmlNodeFrom,
String xpathExpressionFrom,
Node xmlNodeTo,
String xpathExpressionTo) |
static PortalException |
createPortalException(SAXException e)
Creates a PortalException based on the given SAXException.
|
static String |
encodeXml(String pStr)
Encodes a string to be used inside a XML document.
|
static Document |
getDocument(File xmlFile) |
static Document |
getDocument(HttpServletRequest request) |
static Document |
getDocument(IFile xmlFile)
Returns the
Document associated with the given file. |
static Document |
getDocument(InputStream inputStream)
Parses a XML document from an input stream.
|
static Document |
getDocument(String xmlString) |
static Document |
getDocumentFromFile(String filePath) |
static Node |
getOrCreateNode(String path,
Node parentNode) |
static String |
getTextContent(Node node) |
static DocumentBuilder |
getXmlDocumentBuilder() |
static Document |
getXMLDocumentFromString(String xml)
Deprecated.
since 4.2.0 replaced by
getDocument(String) . |
static String |
getXmlEncoding(String xmlString)
Returns the XML encoding for the xml with the given String.
|
static String |
getXmlString(Document document) |
static String |
getXmlString(Element element) |
static String |
getXmlString(Node node)
Returns the xml string representation for a node.
|
static Node |
importIntoNewDocument(Node originalNode)
Clones a node, and adopts it into a new document.
|
static void |
initializeDocumentBuilderPool(int minSize,
int maxSize,
long timeBetweenEvictionRunsMillis,
int numTestsPerEvictionRun,
int minEvictableIdleTimeMillis)
Internal use only.
|
static boolean |
isValidXmlString(String xml) |
static void |
mergeAttributes(Node destinationNode,
Node sourceNode,
boolean replace) |
static void |
mergeElements(Node destinationNode,
Node sourceNode,
boolean replace)
Merges the children elements from a node to another.
|
static boolean |
nodeExists(String xpathExpression,
Node sourceNode) |
static boolean |
readAttributeBoolean(String attributeName,
Node node) |
static boolean |
readAttributeBoolean(String attributeName,
Node node,
boolean valueForNull) |
static int |
readAttributeInt(String attributeName,
Node node,
int valueForNull)
Returns the attribute integer value in the given node.
|
static String |
readAttributeOrNodeString(Node node,
String fieldName) |
static String |
readAttributeOrNodeString(Node node,
String fieldName,
String valueForNull) |
static String |
readAttributeString(String attributeName,
Node node) |
static String |
readAttributeString(String attributeName,
Node node,
String valueForNull) |
static boolean |
readNodeBoolean(String xpathExpression,
Node sourceNode,
boolean valueForNull) |
static int |
readNodeInt(String xpathExpression,
Node sourceNode,
int valueForNull) |
static Integer |
readNodeInteger(String xpathExpression,
Node sourceNode,
Integer valueForNull) |
static String[] |
readNodesString(String xpathExpression,
Node sourceNode) |
static String |
readNodeString(String xpathExpression,
Node sourceNode) |
static String |
readNodeString(String xpathExpression,
Node sourceNode,
String valueForNull) |
static void |
replaceChildNode(Node parentNode,
Node newChildNode) |
static void |
replaceChildNode(String childNodeName,
Node node,
String xmlString) |
static Node[] |
selectAncestorNodes(String ancestorNameQuery,
Node childNode) |
static Node[] |
selectNodes(String childNameQuery,
Node parentNode) |
static Node |
selectSingleAncestorNode(String ancestorNameQuery,
Node childNode) |
static Node |
selectSingleNode(String childNameQuery,
Node parentNode) |
protected static Node |
selectSingleNodeRecursiveByName(String nodeName,
Node parentNode) |
static void |
setTextContent(Node parentNode,
String textValue) |
static Node |
writeNodeString(String xpathExpression,
Node sourceNode,
String nodeValue) |
public static final String XML_HEADER
public static void initializeDocumentBuilderPool(int minSize, int maxSize, long timeBetweenEvictionRunsMillis, int numTestsPerEvictionRun, int minEvictableIdleTimeMillis)
This method may be incompatible in future versions.
minSize
- minimum pool size.maxSize
- maximum pool size.timeBetweenEvictionRunsMillis
- the number of milliseconds to sleep between runs of the idle
object evictor thread. When non-positive, no idle object
evictor thread will be run.numTestsPerEvictionRun
- the number of objects to examine during each run of the idle
object evictor thread (if any).minEvictableIdleTimeMillis
- The minimum amount of time an object may sit idle in the pool
before it is eligable for eviction by the idle object evictor
(if any).public static DocumentBuilder getXmlDocumentBuilder() throws PortalException
PortalException
public static Document getDocument(File xmlFile) throws PortalException
PortalException
public static Document getDocument(IFile xmlFile) throws PortalException
Document
associated with the given file.xmlFile
- the XML file.Document
associated with the given file.PortalException
public static Document getDocument(HttpServletRequest request) throws Exception
Exception
public static Document getDocument(InputStream inputStream) throws SAXException, IOException
This method will read the input stream's data, but will not close it.
inputStream
- the input stream.SAXException
- if any parse errors occur.IOException
- if any I/O errors occur.IllegalArgumentException
- if inputStream
is null
.public static Document getDocument(String xmlString) throws PortalException
PortalException
public static PortalException createPortalException(SAXException e)
e
- the SAXExceptionpublic static String getXmlString(Node node) throws PortalException
node
- the node. Must be of type Document
, Element
, Text
or Comment
.PortalException
public static String getXmlString(Element element) throws PortalException
PortalException
public static String getXmlString(Document document) throws Exception
Exception
public static boolean readNodeBoolean(String xpathExpression, Node sourceNode, boolean valueForNull) throws PortalException
PortalException
public static boolean readAttributeBoolean(String attributeName, Node node) throws PortalException
PortalException
public static boolean readAttributeBoolean(String attributeName, Node node, boolean valueForNull) throws PortalException
PortalException
public static int readNodeInt(String xpathExpression, Node sourceNode, int valueForNull) throws PortalException
PortalException
public static Integer readNodeInteger(String xpathExpression, Node sourceNode, Integer valueForNull) throws PortalException
PortalException
public static String readAttributeString(String attributeName, Node node) throws PortalException
PortalException
public static int readAttributeInt(String attributeName, Node node, int valueForNull) throws PortalException
attributeName
- node
- valueForNull
- PortalException
public static String readAttributeString(String attributeName, Node node, String valueForNull) throws PortalException
PortalException
public static String readNodeString(String xpathExpression, Node sourceNode) throws PortalException
PortalException
public static String readNodeString(String xpathExpression, Node sourceNode, String valueForNull) throws PortalException
PortalException
public static String[] readNodesString(String xpathExpression, Node sourceNode) throws PortalException
PortalException
public static boolean nodeExists(String xpathExpression, Node sourceNode) throws PortalException
PortalException
public static Element addTextNode(Node xmlParentNode, String newNodeName, String newNodeText) throws PortalException
PortalException
public static Element addTextNode(Node xmlParentNode, String xpathExpressionParentNode, String newNodeName, String newNodeText) throws PortalException
PortalException
public static Node[] addTextNodes(Node xmlParentNode, String newNodesName, String[] newNodesValue) throws PortalException
PortalException
public static Node[] addTextNodes(Node xmlParentNode, String xpathExpressionParentNode, String newNodesName, String[] newNodesValue) throws Exception
Exception
public static Node addNode(Node xmlParentNode, String xpathExpressionParentNode, String newNodeName) throws PortalException
PortalException
public static Node copyNode(Node xmlNodeFrom, String xpathExpressionFrom, Node xmlNodeTo) throws Exception
Exception
public static Node copyNode(Node xmlNodeFrom, Node xmlNodeTo, String xpathExpressionTo) throws Exception
Exception
public static Node copyNode(Node xmlNodeFrom, String xpathExpressionFrom, Node xmlNodeTo, String xpathExpressionTo) throws Exception
Exception
public static Document getDocumentFromFile(String filePath) throws Exception
Exception
public static Node selectSingleAncestorNode(String ancestorNameQuery, Node childNode) throws Exception
Exception
public static Node[] selectAncestorNodes(String ancestorNameQuery, Node childNode) throws Exception
Exception
public static Node importIntoNewDocument(Node originalNode) throws PortalException
originalNode
- PortalException
public static Node selectSingleNode(String childNameQuery, Node parentNode) throws PortalException
PortalException
public static Node[] selectNodes(String childNameQuery, Node parentNode) throws PortalException
PortalException
public static boolean checkCondition(Node conditionNode, String condition) throws Exception
Exception
public static boolean checkSingleCondition(Node conditionNode, String condition) throws Exception
Exception
protected static boolean checkCondition(String leftValue, String rightValue, String conditionOperator)
protected static Node selectSingleNodeRecursiveByName(String nodeName, Node parentNode) throws Exception
Exception
@Deprecated public static Document getXMLDocumentFromString(String xml) throws PortalException
getDocument(String)
.PortalException
@Deprecated public static byte[] convertToUTFBytes(byte[] content)
public static Node getOrCreateNode(String path, Node parentNode) throws PortalException
PortalException
public static Node writeNodeString(String xpathExpression, Node sourceNode, String nodeValue) throws PortalException
PortalException
public static String readAttributeOrNodeString(Node node, String fieldName) throws PortalException
PortalException
public static String readAttributeOrNodeString(Node node, String fieldName, String valueForNull) throws PortalException
PortalException
public static void replaceChildNode(Node parentNode, Node newChildNode) throws Exception
Exception
public static void replaceChildNode(String childNodeName, Node node, String xmlString) throws PortalException
PortalException
public static Node addNodeFromXmlString(Node node, String xmlString) throws PortalException
PortalException
public static void mergeAttributes(Node destinationNode, Node sourceNode, boolean replace) throws PortalException
PortalException
public static void mergeElements(Node destinationNode, Node sourceNode, boolean replace) throws PortalException
destinationNode
- the destination node, where the elements will be
appended or replaced.sourceNode
- the source node, where the elements will be copied from.replace
- if true, elements with the same name will be replaced;
if false they will not be copied if an element in the destinationNode
with the same name already exists.PortalException
public static String encodeXml(String pStr)
public static String getXmlEncoding(String xmlString)
The encoding is read from the XML declaration.
xmlString
- the xml.public static boolean isValidXmlString(String xml)
LumisXP 12.4.0.200625 - Copyright © 2006–2020 Lumis EIP Tecnologia da Informação LTDA. All Rights Reserved.