edu.ucsb.cs.jicos.services.external
Class XmlDocument

java.lang.Object
  extended by edu.ucsb.cs.jicos.services.external.XmlDocument
All Implemented Interfaces:
ExternalData, java.io.Serializable

public class XmlDocument
extends java.lang.Object
implements java.io.Serializable, ExternalData

See Also:
Serialized Form

Field Summary
static java.lang.String CRLF
          Line terminator.
protected  org.w3c.dom.Document document
           
protected  java.lang.String xmlText
           
 
Constructor Summary
XmlDocument()
          No-argument constructor of XmlDocument.
XmlDocument(org.w3c.dom.Element element)
          Construct an XmlDocument from a DOM (XML) element.
XmlDocument(ExternalData externalData)
          Construct an XmlDocument on external data.
XmlDocument(java.io.File file)
          Construct an XmlDocument from a XML file.
XmlDocument(java.util.List list)
          Construct an XmlDocument from a list.
XmlDocument(org.w3c.dom.Node rootNode)
          Construct an XmlDocument from an XML node
XmlDocument(java.lang.String xml)
          Construct an XmlDocument from an XML-encoded string.
XmlDocument(TaskExternal task, java.lang.Object result)
          Construct an XmlDocument from a Task, and it's result.
XmlDocument(java.lang.Throwable exception)
          Create an XML document from an exception.
XmlDocument(XmlDocument xmlDocument)
          Copy constructor.
 
Method Summary
 boolean add(Invoice invoice)
           
 java.lang.String[] getArray(java.lang.String xpathQuery)
          Get an individual value from the document.
 org.w3c.dom.Document getDocument()
          Get the raw XML (DOM - Document Object Model) document.
 org.w3c.dom.Element[] getElement(java.lang.String xpathQuery)
          Get an individual value from the document.
 java.lang.String getText()
          Get the text used to create the DOM.
 java.lang.String getValue(java.lang.String xpathQuery)
          Get an individual value from the document.
static void main(java.lang.String[] cmdLine)
           
 boolean parse(java.io.File xmlFile)
          Parse XML-encoded text.
 boolean parse(java.lang.String xmlString)
          Parse XML-encoded text.
 ExternalData removeWrapper()
          Get the data out of the (optional) wrapper.
 java.lang.String toHtmlString()
          Convert the document to an XML-encoded string that can be interpreted as HTML.
static java.lang.String toHtmlString(java.lang.Throwable exception)
          Convert the exception to an XML-encoded string that can be interpreted as HTML.
 java.lang.String toString()
          Convert the document to a "Java" string (class[member, [...]]).
 java.lang.String toVerboseString()
          Convert the document to a (human readable) string.
 java.lang.String toXmlString()
          Convert the document to an XML-encoded string.
static java.lang.String toXmlString(java.lang.Throwable exception)
          Convert the exception to an XML-encoded string.
 java.lang.String Transform(org.w3c.dom.Document xsltStyleSheet)
          Convert the DOM object to a string using a particular stylesheet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CRLF

public static final java.lang.String CRLF
Line terminator.

See Also:
Constant Field Values

xmlText

protected java.lang.String xmlText

document

protected org.w3c.dom.Document document
Constructor Detail

XmlDocument

public XmlDocument()
No-argument constructor of XmlDocument.


XmlDocument

public XmlDocument(java.lang.String xml)
            throws org.xml.sax.SAXException,
                   java.io.IOException
Construct an XmlDocument from an XML-encoded string.

Parameters:
xml - An XML-encoded string.
Throws:
org.xml.sax.SAXException
java.io.IOException

XmlDocument

public XmlDocument(java.io.File file)
            throws org.xml.sax.SAXException,
                   java.io.IOException
Construct an XmlDocument from a XML file.

Parameters:
file - File containing XML.
Throws:
org.xml.sax.SAXException
java.io.IOException

XmlDocument

public XmlDocument(TaskExternal task,
                   java.lang.Object result)
            throws java.lang.Exception
Construct an XmlDocument from a Task, and it's result.

Parameters:
task - A Jicos task.
result - The result of a compute on the above task.
Throws:
java.lang.Exception

XmlDocument

public XmlDocument(XmlDocument xmlDocument)
Copy constructor.

Parameters:
xmlDocument - An XmlDocument instance.

XmlDocument

public XmlDocument(org.w3c.dom.Node rootNode)
Construct an XmlDocument from an XML node

Parameters:
rootNode - A node in a DOM (XML) tree.

