hypercast.util
Class XmlUtil

java.lang.Object
  |
  +--hypercast.util.XmlUtil

public class XmlUtil
extends java.lang.Object

This is a class to implement some special functions for Xml document, for example, writing a Xml document to a file.


Constructor Summary
XmlUtil()
           
 
Method Summary
static void changeNodeOwner(org.w3c.dom.Document doc, org.w3c.dom.Node node)
          change the owner of a node and all its subnodes
static org.w3c.dom.Document createDocument()
          Creates a new Document class for the root of DOM trees.
static org.w3c.dom.Document createDocument(byte[] array)
           
static org.w3c.dom.Document createDocument(java.io.File xmlFile)
          Creates a new Document class from given XML File instance.
static org.w3c.dom.Document createDocument(java.io.InputStream xmlFileStream, java.lang.String fileName)
          Creates a new Document class from given XML File instance.
static org.w3c.dom.Document createDocument(java.lang.String xmlFilename)
           
static org.w3c.dom.Document createDocumentFromString(java.lang.String xmlDocString)
          Creates a new Document class from given XML string.
static org.w3c.dom.Element[] createSchemaElement(org.w3c.dom.Document doc, java.lang.String name, java.lang.String type, java.lang.String restrictionBase, java.lang.String patternValue)
          Return the element which represents a statistic in the schema document.
static org.apache.xpath.XPath createXPath(java.lang.String xpathStr)
           
static org.w3c.dom.Node findChildNode(org.w3c.dom.Node node, java.lang.String name)
          Find a children node by name
static java.lang.String getScalarStatsResult(hypercast.I_Stats stats, java.lang.String name)
          A static function to get the stats in an old fashion way to eliminate the hassle of dealing with XML
static java.lang.String getScalarValue(org.w3c.dom.Element result)
          Extract scalar value from a single Element result
static java.lang.String getScalarValue(org.w3c.dom.Element[] result)
           
static java.lang.String getStringFromDocument(org.w3c.dom.Document doc)
          Method to convert Document to String.
static org.w3c.dom.Element getXmlValue(org.w3c.dom.Document doc, java.lang.String xpath, java.lang.String value)
          Convert a String to an Xml Element that can be passed to a I_Stats
static org.w3c.dom.Element[] getXmlValues(org.w3c.dom.Document doc, java.lang.String xpath, java.lang.String value)
           
static void removeComments(org.w3c.dom.Document d, org.w3c.dom.Node n)
          Remove comments in a document.
static java.lang.String setScalarStatsResult(hypercast.I_Stats stats, java.lang.String xpath, java.lang.String value)
          A static function to set the stats in an old fashion way to eliminate the hassle of dealing with XML
static org.w3c.dom.Element[] valueToList(org.w3c.dom.Element value)
          Make a single Element value to a Element list
static void writeXml(org.w3c.dom.Document saveDoc, java.io.OutputStream output)
          Write Xml document to output stream
static void writeXml(org.w3c.dom.Document saveDoc, java.io.OutputStream output, boolean omit_declaration)
          Write Xml document to output stream
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlUtil

public XmlUtil()
Method Detail

createDocument

public static org.w3c.dom.Document createDocument()
Creates a new Document class for the root of DOM trees.


createDocument

public static org.w3c.dom.Document createDocument(java.lang.String xmlFilename)
                                           throws java.io.FileNotFoundException,
                                                  java.text.ParseException,
                                                  java.io.IOException
java.io.FileNotFoundException
java.text.ParseException
java.io.IOException

createDocument

public static org.w3c.dom.Document createDocument(java.io.File xmlFile)
                                           throws java.io.FileNotFoundException,
                                                  java.text.ParseException,
                                                  java.io.IOException
Creates a new Document class from given XML File instance.

Parameters:
xmlFile - a XML File instance.
Throws:
java.io.FileNotFoundException - If the file cannot be opened.
java.lang.NullPointerException - If the argument is null
java.io.IOException - on parse error
java.text.ParseException

createDocument

public static org.w3c.dom.Document createDocument(java.io.InputStream xmlFileStream,
                                                  java.lang.String fileName)
                                           throws java.io.IOException
Creates a new Document class from given XML File instance.

java.io.IOException

createDocumentFromString

public static org.w3c.dom.Document createDocumentFromString(java.lang.String xmlDocString)
                                                     throws java.text.ParseException
Creates a new Document class from given XML string.

Parameters:
xmlDocString - a XML document in string format.
java.text.ParseException
See Also:
getStringFromDocument(Document)

createDocument

