schmitzm.xml
Class XMLUtil

java.lang.Object
  extended by schmitzm.xml.XMLUtil

public class XMLUtil
extends Object

Diese Klasse enthaelt statische Helper-Methoden fuer das Arbeiten mit XML.

Version:
1.0
Author:
Martin Schmitz (University of Bonn/Germany)

Field Summary
static JAXPDOMAdapter JDOM_TO_JAX
          Wrapper from JDOM to W3C.
static XMLOutputter XML_OUTPUTTER
          Writes XML element to file.
 
Constructor Summary
XMLUtil()
           
 
Method Summary
static String getAttribute(Element element, String attrName, String... defValue)
          Gets the attribute value from element.
static Boolean getBooleanAttribute(Element element, String attrName, Boolean... defValue)
          Gets the attribute value from element as Boolean.
static Color getColorAttribute(Element element, String attrName, Color... defValue)
          Gets the attribute value from element as Color.
static Double getDoubleAttribute(Element element, String attrName, Double... defValue)
          Gets the attribute value from element as Double.
static Float getFloatAttribute(Element element, String attrName, Float... defValue)
          Gets the attribute value from element as Float.
static Integer getIntegerAttribute(Element element, String attrName, Integer... defValue)
          Gets the attribute value from element as Integer.
static boolean setAttribute(Element element, String attrName, Object value, boolean inclNullAttr)
          Sets an attribute value.
static boolean setNotNullAttribute(Element element, String attrName, Object value)
          Sets an attribute value if the value is not null.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JDOM_TO_JAX

public static final JAXPDOMAdapter JDOM_TO_JAX
Wrapper from JDOM to W3C.


XML_OUTPUTTER

public static final XMLOutputter XML_OUTPUTTER
Writes XML element to file.

Constructor Detail

XMLUtil

public XMLUtil()
Method Detail

getAttribute

public static String getAttribute(Element element,
                                  String attrName,
                                  String... defValue)
Gets the attribute value from element.

Parameters:
element - element where the attribute is determined from
attrName - name of the attribute
defValue - default value returned if attribute is not found (or empty)
Returns:
null if element is null or attribute is not specified in element

getBooleanAttribute

public static Boolean getBooleanAttribute(Element element,
                                          String attrName,
                                          Boolean... defValue)
Gets the attribute value from element as Boolean.

Parameters:
element - element where the attribute is determined from
attrName - name of the attribute
defValue - optional default value returned if attribute is not found (or empty)
Returns:
null if element is null or attribute is not specified in element

getIntegerAttribute

public static Integer getIntegerAttribute(Element element,
                                          String attrName,
                                          Integer... defValue)
Gets the attribute value from element as Integer.

Parameters:
element - element where the attribute is determined from
attrName - name of the attribute
defValue - optional default value returned if attribute is not found (or empty)
Returns:
null if element is null or attribute is not specified in element

getDoubleAttribute

public static Double getDoubleAttribute(Element element,
                                        String attrName,
                                        Double... defValue)
Gets the attribute value from element as Double.

Parameters:
element - element where the attribute is determined from
attrName - name of the attribute
defValue - optional default value returned if attribute is not found (or empty)
Returns:
null if element is null or attribute is not specified in element

getFloatAttribute

public static Float getFloatAttribute(Element element,
                                      String attrName,
                                      Float... defValue)
Gets the attribute value from element as Float.

Parameters:
element - element where the attribute is determined from
attrName - name of the attribute
defValue - optional default value returned if attribute is not found (or empty)
Returns:
null if element is null or attribute is not specified in element

getColorAttribute

public static Color getColorAttribute(Element element,
                                      String attrName,
                                      Color... defValue)
Gets the attribute value from element as Color.

Parameters:
element - element where the attribute is determined from
attrName - name of the attribute
defValue - optional default value returned if attribute is not found (or empty)
Returns:
null if element is null or attribute is not specified in element

setAttribute

public static boolean setAttribute(Element element,
                                   String attrName,
                                   Object value,
                                   boolean inclNullAttr)
Sets an attribute value. The .toString() method is used to convert the object value to string.
Exceptions:

Parameters:
element - element the attribute is set for
attrName - name of the attribute to set
value - attribute value
inclNullAttr - if false and value is null the attribute is NOT SET
Returns:
true if the attribute is set

setNotNullAttribute

public static boolean setNotNullAttribute(Element element,
                                          String attrName,
                                          Object value)
Sets an attribute value if the value is not null. The .toString() method is used to convert the object value to string.
Exceptions:

Parameters:
element - element the attribute is set for
attrName - name of the attribute to set
value - attribute value
Returns:
true if the attribute is set