it.cutruzzula.lgml.util
Class DOMUtils

java.lang.Object
  extended by it.cutruzzula.lgml.util.DOMUtils

public class DOMUtils
extends java.lang.Object

XML utility methods


Method Summary
static org.w3c.dom.Document buildDocument(byte[] buffer)
          Method to build a DOM document from a byte array.
static org.w3c.dom.Document buildDocument(java.io.InputStream is)
          Method to build a DOM document from an input stream.
static java.lang.String getAttributeValue(org.w3c.dom.Node node, java.lang.String attributeName)
          Method to get node attribute value with provided name, if present.
static java.util.List<org.w3c.dom.Node> getChildElements(org.w3c.dom.Node node)
          Method to get the input node children of type "ELEMENT".
static java.util.List<org.w3c.dom.Node> getChildElements(org.w3c.dom.Node node, java.lang.String localName)
          Method to get the input node children of type "ELEMENT" with provided local name.
static org.w3c.dom.Node getFirstChildElement(org.w3c.dom.Node node)
          Method to get the first input node's child of type "ELEMENT", if present.
static org.w3c.dom.Node getFirstChildElement(org.w3c.dom.Node node, java.lang.String localName)
          Method to get the first input node child of type "ELEMENT" with provided local name, if present.
static java.lang.String getNodeLocalName(org.w3c.dom.Node node)
          Method to get node local name (example "name" for "ns1:name").
static java.lang.String getNodeTextValue(org.w3c.dom.Node node)
          Method to get node text value, if found.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

buildDocument

public static org.w3c.dom.Document buildDocument(byte[] buffer)
                                          throws java.lang.Exception
Method to build a DOM document from a byte array.

Parameters:
buffer - The input byte array
Returns:
The org.w3c.dom.Document built
Throws:
java.lang.Exception

buildDocument

public static org.w3c.dom.Document buildDocument(java.io.InputStream is)
                                          throws java.lang.Exception
Method to build a DOM document from an input stream.

Parameters:
is - The input stream
Returns:
The org.w3c.dom.Document built
Throws:
java.lang.Exception

getFirstChildElement

public static org.w3c.dom.Node getFirstChildElement(org.w3c.dom.Node node)
Method to get the first input node's child of type "ELEMENT", if present.

Parameters:
node - The org.w3c.dom.Node input Node
Returns:
The first element child, or null if not found

getFirstChildElement

public static org.w3c.dom.Node getFirstChildElement(org.w3c.dom.Node node,
                                                    java.lang.String localName)
Method to get the first input node child of type "ELEMENT" with provided local name, if present.

Parameters:
node - The org.w3c.dom.Node input Node
localName - The local name to be searched
Returns:
The first element child, or null if not found

getChildElements

public static java.util.List<org.w3c.dom.Node> getChildElements(org.w3c.dom.Node node)
Method to get the input node children of type "ELEMENT".

Parameters:
node - The org.w3c.dom.Node input Node
Returns:
A java.util.List containing the element children

getChildElements

public static java.util.List<org.w3c.dom.Node> getChildElements(org.w3c.dom.Node node,
                                                                java.lang.String localName)
Method to get the input node children of type "ELEMENT" with provided local name.

Parameters:
node - The org.w3c.dom.Node input Node
localName - The local name to be searched
Returns:
A java.util.List containing the element children

getNodeLocalName

public static java.lang.String getNodeLocalName(org.w3c.dom.Node node)
Method to get node local name (example "name" for "ns1:name").

Parameters:
node - The org.w3c.dom.Node input Node
Returns:
The node local name

getNodeTextValue

public static java.lang.String getNodeTextValue(org.w3c.dom.Node node)
Method to get node text value, if found.

Parameters:
node - The org.w3c.dom.Node input Node
Returns:
The node text value, or null if not found

getAttributeValue

public static java.lang.String getAttributeValue(org.w3c.dom.Node node,
                                                 java.lang.String attributeName)
Method to get node attribute value with provided name, if present.

Parameters:
node - The org.w3c.dom.Node input Node
attributeName - The attribute to search
Returns:
The attribute value, or null if not found