anon.util
Class XMLUtil

java.lang.Object
  extended by anon.util.XMLUtil

public class XMLUtil
extends java.lang.Object

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

STORAGE_MODE_NORMAL

public static final int STORAGE_MODE_NORMAL
See Also:
Constant Field Values

STORAGE_MODE_OPTIMIZED

public static final int STORAGE_MODE_OPTIMIZED
See Also:
Constant Field Values

STORAGE_MODE_AGRESSIVE

public static final int STORAGE_MODE_AGRESSIVE
See Also:
Constant Field Values

DEFAULT_FORMAT_SPACE

private static final java.lang.String DEFAULT_FORMAT_SPACE
See Also:
Constant Field Values

XML_STR_BOOLEAN_TRUE

private static final java.lang.String XML_STR_BOOLEAN_TRUE
See Also:
Constant Field Values

XML_STR_BOOLEAN_FALSE

private static final java.lang.String XML_STR_BOOLEAN_FALSE
See Also:
Constant Field Values

PACKAGE_TRANSFORMER

private static final java.lang.String PACKAGE_TRANSFORMER
See Also:
Constant Field Values

HIERARCHY_REQUEST_ERR

private static final java.lang.String HIERARCHY_REQUEST_ERR
See Also:
Constant Field Values

ms_DocumentBuilderFactory

private static javax.xml.parsers.DocumentBuilderFactory ms_DocumentBuilderFactory

m_bCheckedHumanReadableFormatting

private static boolean m_bCheckedHumanReadableFormatting

m_bNeedsHumanReadableFormatting

private static boolean m_bNeedsHumanReadableFormatting

ms_storageMode

private static int ms_storageMode

SPECIAL_CHARS

public static final java.lang.String[] SPECIAL_CHARS

ENTITIES

public static final java.lang.String[] ENTITIES
Constructor Detail

XMLUtil

public XMLUtil()
Method Detail

getStorageMode

public static int getStorageMode()

setStorageMode

public static void setStorageMode(int a_storageMode)
Sets the storage mode for XML documents. STORAGE_MODE_AGRESSIVE means that XML classes will try to set their internal XML variables to null as soon as possible, regardless of the state of the object. Calls to some methods may lead to a null pointer if methods calling the XML variables are used. STORAGE_MODE_OPTIMIZED means that XML classes will set their internal XML variables to null if they are optional and the object state is still consistent. However, it may not be possible to store or send these objects any more.

Parameters:
a_storageMode -

assertNotNull

public static void assertNotNull(org.w3c.dom.Node a_node)
                          throws XMLParseException
Throws an XMLParseException if the given XML node is null.

Parameters:
a_node - an XML node
Throws:
XMLParseException - if the given XML node is null

assertNotNull

public static void assertNotNull(org.w3c.dom.Node a_node,
                                 java.lang.String a_attribute)
                          throws XMLParseException
Throws:
XMLParseException

assertNodeName

public static org.w3c.dom.Node assertNodeName(org.w3c.dom.Node a_node,
                                              java.lang.String a_strExpectedName)
                                       throws XMLParseException
Throws an XMLParseException if the given XML node has not the expected name or if it is null. If the given node is an XML document, the document element is returned. Otherwise, the given node is returned.

Parameters:
a_node - an XML node
a_strExpectedName - the node`s expected name
Returns:
If the given node is an XML document, the document element is returned. Otherwise, the given node is returned.
Throws:
XMLParseException - if the given node has not the expected name or if it is null

getDocumentElement

public 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. Otherwise, the node is returned unchanged.

Parameters:
a_node - an XML node
Returns:
if the current node is of the type XML document, this method returns the document element; otherwise, the node is returned unchanged

parseValue

public static int parseValue(org.w3c.dom.Node a_node,
                             int a_defaultValue)
Returns the value of the specified XML node as int.

Parameters:
a_node - an XML node
a_defaultValue - the default value
Returns:
the value of the specified node as boolean if the element`s value is of type int; otherwise, the default value is returned

parseValue

public static long parseValue(org.w3c.dom.Node a_node,
                              long a_defaultValue)
Returns the value of the specified XML node as long.

Parameters:
a_node - an XML node
a_defaultValue - the default value
Returns:
the value of the specified node as boolean if the element`s value is of type long; otherwise, the default value is returned

parseValue

public static double parseValue(org.w3c.dom.Node a_node,
                                double a_defaultValue)
Returns the value of the specified XML node as double.

Parameters:
a_node - an XML node
a_defaultValue - the default value
Returns:
the value of the specified node as double if the element`s value is of type double; otherwise, the default value is returned

