org.greenstone.gs3client.data
Class ParseUtil

java.lang.Object
  extended by org.greenstone.gs3client.data.ParseUtil

public class ParseUtil
extends java.lang.Object

Some useful, general response XML message parsing functions for the JavaClient's data classes.

Author:
ak19

Constructor Summary
ParseUtil()
           
 
Method Summary
static java.util.Vector getAllChildElementsCalled(org.w3c.dom.Element el, java.lang.String childrenName)
           
static java.lang.String getBodyTextValue(org.w3c.dom.Element tag)
           
static java.util.HashMap getElementValuesForAttr(org.w3c.dom.Element parentEl, java.lang.String elName, java.lang.String attrName)
          Given an Element <parentEl>, finds all direct child elements called <elName> that have an attribute named attrName: <elName attrName=value>bodytext</elName> This is particularly useful for extracting info for those cases where elName=<displayItem> and where the attrName is "name".
static org.w3c.dom.Element getFirstChildElementCalled(org.w3c.dom.Element parent, java.lang.String childElementName)
          Method that returns the first child element of parent whose tagname is childElementName.
static org.w3c.dom.Element getFirstDescElementCalled(org.w3c.dom.Element parent, java.lang.String descElementName)
          Method that returns the first descendant element of parent whose tagname is descElementName.
static java.util.Vector getListElementsAsArray(org.w3c.dom.Element parent, java.lang.String listElementName, java.lang.String childElementName)
          Given an xml element ('parent'), it looks through its direct children to find the <listElementName> tag and extracts each child called <childElementName> element from it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParseUtil

public ParseUtil()
Method Detail

getBodyTextValue

public static java.lang.String getBodyTextValue(org.w3c.dom.Element tag)
Parameters:
tag - is the XML element from which the body text value will be extracted.
Returns:
the bodyText nested within the tag element, if any. Otherwise, this method returns empty String.

getAllChildElementsCalled

public static java.util.Vector getAllChildElementsCalled(org.w3c.dom.Element el,
                                                         java.lang.String childrenName)
Parameters:
el - is the element whose child elements are returned.
childrenName - is the name of the child elements to be extracted and returned.
Returns:
a vector containing all child elements of parent that are called childrenName. Returns null if there are no such child elements.

getListElementsAsArray

public static java.util.Vector getListElementsAsArray(org.w3c.dom.Element parent,
                                                      java.lang.String listElementName,
                                                      java.lang.String childElementName)
Given an xml element ('parent'), it looks through its direct children to find the <listElementName> tag and extracts each child called <childElementName> element from it. These are all added into a Vector which is returned.

Parameters:
parent - is the XML element from which the specified descendant elements are identified and returned.
listElementName - is the name of the child element of parent that we are looking for, whose child elements will be returned.
Returns:
a vector of Element items, all children <childelementName> of the first <listElementName> child of parameter called parent.

getFirstChildElementCalled

public static org.w3c.dom.Element getFirstChildElementCalled(org.w3c.dom.Element parent,
                                                             java.lang.String childElementName)
Method that returns the first child element of parent whose tagname is childElementName.

Parameters:
parent - is the element whose child element (if called childElementName) is returned.
childElementName - is the name of the child element to look for in parent.
Returns:
the first *child* element of <parent> that is <childElementName>. Null is returned if there are none.

getFirstDescElementCalled

public static org.w3c.dom.Element getFirstDescElementCalled(org.w3c.dom.Element parent,
                                                            java.lang.String descElementName)
Method that returns the first descendant element of parent whose tagname is descElementName.

Parameters:
parent - is the element whose descendant element (if called descElementName) is returned.
descElementName - is the name of the descendant element to look for in parent.
Returns:
the first descendant element of <parent> that is <descElementName>. Null is returned if there are none.

getElementValuesForAttr

public static java.util.HashMap getElementValuesForAttr(org.w3c.dom.Element parentEl,
                                                        java.lang.String elName,
                                                        java.lang.String attrName)
Given an Element <parentEl>, finds all direct child elements called <elName> that have an attribute named attrName: <elName attrName=value>bodytext</elName> This is particularly useful for extracting info for those cases where elName=<displayItem> and where the attrName is "name".

Parameters:
parentEl - is the parent element whose children are searched
elName - is the name to search for among the child elements of parentEl
attrName - is the name of the attribute to look for in the child element (of parentEl) whose tag name is elName.
Returns:
a Hashmap of all the (value, body) instances found.