org.vfny.geoserver.global.xml
Class ReaderUtils

java.lang.Object
  extended byorg.vfny.geoserver.global.xml.ReaderUtils

public class ReaderUtils
extends java.lang.Object

ReaderUtils purpose.

This class is intended to be used as a library of XML relevant operation for the XMLConfigReader class.

See Also:
XMLConfigReader

Method Summary
static java.io.File checkFile(java.io.File file, boolean isDir)
          Checks to ensure the file is valid.
static java.lang.String getAttribute(org.w3c.dom.Element elem, java.lang.String attName, boolean mandatory)
          getIntAttribute purpose.
static boolean getBooleanAttribute(org.w3c.dom.Element elem, java.lang.String attName, boolean mandatory)
          getBooleanAttribute purpose.
static org.w3c.dom.Element getChildElement(org.w3c.dom.Element root, java.lang.String name)
          getChildElement purpose.
static org.w3c.dom.Element getChildElement(org.w3c.dom.Element root, java.lang.String name, boolean mandatory)
          getChildElement purpose.
static java.lang.String getChildText(org.w3c.dom.Element root, java.lang.String childName)
          getChildText purpose.
static java.lang.String getChildText(org.w3c.dom.Element root, java.lang.String childName, boolean mandatory)
          getChildText purpose.
static double getDoubleAttribute(org.w3c.dom.Element elem, java.lang.String attName, boolean mandatory)
          getDoubleAttribute purpose.
static java.lang.String getElementText(org.w3c.dom.Element elem)
          getChildText purpose.
static java.lang.String getElementText(org.w3c.dom.Element elem, boolean mandatory)
          getChildText purpose.
static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Element root)
          getFirstChildElement purpose.
static int getIntAttribute(org.w3c.dom.Element elem, java.lang.String attName, boolean mandatory, int defaultValue)
          getIntAttribute purpose.
static java.lang.String[] getKeyWords(org.w3c.dom.Element keywordsElem)
          getKeyWords purpose.
static org.w3c.dom.Element loadConfig(java.io.Reader configFile)
          loadConfig purpose.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadConfig

public static org.w3c.dom.Element loadConfig(java.io.Reader configFile)
                                      throws ConfigurationException
loadConfig purpose.

Parses the specified file into a DOM tree.

Parameters:
configFile - The file to parse int a DOM tree.
Returns:
the resulting DOM tree
Throws:
ConfigurationException

checkFile

public static java.io.File checkFile(java.io.File file,
                                     boolean isDir)
                              throws ConfigurationException
Checks to ensure the file is valid.

Returns the file passed in to allow this to wrap file creations.

Parameters:
file - A file Handle to test.
isDir - true when the File passed in is expected to be a directory, false when the handle is expected to be a file.
Returns:
the File handle passed in
Throws:
ConfigurationException - When the file does not exist or is not the type specified.

getChildElement

public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element root,
                                                  java.lang.String name,
                                                  boolean mandatory)
                                           throws ConfigurationException
getChildElement purpose.

Used to help with XML manipulations. Returns the first child element of the specified name. An exception occurs when the node is required and not found.

Parameters:
root - The root element to look for children in.
name - The name of the child element to look for.
mandatory - true when an exception should be thrown if the child element does not exist.
Returns:
The child element found, null if not found.
Throws:
ConfigurationException - When a child element is required and not found.

getChildElement

public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element root,
                                                  java.lang.String name)
getChildElement purpose.

Used to help with XML manipulations. Returns the first child element of the specified name.

Parameters:
root - The root element to look for children in.
name - The name of the child element to look for.
Returns:
The child element found, null if not found.
See Also:
getChildElement(Element,String,boolean)

getIntAttribute

public static int getIntAttribute(org.w3c.dom.Element elem,
                                  java.lang.String attName,
                                  boolean mandatory,
                                  int defaultValue)
                           throws ConfigurationException
getIntAttribute purpose.

Used to help with XML manipulations. Returns the first child integer attribute of the specified name. An exception occurs when the node is required and not found.

Parameters:
elem - The root element to look for children in.
attName - The name of the attribute to look for.
mandatory - true when an exception should be thrown if the attribute element does not exist.
defaultValue - a default value to return incase the attribute was not found. mutually exclusive with the ConfigurationException thrown.
Returns:
The int value if the attribute was found, the default otherwise.
Throws:
ConfigurationException - When a attribute element is required and not found.