parseAttribute

public 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.

Parameters:
a_node - an XML node
a_attribute - an attribute`s name
a_default - the default value
Returns:
the value of the specified attribute as String if the element has this attribute; otherwise, the default value is returned

parseAttribute

public 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.

Parameters:
a_node - an XML node
a_attribute - an attribute`s name
a_default - the default value
Returns:
the value of the specified attribute as boolean if the element has this attribute; otherwise, the default value is returned

parseAttribute

public 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.

Parameters:
a_node - an XML node
a_attribute - an attribute`s name
a_default - the default value
Returns:
the value of the specified attribute as int if the element has this attribute; otherwise, the default value is returned

parseAttribute

public 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.

Parameters:
a_node - an XML node
a_attribute - an attribute`s name
a_default - the default value
Returns:
the value of the specified attribute as int if the element has this attribute; otherwise, the default value is returned

parseAttribute

public 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.

Parameters:
a_node - an XML node
a_attribute - an attribute`s name
a_default - the default value
Returns:
the value of the specified attribute as long if the element has this attribute; otherwise, the default value is returned

parseValue

public static boolean parseValue(org.w3c.dom.Node a_node,
                                 boolean a_defaultValue)
Returns the value of the specified XML node as boolean.

Parameters:
a_node - an XML node
a_defaultValue - the default value
Returns:
the value of the specified node as boolean if the element`s value is of type boolean; otherwise, the default value is returned

parseValue

public 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. The "content" of an Element Node is the text between the opening and closing Element Tag. The content of an attribute node is the value of the attribute.

Parameters:
a_node - text node, element node or attribute node
a_defaultValue - value returned, if an error occured
Returns:
the "content" of the node or the default value, if the node has no value or an error occured

getXmlElementContainerName

public 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.

Parameters:
a_xmlEncodableClass - a Class (should be an IXMLEncodable)
Returns:
the static XML_ELEMENT_CONTAINER_NAME field contents if present in the given class or null if the field was not found

getXmlElementName

public 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.

Parameters:
a_xmlEncodableClass - a Class (should be an IXMLEncodable)
Returns:
the static XML_ELEMENT_NAME field contents if present in the given class or null if the field was not found

readElementsByTagName

public 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.

Parameters:
a_file - a file to load the elements from
a_tagName - the tag that specifies the elements to load
Returns:
the elements read from the given file or an empty array if no elements were read

getElementsByTagName

public static org.w3c.dom.NodeList getElementsByTagName(org.w3c.dom.Node a_elementName,
                                                        java.lang.String a_tagName)

getFirstChildByName

public 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.

Parameters:
a_node - the node from that the search starts
a_childname - the childnode we are looking for
Returns:
the child node of the given node with the given name or null if it was not found

getFirstChildByNameUsingDeepSearch

public 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. If the node is not found in the direct children of the parent node, then all child nodes will be searched and then their child nodes and so on until either the requested child has been found or all nodes in the XML structure have been traversed.

Parameters:
a_node - the node from that the search starts
a_childname - the childnode we are looking for
Returns:
the child node of the given node with the given name or null if it was not found

getLastChildByName

public static org.w3c.dom.Node getLastChildByName(org.w3c.dom.Node n,
                                                  java.lang.String name)

getNextSiblingByName

public 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.

Parameters:
a_node - the node from that the search starts
a_siblingName - the sibling's node name
Returns:
the sibling node of the given node with the given name or null if it was not found

setValue

public static void setValue(org.w3c.dom.Node a_node,
                            java.lang.String a_value)
Inserts a String value into an XML node. If a_value==NULL nothing is done.

Parameters:
a_node - an XML node
a_value - a String

setValue

public static void setValue(org.w3c.dom.Node a_node,
                            int a_value)
Inserts an int value into an XML node.

Parameters:
a_node - an XML node
a_value - an int value

setValue

public static void setValue(org.w3c.dom.Node a_node,
                            long a_value)
Inserts a long value into an XML node.

Parameters:
a_node - an XML node
a_value - a long value

setValue

public static void setValue(org.w3c.dom.Node a_node,
                            double a_value)
Inserts a double precision floating point value into an XML node.

Parameters:
a_node - an XML node
a_value - a double value

setValue

public static void setValue(org.w3c.dom.Node a_node,
                            boolean a_bValue)
Inserts a boolean value into an XML node.

Parameters:
a_node - an XML node
a_bValue - a boolean value

setAttribute

public 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. If a_attribute or a_value is NULL, than nothing is done!

Parameters:
a_element - an XML Element (not NULL)
a_attribute - an attribute name (not NULL)
a_value - a String value for the attribute (not NULL)

