|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object anon.util.XMLUtil
public class XMLUtil
This class provides an easy interface to XML methods.
Field Summary | |
---|---|
private static java.lang.String |
DEFAULT_FORMAT_SPACE
|
static java.lang.String[] |
ENTITIES
|
private static java.lang.String |
HIERARCHY_REQUEST_ERR
|
private static boolean |
m_bCheckedHumanReadableFormatting
|
private static boolean |
m_bNeedsHumanReadableFormatting
|
private static javax.xml.parsers.DocumentBuilderFactory |
ms_DocumentBuilderFactory
|
private static int |
ms_storageMode
|
private static java.lang.String |
PACKAGE_TRANSFORMER
|
static java.lang.String[] |
SPECIAL_CHARS
|
static int |
STORAGE_MODE_AGRESSIVE
|
static int |
STORAGE_MODE_NORMAL
|
static int |
STORAGE_MODE_OPTIMIZED
|
private static java.lang.String |
XML_STR_BOOLEAN_FALSE
|
private static java.lang.String |
XML_STR_BOOLEAN_TRUE
|
Constructor Summary | |
---|---|
XMLUtil()
|
Method Summary | |
---|---|
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.Element a_parent,
java.lang.String a_nodeName)
|
static org.w3c.dom.Element |
createChildElementWithValue(org.w3c.dom.Element a_parent,
java.lang.String a_nodeName,
java.lang.String a_value)
|
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. |
private static int |
formatHumanReadable(org.w3c.dom.Node a_element,
int a_level)
Reformats an 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 |
getFirstChildByNameUsingDeepSearch(org.w3c.dom.Node a_node,
java.lang.String a_childname)
Returns the child node of the given node with the given name. |
private static org.w3c.dom.Node |
getFirstChildByNameUsingDeepSearchInternal(org.w3c.dom.Node node,
java.lang.String name)
Returns a node that is equal to the given name, starting from the given node and, if it is not the node we are looking for, recursing to all its children. |
static org.w3c.dom.Node |
getLastChildByName(org.w3c.dom.Node n,
java.lang.String name)
|
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. |
private static int |
removeCommentsInternal(org.w3c.dom.Node a_node,
org.w3c.dom.Node a_parentNode)
Removes all comments, empty lines and new 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. |
private static java.io.ByteArrayOutputStream |
toByteArrayOutputStream(org.w3c.dom.Node node)
Writes an XML-Node to a String. |
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(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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int STORAGE_MODE_NORMAL
public static final int STORAGE_MODE_OPTIMIZED
public static final int STORAGE_MODE_AGRESSIVE
private static final java.lang.String DEFAULT_FORMAT_SPACE
private static final java.lang.String XML_STR_BOOLEAN_TRUE
private static final java.lang.String XML_STR_BOOLEAN_FALSE
private static final java.lang.String PACKAGE_TRANSFORMER
private static final java.lang.String HIERARCHY_REQUEST_ERR
private static javax.xml.parsers.DocumentBuilderFactory ms_DocumentBuilderFactory
private static boolean m_bCheckedHumanReadableFormatting
private static boolean m_bNeedsHumanReadableFormatting
private static int ms_storageMode
public static final java.lang.String[] SPECIAL_CHARS
public static final java.lang.String[] ENTITIES
Constructor Detail |
---|
public XMLUtil()
Method Detail |
---|
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 node
XMLParseException
- 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 name
XMLParseException
- 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 node
public static int parseValue(org.w3c.dom.Node a_node, int a_defaultValue)
a_node
- an XML nodea_defaultValue
- the default value
public static long parseValue(org.w3c.dom.Node a_node, long a_defaultValue)
a_node
- an XML nodea_defaultValue
- the default value
public static double parseValue(org.w3c.dom.Node a_node, double a_defaultValue)
a_node
- an XML nodea_defaultValue
- the default value
public 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 value
public 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 value
public 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 value
public 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 value
public 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 value
public static boolean parseValue(org.w3c.dom.Node a_node, boolean a_defaultValue)
a_node
- an XML nodea_defaultValue
- the default value
public 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 occured
public 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 load
public 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 for
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 for
public static org.w3c.dom.Node getLastChildByName(org.w3c.dom.Node n, java.lang.String name)
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 name
public 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.Element a_parent, java.lang.String a_nodeName, java.lang.String a_value)
public static org.w3c.dom.Element createChildElement(org.w3c.dom.Element a_parent, java.lang.String 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 copied
java.lang.Exception
- if an error occurs
XMLParseException
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 Node
public 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 source
java.io.IOException
- if an I/O error occurs
XMLParseException
- 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 stream
java.io.IOException
- if an I/O error occurs
XMLParseException
- 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 occurs
XMLParseException
- 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 file
java.io.IOException
- if an I/O error occurs
XMLParseException
- 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 stream
java.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 Writer
java.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 file
java.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 representation
XMLParseException
- 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 representation
XMLParseException
- if the given byte array is no valid XML documentpublic static org.w3c.dom.Document toXMLDocument(IXMLEncodable a_xmlEncodable)
a_xmlEncodable
- an IXMLEncodable
public static org.w3c.dom.Document toSignedXMLDocument(IXMLEncodable a_xmlEncodable, int a_iDocumentClass)
a_xmlEncodable
- an IXMLEncodable
public static org.w3c.dom.Element toXMLElement(IXMLEncodable a_xmlEncodable)
a_xmlEncodable
- an IXMLEncodable
public static final byte[] createDocumentStructure()
private static java.io.ByteArrayOutputStream toByteArrayOutputStream(org.w3c.dom.Node node)
node
- an XML Node
private static org.w3c.dom.Node getFirstChildByNameUsingDeepSearchInternal(org.w3c.dom.Node node, java.lang.String name)
node
- the node from that the search startsname
- the node we are looking for
private static int formatHumanReadable(org.w3c.dom.Node a_element, int a_level)
a_element
- an xml elementa_level
- the level of this element
private static int removeCommentsInternal(org.w3c.dom.Node a_node, org.w3c.dom.Node a_parentNode)
a_node
- a nodea_parentNode
- the node`s parent node
public static java.lang.String stripNewlineFromHash(java.lang.String hashValue)
hashValue
- String: a SHA1 hash value
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)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |