edu.cmu.emulator.util
Class XMLUtil

java.lang.Object
  extended by edu.cmu.emulator.util.XMLUtil

public final class XMLUtil
extends Object

XML utlitiy routines.

Author:
Glenn Judd

Field Summary
(package private) static DocumentBuilderFactory docBuilderFactory
           
 
Constructor Summary
XMLUtil()
           
 
Method Summary
static boolean childExists(Element element, String tagName)
           
static Element convertToDom(byte[] msg, String rootElementName)
           
static Element convertToDom(InputStream inStream, String rootElementName)
           
static Element getChildByTagName(Document queryElement, String tagName)
          Return a single child by a given tag name.
static Element getChildByTagName(Element element, String tagName)
          Return a single child by a given tag name.
static Element getChildByTagName(Element element, String tagName, boolean required)
          Return a single child by a given tag name.
static ArrayList getChildrenByTagName(Document doc, String tagName)
          Return children that are Elements.
static ArrayList getChildrenByTagName(Element element, String tagName)
          Return all children matching a given tag name.
static Element getChoice(Element element, String[] choices)
          note getChoice doesn't handle the case where both an completely bogus entry and a valid choice are selected it simply picks the valid choice
static Element getElementChild(Element element, int index)
          Return nth child that is an Element.
static ArrayList getElementChildren(Document doc)
          Return children that are Elements.
static ArrayList getElementChildren(Element element)
          Return children that are Elements.
static Element getFirstElementChild(Document doc)
          Return first children that is an Element.
static Element getFirstElementChild(Element element)
          Return first children that is an Element.
static String getSingleTextContent(Element element)
          Return a single text child of an Element.
static String getSingleTextContent(Element element, boolean requireContent)
           
static boolean parseBoolean(Element element)
           
static boolean parseBooleanChild(Element element, String childName)
           
static double parseDouble(Element element)
           
static double parseDoubleChild(Element element, String childName)
           
static double parseDoubleChild(Element element, String childName, boolean required)
           
static int parseInt(Element element)
           
static int parseIntChild(Element element, String childName)
           
static long parseLong(Element element)
           
static long parseLongChild(Element element, String childName)
           
static String parseString(Element element)
           
static String parseStringChild(Element element, String childName)
           
static String parseStringChild(Element element, String childName, boolean required)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

docBuilderFactory

static DocumentBuilderFactory docBuilderFactory
Constructor Detail

XMLUtil

public XMLUtil()
Method Detail

getElementChildren

public static final ArrayList getElementChildren(Element element)
Return children that are Elements.

Parameters:
element - Element to find child Elements for

getElementChildren

public static final ArrayList getElementChildren(Document doc)
Return children that are Elements.

Parameters:
doc - Document to find child Elements for

getChildrenByTagName

public static final ArrayList getChildrenByTagName(Document doc,
                                                   String tagName)
Return children that are Elements.

Parameters:
doc - Document to find child Elements for

getFirstElementChild

public static final Element getFirstElementChild(Element element)
                                          throws DeserializationException
Return first children that is an Element.

Parameters:
element - element to find child Element for
Throws:
DeserializationException

getFirstElementChild

public static final Element getFirstElementChild(Document doc)
                                          throws DeserializationException
Return first children that is an Element.

Parameters:
doc - Document to find child Element for
Throws:
DeserializationException

getElementChild

public static final Element getElementChild(Element element,
                                            int index)
                                     throws DeserializationException
Return nth child that is an Element.

Parameters:
element - element to find child Element for
Throws:
DeserializationException

getSingleTextContent

public static final String getSingleTextContent(Element element)
                                         throws DeserializationException
Return a single text child of an Element. Multiple text children results in an exception

Parameters:
element - to return text for.
Throws:
DeserializationException

getSingleTextContent

public static final String getSingleTextContent(Element element,
                                                boolean requireContent)
                                         throws DeserializationException
Throws:
DeserializationException

childExists

public static final boolean childExists(Element element,
                                        String tagName)
                                 throws DeserializationException
Throws:
DeserializationException

getChildByTagName

public static final Element getChildByTagName(Element element,
                                              String tagName)
                                       throws DeserializationException
Return a single child by a given tag name. More than one matching child results in an exception being thrown.

Parameters:
element - Element to find child of
tagName - tag name to match
Throws:
DeserializationException

getChildByTagName

public static final Element getChildByTagName(Element element,
                                              String tagName,
                                              boolean required)
                                       throws DeserializationException
Return a single child by a given tag name. More than one matching child results in an exception being thrown.

Parameters:
element - Element to find child of
tagName - tag name to match
Throws:
DeserializationException

getChildrenByTagName

public static final ArrayList getChildrenByTagName(Element element,
                                                   String tagName)
                                            throws DeserializationException
Return all children matching a given tag name.

Parameters:
element - Element to find child of
tagName - tag name to match
Throws:
DeserializationException

getChildByTagName

public static final Element getChildByTagName(Document queryElement,
                                              String tagName)
                                       throws DeserializationException
Return a single child by a given tag name. More than one matching child results in an exception being thrown.

Parameters:
doc - Document to find child of
tagName - tag name to match
Throws:
DeserializationException

getChoice

public static final Element getChoice(Element element,
                                      String[] choices)
                               throws DeserializationException
note getChoice doesn't handle the case where both an completely bogus entry and a valid choice are selected it simply picks the valid choice

Throws:
DeserializationException

parseString

public static final String parseString(Element element)
                                throws DeserializationException
Throws:
DeserializationException

parseLong

public static final long parseLong(Element element)
                            throws DeserializationException
Throws:
DeserializationException

parseInt

public static final int parseInt(Element element)
                          throws DeserializationException
Throws:
DeserializationException

parseDouble

public static final double parseDouble(Element element)
                                throws DeserializationException
Throws:
DeserializationException

parseBoolean

public static final boolean parseBoolean(Element element)
                                  throws DeserializationException
Throws:
DeserializationException

parseStringChild

public static final String parseStringChild(Element element,
                                            String childName)
                                     throws DeserializationException
Throws:
DeserializationException

parseStringChild

public static final String parseStringChild(Element element,
                                            String childName,
                                            boolean required)
                                     throws DeserializationException
Throws:
DeserializationException

parseLongChild

public static final long parseLongChild(Element element,
                                        String childName)
                                 throws DeserializationException
Throws:
DeserializationException

parseIntChild

public static final int parseIntChild(Element element,
                                      String childName)
                               throws DeserializationException
Throws:
DeserializationException

parseBooleanChild

public static final boolean parseBooleanChild(Element element,
                                              String childName)
                                       throws DeserializationException
Throws:
DeserializationException

parseDoubleChild

public static final double parseDoubleChild(Element element,
                                            String childName)
                                     throws DeserializationException
Throws:
DeserializationException

parseDoubleChild

public static final double parseDoubleChild(Element element,
                                            String childName,
                                            boolean required)
                                     throws DeserializationException
Throws:
DeserializationException

convertToDom

public static Element convertToDom(byte[] msg,
                                   String rootElementName)
                            throws DeserializationException
Throws:
DeserializationException

convertToDom

public static Element convertToDom(InputStream inStream,
                                   String rootElementName)
                            throws DeserializationException
Throws:
DeserializationException


Copyright © 2013. All Rights Reserved.