net.dpml.util
Class ElementHelper

java.lang.Object
  extended by net.dpml.util.ElementHelper

public final class ElementHelper
extends Object

Utility class supporting the translation of DOM content into local child, children, attribute and value values.

Version:
1.0.3
Author:
Digital Product Meta Library

Method Summary
static String getAttribute(Element node, String key)
          Return the value of an element attribute.
static String getAttribute(Element node, String key, String def)
          Return the value of an element attribute.
static boolean getBooleanAttribute(Element node, String key)
          Return the value of an element attribute as a boolean
static boolean getBooleanAttribute(Element node, String key, boolean def)
          Return the value of an element attribute as a boolean.
static Element getChild(Element root, String name)
          Return a named child relative to a supplied element.
static Element[] getChildren(Element root)
          Return all children of the supplied parent.
static Element[] getChildren(Element root, String name)
          Return all children matching the supplied element name.
static Element getRootElement(DocumentBuilder builder, InputStream input)
          Return the root element of the supplied input stream.
static Element getRootElement(File definition)
          Return the root element of the supplied file.
static Element getRootElement(InputStream input)
          Return the root element of the supplied input stream.
static String getValue(Element node)
          Return the value of an element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getRootElement

public static Element getRootElement(File definition)
                              throws Exception
Return the root element of the supplied file.

Parameters:
definition - the file to load
Returns:
the root element
Throws:
Exception - if the error occurs during root element establishment

getRootElement

public static Element getRootElement(InputStream input)
                              throws Exception
Return the root element of the supplied input stream.

Parameters:
input - the input stream containing a XML definition
Returns:
the root element
Throws:
Exception - if an error occurs

getRootElement

public static Element getRootElement(DocumentBuilder builder,
                                     InputStream input)
                              throws Exception
Return the root element of the supplied input stream.

Parameters:
builder - the document builder
input - the input stream containing a XML definition
Returns:
the root element
Throws:
Exception - if an error occurs

getChild

public static Element getChild(Element root,
                               String name)
Return a named child relative to a supplied element.

Parameters:
root - the parent DOM element
name - the name of a child element
Returns:
the child element of null if the child does not exist

getChildren

public static Element[] getChildren(Element root,
                                    String name)
Return all children matching the supplied element name.

Parameters:
root - the parent DOM element
name - the name against which child element will be matched
Returns:
the array of child elements with a matching name

getChildren

public static Element[] getChildren(Element root)
Return all children of the supplied parent.

Parameters:
root - the parent DOM element
Returns:
the array of all children

getValue

public static String getValue(Element node)
Return the value of an element.

Parameters:
node - the DOM node
Returns:
the node value

getAttribute

public static String getAttribute(Element node,
                                  String key)
Return the value of an element attribute.

Parameters:
node - the DOM node
key - the attribute key
Returns:
the attribute value or null if the attribute is undefined

getAttribute

public static String getAttribute(Element node,
                                  String key,
                                  String def)
Return the value of an element attribute.

Parameters:
node - the DOM node
key - the attribute key
def - the default value if the attribute is undefined
Returns:
the attribute value or the default value if undefined

getBooleanAttribute

public static boolean getBooleanAttribute(Element node,
                                          String key)
Return the value of an element attribute as a boolean

Parameters:
node - the DOM node
key - the attribute key
Returns:
the attribute value as a boolean or false if undefined

getBooleanAttribute

public static boolean getBooleanAttribute(Element node,
                                          String key,
                                          boolean def)
Return the value of an element attribute as a boolean.

Parameters:
node - the DOM node
key - the attribute key
def - the default value if the attribute is undefined
Returns:
the attribute value or the default value if undefined