public class XMLUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String[] |
ENTITIES |
static java.lang.String[] |
SPECIAL_CHARS |
static int |
STORAGE_MODE_AGRESSIVE |
static int |
STORAGE_MODE_NORMAL |
static int |
STORAGE_MODE_OPTIMIZED |
Constructor and Description |
---|
XMLUtil() |
Modifier and Type | Method and Description |
---|---|
static org.w3c.dom.Node |
assertNodeName(org.w3c.dom.Node a_node,
java.lang.String a_strExpectedName)
Throws an XMLParseException if the given XML node has not the expected
name or if it is null.
|
static void |
assertNotNull(org.w3c.dom.Node a_node)
Throws an XMLParseException if the given XML node is null.
|
static void |
assertNotNull(org.w3c.dom.Node a_node,
java.lang.String a_attribute) |
static org.w3c.dom.Element |
createChildElement(org.w3c.dom.Node a_parent,
java.lang.String a_nodeName)
Creates an element and appends it to a root node.
|
static org.w3c.dom.Element |
createChildElementWithValue(org.w3c.dom.Node a_parent,
java.lang.String a_nodeName,
java.lang.String a_value)
Creates an element with a given value and appends it to a root node.
|
static org.w3c.dom.Document |
createDocument()
Creates a new Document.
|
static org.w3c.dom.Document |
createDocumentFromElement(org.w3c.dom.Element a_elem) |
static byte[] |
createDocumentStructure() |
static java.lang.String |
filterXMLChars(java.lang.String a_source)
filters out the chars &, <, >and " with the unicode entities.
|
static void |
filterXMLCharsForAnObject(java.lang.Object anObject) |
static org.w3c.dom.Document |
formatHumanReadable(org.w3c.dom.Document a_doc)
Reformats an XML document into a human readable format.
|
static org.w3c.dom.Element |
formatHumanReadable(org.w3c.dom.Element a_element)
Reformats an XML element into a human readable format.
|
static org.w3c.dom.Node |
getDocumentElement(org.w3c.dom.Node a_node)
If the current node is of the type XML document, this method returns the
document element.
|
static org.w3c.dom.NodeList |
getElementsByTagName(org.w3c.dom.Node a_elementName,
java.lang.String a_tagName) |
static org.w3c.dom.Node |
getFirstChildByName(org.w3c.dom.Node a_node,
java.lang.String a_childname)
Returns the child node of the given node with the given name.
|
static org.w3c.dom.Node |
getFirstChildByName(org.w3c.dom.Node a_node,
java.lang.String a_childname,
boolean a_bDeepSearch) |
static org.w3c.dom.Node |
getFirstChildByNameUsingDeepSearch(org.w3c.dom.Node a_node,
java.lang.String a_childname)
Returns the child node of the given node with the given name.
|
static org.w3c.dom.Node |
getLastChildByName(org.w3c.dom.Node n,
java.lang.String name) |
static org.w3c.dom.Node |
getNextSibling(org.w3c.dom.Node a_node)
Returns the next sibling of a given node or null, if there is no next
node.
|
static org.w3c.dom.Node |
getNextSiblingByName(org.w3c.dom.Node a_node,
java.lang.String a_siblingName)
Returns the first next sibling node of the given node with the given
name.
|
static int |
getStorageMode() |
static java.lang.String |
getXmlElementContainerName(java.lang.Class a_xmlEncodableClass)
Uses Java reflection to get the static XML_ELEMENT_CONTAINER_NAME field
contents if present in the given class.
|
static java.lang.String |
getXmlElementName(java.lang.Class a_xmlEncodableClass)
Uses Java reflection to get the static XML_ELEMENT_NAME field contents if
present in the given class.
|
static org.w3c.dom.Node |
importNode(org.w3c.dom.Document a_doc,
org.w3c.dom.Node a_source,
boolean a_bDeep)
Returns a copy of the source node with the given document as owner
document This method is needed as nodes cannot be appended to foreign
documents by default, but only to the document by which they have been
created.
|
static boolean |
parseAttribute(org.w3c.dom.Node a_node,
java.lang.String a_attribute,
boolean a_default)
Returns the value of the specified attribute of an XML element as
boolean.
|
static double |
parseAttribute(org.w3c.dom.Node a_node,
java.lang.String a_attribute,
double a_default)
Returns the value of the specified attribute of an XML element as double.
|
static int |
parseAttribute(org.w3c.dom.Node a_node,
java.lang.String a_attribute,
int a_default)
Returns the value of the specified attribute of an XML element as int.
|
static long |
parseAttribute(org.w3c.dom.Node a_node,
java.lang.String a_attribute,
long a_default)
Returns the value of the specified attribute of an XML element as long.
|
static java.lang.String |
parseAttribute(org.w3c.dom.Node a_node,
java.lang.String a_attribute,
java.lang.String a_default)
Returns the value of the specified attribute of an XML element as String.
|
static java.math.BigInteger |
parseValue(org.w3c.dom.Element elem,
java.math.BigInteger defValue) |
static boolean |
parseValue(org.w3c.dom.Node a_node,
boolean a_defaultValue)
Returns the value of the specified XML node as boolean.
|
static double |
parseValue(org.w3c.dom.Node a_node,
double a_defaultValue)
Returns the value of the specified XML node as double.
|
static int |
parseValue(org.w3c.dom.Node a_node,
int a_defaultValue)
Returns the value of the specified XML node as int.
|
static long |
parseValue(org.w3c.dom.Node a_node,
long a_defaultValue)
Returns the value of the specified XML node as long.
|
static java.lang.String |
parseValue(org.w3c.dom.Node a_node,
java.lang.String a_defaultValue)
Gets the content of an Element or Text Node.
|
static void |
printXmlEncodable(IXMLEncodable xmlobject) |
static java.lang.String |
quoteXML(java.lang.String text) |
static org.w3c.dom.Element[] |
readElementsByTagName(java.io.File a_file,
java.lang.String a_tagName)
Loads all elements under the root elements that have the specified tag
name.
|
static org.w3c.dom.Document |
readXMLDocument(java.io.File a_file)
Reads an XML document from a file.
|
static org.w3c.dom.Document |
readXMLDocument(org.xml.sax.InputSource a_inputSource)
Reads an XML document from an input source.
|
static org.w3c.dom.Document |
readXMLDocument(java.io.InputStream a_inputStream)
Reads an XML document from an input stream.
|
static org.w3c.dom.Document |
readXMLDocument(java.io.Reader a_reader)
Reads an XML document from a Reader.
|
static void |
removeComments(org.w3c.dom.Node a_node)
Removes all comments and empty lines from a node.
|
static java.lang.String |
restoreFilteredXMLChars(java.lang.String a_source) |
static void |
setAttribute(org.w3c.dom.Element a_element,
java.lang.String a_attribute,
boolean a_value)
Creates and sets an attribute with a boolean value to an XML element.
|
static void |
setAttribute(org.w3c.dom.Element a_element,
java.lang.String a_attribute,
double a_value)
Creates and sets an attribute with a double value to an XML element.
|
static void |
setAttribute(org.w3c.dom.Element a_element,
java.lang.String a_attribute,
int a_value)
Creates and sets an attribute with an int value to an XML element.
|
static void |
setAttribute(org.w3c.dom.Element a_element,
java.lang.String a_attribute,
long a_value)
Creates and sets an attribute with a long value to an XML element.
|
static void |
setAttribute(org.w3c.dom.Element a_element,
java.lang.String a_attribute,
java.lang.String a_value)
Creates and sets an attribute with a String value to an XML element.
|
static void |
setStorageMode(int a_storageMode)
Sets the storage mode for XML documents.
|
static void |
setValue(org.w3c.dom.Element elem,
java.math.BigInteger i) |
static void |
setValue(org.w3c.dom.Node a_node,
boolean a_bValue)
Inserts a boolean value into an XML node.
|
static void |
setValue(org.w3c.dom.Node a_node,
double a_value)
Inserts a double precision floating point value into an XML node.
|
static void |
setValue(org.w3c.dom.Node a_node,
int a_value)
Inserts an int value into an XML node.
|
static void |
setValue(org.w3c.dom.Node a_node,
long a_value)
Inserts a long value into an XML node.
|
static void |
setValue(org.w3c.dom.Node a_node,
java.lang.String a_value)
Inserts a String value into an XML node.
|
static java.lang.String |
stripNewlineFromHash(java.lang.String hashValue)
Takes a SHA-1 hash value, and if it is followed by a newline ("\n"),
strips off the newline so it will be usable as a pure hashvalue
Call this after reading a hash value from an xml node value
|
static byte[] |
toByteArray(org.w3c.dom.Node a_inputNode)
Creates a byte array from the abstract tree of the node.
|
static org.w3c.dom.Document |
toSignedXMLDocument(IXMLEncodable a_xmlEncodable,
int a_iDocumentClass)
Transforms an IXMLEncodable object into an signed XML document.
|
static java.lang.String |
toString(IXMLEncodable xmlobject) |
static java.lang.String |
toString(org.w3c.dom.Node a_node)
Writes an XML-Node to a String.
|
static org.w3c.dom.Document |
toXMLDocument(byte[] a_xmlDocument)
Transforms a byte array into an XML document.
|
static org.w3c.dom.Document |
toXMLDocument(char[] a_xmlDocument) |
static org.w3c.dom.Document |
toXMLDocument(IXMLEncodable a_xmlEncodable)
Transforms an IXMLEncodable object into an XML document.
|
static org.w3c.dom.Document |
toXMLDocument(java.lang.String a_xmlDocument)
Transforms a String into an XML document.
|
static org.w3c.dom.Element |
toXMLElement(IXMLEncodable a_xmlEncodable)
Transforms an IXMLEncodable object into an XML element.
|
static void |
write(org.w3c.dom.Document a_doc,
java.io.File a_file)
Writes an XML document to a file.
|
static void |
write(org.w3c.dom.Document a_doc,
java.io.OutputStream a_outputStream)
Writes an XML document to an output stream.
|
static void |
write(org.w3c.dom.Document a_doc,
java.io.Writer a_writer)
Writes an XML document to a Writer.
|
public static final int STORAGE_MODE_NORMAL
public static final int STORAGE_MODE_OPTIMIZED
public static final int STORAGE_MODE_AGRESSIVE
public static final java.lang.String[] SPECIAL_CHARS
public static final java.lang.String[] ENTITIES
public static int getStorageMode()
public static void setStorageMode(int a_storageMode)
a_storageMode
- public static void assertNotNull(org.w3c.dom.Node a_node) throws XMLParseException
a_node
- an XML nodeXMLParseException
- if the given XML node is nullpublic static void assertNotNull(org.w3c.dom.Node a_node, java.lang.String a_attribute) throws XMLParseException
XMLParseException
public static org.w3c.dom.Node assertNodeName(org.w3c.dom.Node a_node, java.lang.String a_strExpectedName) throws XMLParseException
a_node
- an XML nodea_strExpectedName
- the node`s expected nameXMLParseException
- if the given node has not the expected name or if it is nullpublic static org.w3c.dom.Node getDocumentElement(org.w3c.dom.Node a_node)
a_node
- an XML nodepublic static int parseValue(org.w3c.dom.Node a_node, int a_defaultValue)
a_node
- an XML nodea_defaultValue
- the default valuepublic static long parseValue(org.w3c.dom.Node a_node, long a_defaultValue)
a_node
- an XML nodea_defaultValue
- the default valuepublic static double parseValue(org.w3c.dom.Node a_node, double a_defaultValue)
a_node
- an XML nodea_defaultValue
- the default valuepublic static java.lang.String parseAttribute(org.w3c.dom.Node a_node, java.lang.String a_attribute, java.lang.String a_default)
a_node
- an XML nodea_attribute
- an attribute`s namea_default
- the default valuepublic static boolean parseAttribute(org.w3c.dom.Node a_node, java.lang.String a_attribute, boolean a_default)
a_node
- an XML nodea_attribute
- an attribute`s namea_default
- the default valuepublic static int parseAttribute(org.w3c.dom.Node a_node, java.lang.String a_attribute, int a_default)
a_node
- an XML nodea_attribute
- an attribute`s namea_default
- the default valuepublic static double parseAttribute(org.w3c.dom.Node a_node, java.lang.String a_attribute, double a_default)
a_node
- an XML nodea_attribute
- an attribute`s namea_default
- the default valuepublic static long parseAttribute(org.w3c.dom.Node a_node, java.lang.String a_attribute, long a_default)
a_node
- an XML nodea_attribute
- an attribute`s namea_default
- the default valuepublic static boolean parseValue(org.w3c.dom.Node a_node, boolean a_defaultValue)
a_node
- an XML nodea_defaultValue
- the default valuepublic static java.lang.String parseValue(org.w3c.dom.Node a_node, java.lang.String a_defaultValue)
a_node
- text node, element node or attribute nodea_defaultValue
- value returned, if an error occuredpublic static java.lang.String getXmlElementContainerName(java.lang.Class a_xmlEncodableClass)
a_xmlEncodableClass
- a Class (should be an IXMLEncodable)public static java.lang.String getXmlElementName(java.lang.Class a_xmlEncodableClass)
a_xmlEncodableClass
- a Class (should be an IXMLEncodable)public static org.w3c.dom.Element[] readElementsByTagName(java.io.File a_file, java.lang.String a_tagName)
a_file
- a file to load the elements froma_tagName
- the tag that specifies the elements to loadpublic static org.w3c.dom.NodeList getElementsByTagName(org.w3c.dom.Node a_elementName, java.lang.String a_tagName)
public static org.w3c.dom.Node getFirstChildByName(org.w3c.dom.Node a_node, java.lang.String a_childname)
a_node
- the node from that the search startsa_childname
- the childnode we are looking forpublic static org.w3c.dom.Node getFirstChildByName(org.w3c.dom.Node a_node, java.lang.String a_childname, boolean a_bDeepSearch)
public static org.w3c.dom.Node getFirstChildByNameUsingDeepSearch(org.w3c.dom.Node a_node, java.lang.String a_childname)
a_node
- the node from that the search startsa_childname
- the childnode we are looking forpublic static org.w3c.dom.Node getLastChildByName(org.w3c.dom.Node n, java.lang.String name)
public static org.w3c.dom.Node getNextSibling(org.w3c.dom.Node a_node)
a_node
- public static org.w3c.dom.Node getNextSiblingByName(org.w3c.dom.Node a_node, java.lang.String a_siblingName)
a_node
- the node from that the search startsa_siblingName
- the sibling's node namepublic static void setValue(org.w3c.dom.Node a_node, java.lang.String a_value)
a_node
- an XML nodea_value
- a Stringpublic static void setValue(org.w3c.dom.Node a_node, int a_value)
a_node
- an XML nodea_value
- an int valuepublic static void setValue(org.w3c.dom.Node a_node, long a_value)
a_node
- an XML nodea_value
- a long valuepublic static void setValue(org.w3c.dom.Node a_node, double a_value)
a_node
- an XML nodea_value
- a double valuepublic static void setValue(org.w3c.dom.Node a_node, boolean a_bValue)
a_node
- an XML nodea_bValue
- a boolean valuepublic static void setAttribute(org.w3c.dom.Element a_element, java.lang.String a_attribute, java.lang.String a_value)
a_element
- an XML Element (not NULL)a_attribute
- an attribute name (not NULL)a_value
- a String value for the attribute (not NULL)public static void setAttribute(org.w3c.dom.Element a_element, java.lang.String a_attribute, boolean a_value)
a_element
- an XML Elementa_attribute
- an attribute namea_value
- a boolean value for the attributepublic static void setAttribute(org.w3c.dom.Element a_element, java.lang.String a_attribute, int a_value)
a_element
- an XML Elementa_attribute
- an attribute namea_value
- an int value for the attributepublic static void setAttribute(org.w3c.dom.Element a_element, java.lang.String a_attribute, double a_value)
a_element
- an XML Elementa_attribute
- an attribute namea_value
- a double value for the attributepublic static void setAttribute(org.w3c.dom.Element a_element, java.lang.String a_attribute, long a_value)
a_element
- an XML Elementa_attribute
- an attribute namea_value
- a long value for the attributepublic static org.w3c.dom.Document createDocument()
public static org.w3c.dom.Element createChildElementWithValue(org.w3c.dom.Node a_parent, java.lang.String a_nodeName, java.lang.String a_value)
a_parent
- a_nodeName
- a_value
- public static org.w3c.dom.Element createChildElement(org.w3c.dom.Node a_parent, java.lang.String a_nodeName)
a_parent
- a_nodeName
- public static org.w3c.dom.Node importNode(org.w3c.dom.Document a_doc, org.w3c.dom.Node a_source, boolean a_bDeep) throws XMLParseException
a_doc
- the new owner document of the copied source nodea_source
- the source XML nodea_bDeep
- true if the source node should be copied with all children, the
chlidren`s children and so on; false, if only the direct
children of the source node should be copiedjava.lang.Exception
- if an error occursXMLParseException
public static byte[] toByteArray(org.w3c.dom.Node a_inputNode)
a_inputNode
- The node (incl. the whole tree) which is flattened to a byte
array.public static java.lang.String toString(org.w3c.dom.Node a_node)
a_node
- an XML Nodepublic static java.lang.String quoteXML(java.lang.String text)
public static void removeComments(org.w3c.dom.Node a_node)
a_node
- a nodepublic static org.w3c.dom.Document formatHumanReadable(org.w3c.dom.Document a_doc)
a_doc
- an xml documentpublic static org.w3c.dom.Element formatHumanReadable(org.w3c.dom.Element a_element)
a_element
- an xml elementpublic static org.w3c.dom.Document readXMLDocument(org.xml.sax.InputSource a_inputSource) throws java.io.IOException, XMLParseException
a_inputSource
- an input sourcejava.io.IOException
- if an I/O error occursXMLParseException
- if the input stream could not be parsed correctlypublic static org.w3c.dom.Document readXMLDocument(java.io.InputStream a_inputStream) throws java.io.IOException, XMLParseException
a_inputStream
- an input streamjava.io.IOException
- if an I/O error occursXMLParseException
- if the input stream could not be parsed correctlypublic static org.w3c.dom.Document readXMLDocument(java.io.Reader a_reader) throws java.io.IOException, XMLParseException
a_reader
- a Reader.java.io.IOException
- if an I/O error occursXMLParseException
- if the input stream could not be parsed correctlypublic static org.w3c.dom.Document readXMLDocument(java.io.File a_file) throws java.io.IOException, XMLParseException
a_file
- a filejava.io.IOException
- if an I/O error occursXMLParseException
- if the file could not be parsed correctlypublic static void write(org.w3c.dom.Document a_doc, java.io.OutputStream a_outputStream) throws java.io.IOException
a_doc
- an XML documenta_outputStream
- an output streamjava.io.IOException
- if an I/O error occurspublic static void write(org.w3c.dom.Document a_doc, java.io.Writer a_writer) throws java.io.IOException
a_doc
- an XML documenta_writer
- a Writerjava.io.IOException
- if an I/O error occurspublic static void write(org.w3c.dom.Document a_doc, java.io.File a_file) throws java.io.IOException
a_doc
- an XML documenta_file
- a filejava.io.IOException
- if an I/O error occurspublic static org.w3c.dom.Document toXMLDocument(java.lang.String a_xmlDocument) throws XMLParseException
a_xmlDocument
- a valid XML document in String representationXMLParseException
- if the given String is no valid XML documentpublic static org.w3c.dom.Document toXMLDocument(char[] a_xmlDocument) throws XMLParseException
XMLParseException
public static org.w3c.dom.Document toXMLDocument(byte[] a_xmlDocument) throws XMLParseException
a_xmlDocument
- a valid XML document in byte representationXMLParseException
- if the given byte array is no valid XML documentpublic static org.w3c.dom.Document toXMLDocument(IXMLEncodable a_xmlEncodable)
a_xmlEncodable
- an IXMLEncodablepublic static org.w3c.dom.Document toSignedXMLDocument(IXMLEncodable a_xmlEncodable, int a_iDocumentClass)
a_xmlEncodable
- an IXMLEncodablepublic static org.w3c.dom.Element toXMLElement(IXMLEncodable a_xmlEncodable)
a_xmlEncodable
- an IXMLEncodablepublic static final byte[] createDocumentStructure()
public static java.lang.String stripNewlineFromHash(java.lang.String hashValue)
hashValue
- String: a SHA1 hash valuepublic static java.lang.String toString(IXMLEncodable xmlobject)
public static void printXmlEncodable(IXMLEncodable xmlobject)
public static java.math.BigInteger parseValue(org.w3c.dom.Element elem, java.math.BigInteger defValue)
public static void setValue(org.w3c.dom.Element elem, java.math.BigInteger i)
public static org.w3c.dom.Document createDocumentFromElement(org.w3c.dom.Element a_elem) throws XMLParseException
XMLParseException
public static java.lang.String filterXMLChars(java.lang.String a_source)
a_source
- public static void filterXMLCharsForAnObject(java.lang.Object anObject)
public static java.lang.String restoreFilteredXMLChars(java.lang.String a_source)
Copyright © 2023. All rights reserved.