public static org.w3c.dom.Document createDocument(byte[] array)
                                           throws java.text.ParseException
java.text.ParseException

getStringFromDocument

public static java.lang.String getStringFromDocument(org.w3c.dom.Document doc)
Method to convert Document to String.

Parameters:
doc - a Document instance.
See Also:
createDocumentFromString(String)

removeComments

public static void removeComments(org.w3c.dom.Document d,
                                  org.w3c.dom.Node n)
Remove comments in a document.

Parameters:
d - A Document instance.
n - Node which represents the subtree from which comments are removed.

writeXml

public static void writeXml(org.w3c.dom.Document saveDoc,
                            java.io.OutputStream output)
                     throws java.io.IOException
Write Xml document to output stream

Parameters:
saveDoc - the Xml document to write
output - the output stream
Throws:
java.io.IOException
java.io.IOException - if writing fails

writeXml

public static void writeXml(org.w3c.dom.Document saveDoc,
                            java.io.OutputStream output,
                            boolean omit_declaration)
                     throws java.io.IOException
Write Xml document to output stream

Parameters:
saveDoc - the Xml document to write
output - the output stream
omit_declaration - whether to omit the XML delcaration when outputing. Used "true "when want to put several XML docs in a single file.
Throws:
java.io.IOException
java.io.IOException - if writing fails

findChildNode

public static org.w3c.dom.Node findChildNode(org.w3c.dom.Node node,
                                             java.lang.String name)
Find a children node by name

Parameters:
node - the node to find the child node in
name - the name of child node to find
Returns:
the child node, or null if not found

changeNodeOwner

public static void changeNodeOwner(org.w3c.dom.Document doc,
                                   org.w3c.dom.Node node)
change the owner of a node and all its subnodes

Parameters:
doc - the new owner
node - the node to change owner of

getScalarStatsResult

public static java.lang.String getScalarStatsResult(hypercast.I_Stats stats,
                                                    java.lang.String name)
                                             throws HyperCastStatsException,
                                                    javax.xml.transform.TransformerException
A static function to get the stats in an old fashion way to eliminate the hassle of dealing with XML

Parameters:
stats - the I_Stas object
name - the name of the stats
Returns:
the String value of the stats if the result is not a tree
Throws:
javax.xml.transform.TransformerException
HyperCastStatsException

getScalarValue

public static java.lang.String getScalarValue(org.w3c.dom.Element result)
Extract scalar value from a single Element result


valueToList

public static org.w3c.dom.Element[] valueToList(org.w3c.dom.Element value)
Make a single Element value to a Element list


getScalarValue

public static java.lang.String getScalarValue(org.w3c.dom.Element[] result)

createSchemaElement

public static org.w3c.dom.Element[] createSchemaElement(org.w3c.dom.Document doc,
                                                        java.lang.String name,
                                                        java.lang.String type,
                                                        java.lang.String restrictionBase,
                                                        java.lang.String patternValue)
Return the element which represents a statistic in the schema document.

Parameters:
doc - The document to create the Element
name - The name of the created Element
type - The type of the statistic. It can be either SimpleType or ComplexType.
restrictionBase - When type is "simpleType", it is to specify the specific type of this statistic, such as "xsd:string". For ComplexType statistic, it is null.
patternValue - When type is "simpleType", it is to specify the format of the value under the specific restriction base. For ComplexType statistic, it is null.
Returns:
new created Element

createXPath

public static org.apache.xpath.XPath createXPath(java.lang.String xpathStr)
Parameters:
xpathStr - xpath string.
Returns:
XPath instance cooresponding to the given string.

getXmlValue

public static org.w3c.dom.Element getXmlValue(org.w3c.dom.Document doc,
                                              java.lang.String xpath,
                                              java.lang.String value)
Convert a String to an Xml Element that can be passed to a I_Stats

Parameters:
doc - The document to create the Element
xpath - The xpath string
value - The String value to convert
Returns:
The Element value

getXmlValues

public static org.w3c.dom.Element[] getXmlValues(org.w3c.dom.Document doc,
                                                 java.lang.String xpath,
                                                 java.lang.String value)

setScalarStatsResult

public static java.lang.String setScalarStatsResult(hypercast.I_Stats stats,
                                                    java.lang.String xpath,
                                                    java.lang.String value)
                                             throws HyperCastStatsException,
                                                    javax.xml.transform.TransformerException
A static function to set the stats in an old fashion way to eliminate the hassle of dealing with XML

Parameters:
stats - the stats object
value - the new value in String format
Returns:
the value of stats after set
Throws:
HyperCastStatsException
javax.xml.transform.TransformerException