getAttribute

public static java.lang.String getAttribute(org.w3c.dom.Element elem,
                                            java.lang.String attName,
                                            boolean mandatory)
                                     throws ConfigurationException
getIntAttribute purpose.

Used to help with XML manipulations. Returns the first child integer attribute of the specified name. An exception occurs when the node is required and not found.

Parameters:
elem - The root element to look for children in.
attName - The name of the attribute to look for.
mandatory - true when an exception should be thrown if the attribute element does not exist.
Returns:
The value if the attribute was found, the null otherwise.
Throws:
ConfigurationException - When a child attribute is required and not found.

getBooleanAttribute

public static boolean getBooleanAttribute(org.w3c.dom.Element elem,
                                          java.lang.String attName,
                                          boolean mandatory)
                                   throws ConfigurationException
getBooleanAttribute purpose.

Used to help with XML manipulations. Returns the first child integer attribute of the specified name. An exception occurs when the node is required and not found.

Parameters:
elem - The root element to look for children in.
attName - The name of the attribute to look for.
mandatory - true when an exception should be thrown if the attribute element does not exist.
Returns:
The value if the attribute was found, the false otherwise.
Throws:
ConfigurationException - When a child attribute is required and not found.

getChildText

public static java.lang.String getChildText(org.w3c.dom.Element root,
                                            java.lang.String childName)
getChildText purpose.

Used to help with XML manipulations. Returns the first child text value of the specified element name.

Parameters:
root - The root element to look for children in.
childName - The name of the attribute to look for.
Returns:
The value if the child was found, the null otherwise.

getChildText

public static java.lang.String getChildText(org.w3c.dom.Element root,
                                            java.lang.String childName,
                                            boolean mandatory)
                                     throws ConfigurationException
getChildText purpose.

Used to help with XML manipulations. Returns the first child text value of the specified element name. An exception occurs when the node is required and not found.

Parameters:
root - The root element to look for children in.
childName - The name of the attribute to look for.
mandatory - true when an exception should be thrown if the text does not exist.
Returns:
The value if the child was found, the null otherwise.
Throws:
ConfigurationException - When a child attribute is required and not found.

getElementText

public static java.lang.String getElementText(org.w3c.dom.Element elem)
getChildText purpose.

Used to help with XML manipulations. Returns the text value of the specified element name.

Parameters:
elem - The root element to look for children in.
Returns:
The value if the text was found, the null otherwise.

getElementText

public static java.lang.String getElementText(org.w3c.dom.Element elem,
                                              boolean mandatory)
                                       throws ConfigurationException
getChildText purpose.

Used to help with XML manipulations. Returns the text value of the specified element name. An exception occurs when the node is required and not found.

Parameters:
elem - The root element to look for children in.
mandatory - true when an exception should be thrown if the text does not exist.
Returns:
The value if the text was found, the null otherwise.
Throws:
ConfigurationException - When text is required and not found.

getKeyWords

public static java.lang.String[] getKeyWords(org.w3c.dom.Element keywordsElem)
getKeyWords purpose.

Used to help with XML manipulations. Returns a list of keywords that were found.

Parameters:
keywordsElem - The root element to look for children in.
Returns:
The list of keywords that were found.

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Element root)
getFirstChildElement purpose.

Used to help with XML manipulations. Returns the element which represents the first child.

Parameters:
root - The root element to look for children in.
Returns:
The element if a child was found, the null otherwise.

getDoubleAttribute

public static double getDoubleAttribute(org.w3c.dom.Element elem,
                                        java.lang.String attName,
                                        boolean mandatory)
                                 throws ConfigurationException
getDoubleAttribute purpose.

Used to help with XML manipulations. Returns the first child integer attribute of the specified name. An exception occurs when the node is required and not found.

Parameters:
elem - The root element to look for children in.
attName - The name of the attribute to look for.
mandatory - true when an exception should be thrown if the attribute element does not exist.
Returns:
The double value if the attribute was found, the NaN otherwise.
Throws:
ConfigurationException - When a attribute element is required and not found.