XmlDocument

public XmlDocument(ExternalData externalData)
Construct an XmlDocument on external data.

Parameters:
externalData - External data - currently a XmlDocument or List.
Throws:
java.lang.IllegalArgumentException - If the externalData cannot be converted.

XmlDocument

public XmlDocument(java.util.List list)
            throws java.lang.Exception
Construct an XmlDocument from a list.

Parameters:
list - A list of key/value pairs.
Throws:
java.lang.Exception - Catch-all
See Also:
createFromList(List)

XmlDocument

public XmlDocument(org.w3c.dom.Element element)
Construct an XmlDocument from a DOM (XML) element.

Parameters:
element - A DOM element.

XmlDocument

public XmlDocument(java.lang.Throwable exception)
Create an XML document from an exception. This does NOT throw any exceptions as it is usually called in a catch block of a different exception.

Parameters:
exception - The badness that occurred.
Method Detail

getText

public java.lang.String getText()
Get the text used to create the DOM.


getDocument

public org.w3c.dom.Document getDocument()
Get the raw XML (DOM - Document Object Model) document.


add

public boolean add(Invoice invoice)

parse

public boolean parse(java.io.File xmlFile)
              throws org.xml.sax.SAXException,
                     java.io.IOException
Parse XML-encoded text.

Parameters:
xmlFile - File containing XML-encoded text.
Returns:
Success (true), or failure (false ).
Throws:
org.xml.sax.SAXException
java.io.IOException

parse

public boolean parse(java.lang.String xmlString)
              throws org.xml.sax.SAXException,
                     java.io.IOException
Parse XML-encoded text.

Parameters:
xmlString - String containing XML-encoded text.
Returns:
Success (true), or failure (false ).
Throws:
org.xml.sax.SAXException
java.io.IOException

getElement

public org.w3c.dom.Element[] getElement(java.lang.String xpathQuery)
Get an individual value from the document. This supports a very limited subset of the XPath queries. Right now, it only supports paths, leaves, and attributes. Although it will return an array of nodes IFF they are the leaf nodes. SOME Limitations:

Parameters:
xpathQuery - An XPath query.
Returns:
An individual node.

getValue

public java.lang.String getValue(java.lang.String xpathQuery)
Get an individual value from the document. This supports a very limited subset of the XPath queries. Right now, it only supports paths, leaves, and attributes. SOME Known Limitations:
Selections:

Specified by:
getValue in interface ExternalData
Parameters:
xpathQuery - An XPath query.
Returns:
An individual string value.

getArray

public java.lang.String[] getArray(java.lang.String xpathQuery)
Get an individual value from the document. This supports a very limited subset of the XPath queries. Right now, it only supports paths, leaves, and attributes. SOME Known Limitations:
Selections:

Specified by:
getArray in interface ExternalData
Parameters:
xpathQuery - An XPath query.
Returns:
An individual string value.

removeWrapper

public ExternalData removeWrapper()
Get the data out of the (optional) wrapper. This may return the same object.

Specified by:
removeWrapper in interface ExternalData
Returns:
The data.

toXmlString

public static java.lang.String toXmlString(java.lang.Throwable exception)
Convert the exception to an XML-encoded string.

Returns:
An XML encoded string representing the exception.

toXmlString

public java.lang.String toXmlString()
Convert the document to an XML-encoded string.

Returns:
An XML encoded string representing the current DOM structure.

toHtmlString

public static java.lang.String toHtmlString(java.lang.Throwable exception)
Convert the exception to an XML-encoded string that can be interpreted as HTML.

Returns:
An HTML encoded string representing the exception.

toHtmlString

public java.lang.String toHtmlString()
Convert the document to an XML-encoded string that can be interpreted as HTML.
The necessary conversions are:


toString

public java.lang.String toString()
Convert the document to a "Java" string (class[member, [...]]).

Overrides:
toString in class java.lang.Object
Returns:
An instance of the correct result.

toVerboseString

public java.lang.String toVerboseString()
Convert the document to a (human readable) string.

Returns:
An instance of the correct result.

Transform

public java.lang.String Transform(org.w3c.dom.Document xsltStyleSheet)
Convert the DOM object to a string using a particular stylesheet.

Parameters:
xsltStyleSheet - The style sheet to use for the transformation.

main

public static void main(java.lang.String[] cmdLine)
                 throws java.lang.Exception
Throws:
java.lang.Exception


Jicos: http://cs.ucsb.edu/projects/jicos