eu.beesoft.gaia.util
Class Xml

java.lang.Object
  extended by eu.beesoft.gaia.util.Xml

public abstract class Xml
extends java.lang.Object

Helper class to support XML DOM parsing and processing.


Method Summary
static java.util.Map<java.lang.String,java.lang.String> getAttributes(org.w3c.dom.Element element)
          Returns the attribute map of the given element.
static java.lang.String getAttributeValue(java.lang.String name, org.w3c.dom.Element element)
          Returns the value of the attribute with the given name.
static int getAttributeValue(java.lang.String name, org.w3c.dom.Element element, int defaultValue)
          Returns the value of the attribute with the given name converted to int.
static java.lang.String getAttributeValue(java.lang.String name, org.w3c.dom.Element element, java.lang.String defaultValue)
          Returns the value of the attribute with the given name.
static java.util.Iterator<org.w3c.dom.Element> getElementIterator(org.w3c.dom.Element parent)
          Returns iterator over the given element child elements.
static java.lang.String getText(org.w3c.dom.Element element)
          Returns content of text node under the given element.
static org.w3c.dom.Document parse(java.io.File file)
          Parses XML resource from the file system..
static org.w3c.dom.Document parse(java.io.File file, org.xml.sax.EntityResolver resolver, org.xml.sax.ErrorHandler handler)
          Parses XML resource from the file system..
static org.w3c.dom.Document parse(java.io.InputStream stream)
          Parses XML input stream.
static org.w3c.dom.Document parse(java.io.InputStream stream, org.xml.sax.EntityResolver resolver, org.xml.sax.ErrorHandler handler)
          Parses XML input stream.
static org.w3c.dom.Document parse(java.io.Reader reader)
          Parses XML character stream.
static org.w3c.dom.Document parse(java.io.Reader reader, org.xml.sax.EntityResolver resolver, org.xml.sax.ErrorHandler handler)
          Parses XML character stream.
static org.w3c.dom.Document parse(java.lang.String sourceName)
          Parses XML resource with given name (file name).
static org.w3c.dom.Document parse(java.lang.String sourceName, org.xml.sax.EntityResolver resolver, org.xml.sax.ErrorHandler handler)
          Parses XML resource with given name (file name).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parse

public static org.w3c.dom.Document parse(java.lang.String sourceName)
Parses XML resource with given name (file name).

Parameters:
sourceName - - the name of the XML resource (qualified file name, class path name, etc.)
Returns:
created instance of org.w3c.dom.Document

parse

public static org.w3c.dom.Document parse(java.lang.String sourceName,
                                         org.xml.sax.EntityResolver resolver,
                                         org.xml.sax.ErrorHandler handler)
Parses XML resource with given name (file name).

Parameters:
sourceName - - the name of the XML resource (qualified file name, class path name, etc.)
resolver - - entity resolver (can be null)
handler - - error handler (can be null)
Returns:
created instance of org.w3c.dom.Document

parse

public static org.w3c.dom.Document parse(java.io.File file)
Parses XML resource from the file system..

Parameters:
file - - file in file system
Returns:
created instance of org.w3c.dom.Document

parse

public static org.w3c.dom.Document parse(java.io.File file,
                                         org.xml.sax.EntityResolver resolver,
                                         org.xml.sax.ErrorHandler handler)
Parses XML resource from the file system..

Parameters:
file - - file in file system
resolver - - entity resolver (can be null)
handler - - error handler (can be null)
Returns:
created instance of org.w3c.dom.Document

parse

public static org.w3c.dom.Document parse(java.io.Reader reader)
Parses XML character stream.

Parameters:
reader - - character stream to parse
Returns:
created instance of org.w3c.dom.Document

parse

public static org.w3c.dom.Document parse(java.io.Reader reader,
                                         org.xml.sax.EntityResolver resolver,
                                         org.xml.sax.ErrorHandler handler)
Parses XML character stream.

Parameters:
reader - - character stream to parse
resolver - - entity resolver (can be null)
handler - - error handler (can be null)
Returns:
created instance of org.w3c.dom.Document

parse

public static org.w3c.dom.Document parse(java.io.InputStream stream)
Parses XML input stream.

Parameters:
stream - - input stream to parse
Returns:
created instance of org.w3c.dom.Document

parse

public static org.w3c.dom.Document parse(java.io.InputStream stream,
                                         org.xml.sax.EntityResolver resolver,
                                         org.xml.sax.ErrorHandler handler)
Parses XML input stream.

Parameters:
stream - - input stream to parse
resolver - - entity resolver (can be null)
handler - - error handler (can be null)
Returns:
created instance of org.w3c.dom.Document

getElementIterator

public static java.util.Iterator<org.w3c.dom.Element> getElementIterator(org.w3c.dom.Element parent)
Returns iterator over the given element child elements.

Parameters:
parent - - the element from which subelements should be iterated
Returns:
iterator over the subelements (if given parent element has no subelements, returns empty iterator)

getAttributes

public static java.util.Map<java.lang.String,java.lang.String> getAttributes(org.w3c.dom.Element element)
Returns the attribute map of the given element.

Parameters:
element - - element from which should be attributes exported
Returns:
map of attributes {name : value} entries

getAttributeValue

public static java.lang.String getAttributeValue(java.lang.String name,
                                                 org.w3c.dom.Element element)
Returns the value of the attribute with the given name. If element does not contain required attribute, returns null.

Parameters:
name - - name of the attribute
element - - element from which should be attribute value exported
Returns:
value of the attribute

getAttributeValue

public static java.lang.String getAttributeValue(java.lang.String name,
                                                 org.w3c.dom.Element element,
                                                 java.lang.String defaultValue)
Returns the value of the attribute with the given name. If element does not contain required attribute, returns defaultValue.

Parameters:
name - - name of the attribute
element - - element from which should be attribute value exported
defaultValue - - value to be used to return if no attribute with given name exists
Returns:
value of the attribute or defaultValue

getAttributeValue

public static int getAttributeValue(java.lang.String name,
                                    org.w3c.dom.Element element,
                                    int defaultValue)
Returns the value of the attribute with the given name converted to int. If element does not contain required attribute or contained value cannot be converted to int, returns defaultValue.

Parameters:
name - - name of the attribute
element - - element from which should be attribute value exported
defaultValue - - value to be used to return if no attribute with given name exists
Returns:
integer value of the attribute or defaultValue

getText

public static java.lang.String getText(org.w3c.dom.Element element)
Returns content of text node under the given element.

Parameters:
element - - element from which should be text returned
Returns:
plain text from element or null