edu.memphis.ccrg.lida.framework.initialization
Class XmlUtils

java.lang.Object
  extended by edu.memphis.ccrg.lida.framework.initialization.XmlUtils

public class XmlUtils
extends java.lang.Object

Utilities for reading an XML file.

Author:
Javier Snaider, Ryan J. McCall

Constructor Summary
XmlUtils()
           
 
Method Summary
static boolean containsTag(org.w3c.dom.Element ele, java.lang.String tagName)
          Returns whether specified Element contains a child node with specified tagName
static boolean getBooleanValue(org.w3c.dom.Element ele, java.lang.String tagName)
          Returns a Boolean with value true if the first element inside specified element has specified tag contains 'true' ignoring case.
static org.w3c.dom.Element getChild(org.w3c.dom.Element parent, java.lang.String name)
          Returns the first child of specified Element with specified name.
static java.util.List<org.w3c.dom.Element> getChildren(org.w3c.dom.Element parent, java.lang.String name)
          Returns all children with specified name.
static java.util.List<org.w3c.dom.Element> getChildrenInGroup(org.w3c.dom.Element e, java.lang.String groupName, java.lang.String childName)
          Returns the Elements with name childName, in the group groupName inside the specified Element e.
static java.util.List<java.lang.String> getChildrenValues(org.w3c.dom.Element element, java.lang.String name)
          Gets the values of the children of the element with specified name.
static java.lang.Integer getIntegerValue(org.w3c.dom.Element ele, java.lang.String tagName)
          Returns Integer value of first element inside specified element with specified tag or else null.
static java.util.Map<java.lang.String,java.lang.Object> getParams(org.w3c.dom.Element moduleElement)
          Reads and creates a Properties from specified Element
static java.lang.String getTextValue(org.w3c.dom.Element ele, java.lang.String tagName)
          Returns text value of first element in specified element with specified tag.
static java.util.Map<java.lang.String,java.lang.Object> getTypedParams(org.w3c.dom.Element moduleElement)
          Reads typed parameters from xml element and returns them in a Map where the key is the parameter's String name and the value is the value of the parameter.
static java.lang.String getValue(org.w3c.dom.Element parent)
          Returns String value of first child found that is a Text.
static org.w3c.dom.Document parseXmlFile(java.lang.String fileName, java.lang.String schemaFilePath)
          Verifies and parses specified xml file into a Document.
static org.w3c.dom.Document parseXmlString(java.lang.String xml)
          Parses a String containing xml data into a dom Document
static boolean validateXmlFile(java.lang.String xmlFile, java.lang.String schemaFile)
          Validates specified XML file with specified XML schema file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlUtils

public XmlUtils()
Method Detail

validateXmlFile

public static boolean validateXmlFile(java.lang.String xmlFile,
                                      java.lang.String schemaFile)
Validates specified XML file with specified XML schema file

Parameters:
xmlFile - name of xml file
schemaFile - name of schema file
Returns:
true if the xml is valid under specified schema.

getTextValue

public static java.lang.String getTextValue(org.w3c.dom.Element ele,
                                            java.lang.String tagName)
Returns text value of first element in specified element with specified tag. Returns null if specified tag is empty or only has subchildren.

Parameters:
ele - Dom element
tagName - name of xml tag
Returns:
text value of element with specified xml tag

getIntegerValue

public static java.lang.Integer getIntegerValue(org.w3c.dom.Element ele,
                                                java.lang.String tagName)
Returns Integer value of first element inside specified element with specified tag or else null.

Parameters:
ele - Dom element
tagName - name of xml tag
Returns:
Integer value of first element with specified xml tag or null if no such value can be parsed

containsTag

public static boolean containsTag(org.w3c.dom.Element ele,
                                  java.lang.String tagName)
Returns whether specified Element contains a child node with specified tagName

Parameters:
ele - Element
tagName - tag name
Returns:
true if

getBooleanValue

public static boolean getBooleanValue(org.w3c.dom.Element ele,
                                      java.lang.String tagName)
Returns a Boolean with value true if the first element inside specified element has specified tag contains 'true' ignoring case. Returns false otherwise.

Parameters:
ele - Dom element
tagName - name of xml tag
Returns:
boolean value of element with specified xml tag

getParams

public static java.util.Map<java.lang.String,java.lang.Object> getParams(org.w3c.dom.Element moduleElement)
Reads and creates a Properties from specified Element

Parameters:
moduleElement - Dom element
Returns:
Properties

getTypedParams

public static java.util.Map<java.lang.String,java.lang.Object> getTypedParams(org.w3c.dom.Element moduleElement)
Reads typed parameters from xml element and returns them in a Map where the key is the parameter's String name and the value is the value of the parameter. Finds all tags named "param". Those tags should have two attributes, name and type. Valid parameters types are "int", "double", "boolean", and "string". If the value is not compatible with the specified type then value will be null, except in the case of a Boolean with an incompatible value, in which case the value will be False. If a parameter's value is not specified or empty then the value will be null.

Parameters:
moduleElement - Dom Element
Returns:
parameters indexed by name.

getChild

public static org.w3c.dom.Element getChild(org.w3c.dom.Element parent,
                                           java.lang.String name)
Returns the first child of specified Element with specified name.

Parameters:
parent - an Element
name - name of child specified
Returns:
child or null

getValue

public static java.lang.String getValue(org.w3c.dom.Element parent)
Returns String value of first child found that is a Text. or null if the Text is empty

Parameters:
parent - Element
Returns:
child's string value.

getChildrenValues

public static java.util.List<java.lang.String> getChildrenValues(org.w3c.dom.Element element,
                                                                 java.lang.String name)
Gets the values of the children of the element with specified name.

Parameters:
element - Parent Element
name - specified tag name
Returns:
values of children

getChildren

public static java.util.List<org.w3c.dom.Element> getChildren(org.w3c.dom.Element parent,
                                                              java.lang.String name)
Returns all children with specified name.

Parameters:
parent - Element
name - name of sought children
Returns:
list of all children found.

getChildrenInGroup

public static java.util.List<org.w3c.dom.Element> getChildrenInGroup(org.w3c.dom.Element e,
                                                                     java.lang.String groupName,
                                                                     java.lang.String childName)
Returns the Elements with name childName, in the group groupName inside the specified Element e. groupName must be a direct child of e.

Parameters:
e - Element
groupName - name of the group
childName - name of children Elements returned
Returns:
List of child Elements

parseXmlFile

public static org.w3c.dom.Document parseXmlFile(java.lang.String fileName,
                                                java.lang.String schemaFilePath)
Verifies and parses specified xml file into a Document.

Parameters:
fileName - the name of the file to parse
schemaFilePath - path to the schema file
Returns:
the DOM Document of the file fileName or null if the xml file is not valid

parseXmlString

public static org.w3c.dom.Document parseXmlString(java.lang.String xml)
Parses a String containing xml data into a dom Document

Parameters:
xml - the string with xml data
Returns:
a dom Document