setAttribute

public 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.

Parameters:
a_element - an XML Element
a_attribute - an attribute name
a_value - a boolean value for the attribute

setAttribute

public 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.

Parameters:
a_element - an XML Element
a_attribute - an attribute name
a_value - an int value for the attribute

setAttribute

public 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.

Parameters:
a_element - an XML Element
a_attribute - an attribute name
a_value - a double value for the attribute

setAttribute

public 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.

Parameters:
a_element - an XML Element
a_attribute - an attribute name
a_value - a long value for the attribute

createDocument

public static org.w3c.dom.Document createDocument()
Creates a new Document.

Returns:
a new Document

createChildElementWithValue

public static org.w3c.dom.Element createChildElementWithValue(org.w3c.dom.Element a_parent,
                                                              java.lang.String a_nodeName,
                                                              java.lang.String a_value)

createChildElement

public static org.w3c.dom.Element createChildElement(org.w3c.dom.Element a_parent,
                                                     java.lang.String a_nodeName)

importNode

public static org.w3c.dom.Node importNode(org.w3c.dom.Document a_doc,
                                          org.w3c.dom.Node a_source,
                                          boolean a_bDeep)
                                   throws XMLParseException
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.

Parameters:
a_doc - the new owner document of the copied source node
a_source - the source XML node
a_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
Returns:
a copy of the source node with the given document as owner document
Throws:
java.lang.Exception - if an error occurs
XMLParseException

toByteArray

public static byte[] toByteArray(org.w3c.dom.Node a_inputNode)
Creates a byte array from the abstract tree of the node.

Parameters:
a_inputNode - The node (incl. the whole tree) which is flattened to a byte array.
Returns:
the node as a byte array (incl. the whole tree).

toString

public static java.lang.String toString(org.w3c.dom.Node a_node)
Writes an XML-Node to a String. If the node is a Document then the header is included. Since writing was not standardized until JAXP 1.1 different Methods are tried

Parameters:
a_node - an XML Node
Returns:
an XML Node in a String representation or null if no transformation could be done

quoteXML

public static java.lang.String quoteXML(java.lang.String text)

removeComments

public static void removeComments(org.w3c.dom.Node a_node)
Removes all comments and empty lines from a node. Does nothing if the node is a comment node.

Parameters:
a_node - a node

formatHumanReadable

public static org.w3c.dom.Document formatHumanReadable(org.w3c.dom.Document a_doc)
Reformats an XML document into a human readable format.

Parameters:
a_doc - an xml document

formatHumanReadable

public static org.w3c.dom.Element formatHumanReadable(org.w3c.dom.Element a_element)
Reformats an XML element into a human readable format.

Parameters:
a_element - an xml element

readXMLDocument

public static org.w3c.dom.Document readXMLDocument(org.xml.sax.InputSource a_inputSource)
                                            throws java.io.IOException,
                                                   XMLParseException
Reads an XML document from an input source.

Parameters:
a_inputSource - an input source
Returns:
the XML document that was read from the input source
Throws:
java.io.IOException - if an I/O error occurs
XMLParseException - if the input stream could not be parsed correctly

readXMLDocument

public static org.w3c.dom.Document readXMLDocument(java.io.InputStream a_inputStream)
                                            throws java.io.IOException,
                                                   XMLParseException
Reads an XML document from an input stream.

Parameters:
a_inputStream - an input stream
Returns:
the XML document that was read from the input stream
Throws:
java.io.IOException - if an I/O error occurs
XMLParseException - if the input stream could not be parsed correctly

readXMLDocument

public static org.w3c.dom.Document readXMLDocument(java.io.Reader a_reader)
                                            throws java.io.IOException,
                                                   XMLParseException
Reads an XML document from a Reader.

Parameters:
a_reader - a Reader.
Returns:
the XML document that was read from the Reader
Throws:
java.io.IOException - if an I/O error occurs
XMLParseException - if the input stream could not be parsed correctly

readXMLDocument

public static org.w3c.dom.Document readXMLDocument(java.io.File a_file)
                                            throws java.io.IOException,
                                                   XMLParseException
Reads an XML document from a file.

Parameters:
a_file - a file
Returns:
the XML document that was read from the file
Throws:
java.io.IOException - if an I/O error occurs
XMLParseException - if the file could not be parsed correctly

write

public static void write(org.w3c.dom.Document a_doc,
                         java.io.OutputStream a_outputStream)
                  throws java.io.IOException
Writes an XML document to an output stream.

Parameters:
a_doc - an XML document
a_outputStream - an output stream
Throws:
java.io.IOException - if an I/O error occurs

