org.brickred.socialauth.util
Class XMLParseUtil

java.lang.Object
  extended by org.brickred.socialauth.util.XMLParseUtil

public class XMLParseUtil
extends Object

This is a utility class, which is used to read the xml files.

Author:
Tarun Nagpal

Constructor Summary
XMLParseUtil()
           
 
Method Summary
static DocumentBuilder getDocumentBuilder()
          Returns a DocumentBuilder, which is used for parsing XML documents.
static String getElementData(Element root, String elementName)
          Gets the text value of the specified element.
static String getElementData(Node node)
          Static helper function to get the element data of the specified node.
static Element loadXmlResource(InputStream in)
          Loads the imput stream and returns the root element.
static Element loadXmlResource(String fileName)
          Loads the xml file into an xml document and returns the root element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLParseUtil

public XMLParseUtil()
Method Detail

getElementData

public static String getElementData(Node node)
Static helper function to get the element data of the specified node.

Parameters:
node - the node where the text data resides; may be null in which case this funtion will return ""
Returns:
the complete text of the specified node, or an empty string if the node has no text or is null

getElementData

public static String getElementData(Element root,
                                    String elementName)
Gets the text value of the specified element.

Parameters:
root - the root of the element whose text is to be retrieved; assumed not to be null.
elementName - the name of the element whose text is to be retrieved.
Returns:
the retrieved text value of the specified element or null if root has no given element.

loadXmlResource

public static Element loadXmlResource(String fileName)
                               throws Exception
Loads the xml file into an xml document and returns the root element.

Parameters:
fileName - the fully qualified name of the XML file to load; assumed not to be null.
Returns:
root element of the xml document, never null.
Throws:
Exception - on any error

loadXmlResource

public static Element loadXmlResource(InputStream in)
                               throws Exception
Loads the imput stream and returns the root element.

Parameters:
in - Input Stream.
Returns:
root element of the xml document, never null.
Throws:
Exception - on any error

getDocumentBuilder

public static DocumentBuilder getDocumentBuilder()
Returns a DocumentBuilder, which is used for parsing XML documents.

Returns:
a DocumentBuilder which is used for parsing XML documents. Never null.


Copyright © 2013. All Rights Reserved.