write

public static void write(org.w3c.dom.Document a_doc,
                         java.io.Writer a_writer)
                  throws java.io.IOException
Writes an XML document to a Writer.

Parameters:
a_doc - an XML document
a_writer - a Writer
Throws:
java.io.IOException - if an I/O error occurs

write

public static void write(org.w3c.dom.Document a_doc,
                         java.io.File a_file)
                  throws java.io.IOException
Writes an XML document to a file.

Parameters:
a_doc - an XML document
a_file - a file
Throws:
java.io.IOException - if an I/O error occurs

toXMLDocument

public static org.w3c.dom.Document toXMLDocument(java.lang.String a_xmlDocument)
                                          throws XMLParseException
Transforms a String into an XML document. The String must be a valid XML document in String representation.

Parameters:
a_xmlDocument - a valid XML document in String representation
Returns:
an XML document
Throws:
XMLParseException - if the given String is no valid XML document

toXMLDocument

public static org.w3c.dom.Document toXMLDocument(char[] a_xmlDocument)
                                          throws XMLParseException
Throws:
XMLParseException

toXMLDocument

public static org.w3c.dom.Document toXMLDocument(byte[] a_xmlDocument)
                                          throws XMLParseException
Transforms a byte array into an XML document. The byte array must be a valid XML document in byte representation.

Parameters:
a_xmlDocument - a valid XML document in byte representation
Returns:
an XML document
Throws:
XMLParseException - if the given byte array is no valid XML document

toXMLDocument

public static org.w3c.dom.Document toXMLDocument(IXMLEncodable a_xmlEncodable)
Transforms an IXMLEncodable object into an XML document.

Parameters:
a_xmlEncodable - an IXMLEncodable
Returns:
an XML document

toSignedXMLDocument

public static org.w3c.dom.Document toSignedXMLDocument(IXMLEncodable a_xmlEncodable,
                                                       int a_iDocumentClass)
Transforms an IXMLEncodable object into an signed XML document.

Parameters:
a_xmlEncodable - an IXMLEncodable
Returns:
an XML document

toXMLElement

public static org.w3c.dom.Element toXMLElement(IXMLEncodable a_xmlEncodable)
Transforms an IXMLEncodable object into an XML element.

Parameters:
a_xmlEncodable - an IXMLEncodable
Returns:
an XML element

createDocumentStructure

public static final byte[] createDocumentStructure()

toByteArrayOutputStream

private static java.io.ByteArrayOutputStream toByteArrayOutputStream(org.w3c.dom.Node node)
Writes an XML-Node to a String. If the node is a Document then the header is included. Since writing was not standardized until JAXP 1.1 different Methods are tried

Parameters:
node - an XML Node
Returns:
an XML Node in a ByteArrayOutputStream representation or null if no transformation could be done

getFirstChildByNameUsingDeepSearchInternal

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.

Parameters:
node - the node from that the search starts
name - the node we are looking for
Returns:
Node the node with the given name or null if it was not found

formatHumanReadable

private static int formatHumanReadable(org.w3c.dom.Node a_element,
                                       int a_level)
Reformats an element into a human readable format. This is a recursive function.

Parameters:
a_element - an xml element
a_level - the level of this element
Returns:
the number of nodes added (0 or 1)

removeCommentsInternal

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. This is a recursive function.

Parameters:
a_node - a node
a_parentNode - the node`s parent node
Returns:
the number of children removed (0 or 1)

stripNewlineFromHash

public 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

Parameters:
hashValue - String: a SHA1 hash value
Returns:
String: the input value, minus a trailing "\n"

printXmlEncodable

public static void printXmlEncodable(IXMLEncodable xmlobject)

parseValue

public static java.math.BigInteger parseValue(org.w3c.dom.Element elem,
                                              java.math.BigInteger defValue)

setValue

public static void setValue(org.w3c.dom.Element elem,
                            java.math.BigInteger i)

createDocumentFromElement

public static org.w3c.dom.Document createDocumentFromElement(org.w3c.dom.Element a_elem)
                                                      throws XMLParseException
Throws:
XMLParseException

filterXMLChars

public static java.lang.String filterXMLChars(java.lang.String a_source)
filters out the chars &, <, >and " with the unicode entities. WARNING: this destroys valid Entities so only use this this for dirty, not XML compliant Strings

Parameters:
a_source -
Returns:

filterXMLCharsForAnObject

public static void filterXMLCharsForAnObject(java.lang.Object anObject)

restoreFilteredXMLChars

public static java.lang.String restoreFilteredXMLChars(java.lang.String a_source)