org.ozoneDB.xml.dom4j
Class O3DocumentHelper

java.lang.Object
  extended byorg.ozoneDB.xml.dom4j.O3DocumentHelper

public class O3DocumentHelper
extends java.lang.Object

O3DocumentHelper is a collection of helper methods for using DOM4J.

Version:
$Revision: 1.3 $
Author:
James Strachan, Per Nyfelt

Constructor Summary
O3DocumentHelper()
           
 
Method Summary
static void configure(org.ozoneDB.OzoneInterface db)
           
static Attribute createAttribute(Element owner, QName qname, java.lang.String value)
           
static Attribute createAttribute(Element owner, java.lang.String name, java.lang.String value)
           
static CDATA createCDATA(java.lang.String text)
           
static Comment createComment(java.lang.String text)
           
static Document createDocument()
           
static Document createDocument(Element rootElement)
           
static Document createDocument(Element rootElement, java.lang.String name)
          creates a persistent Object with the given name
static Document createDocument(java.lang.String name)
          creates a persistent Object with the given name
static Element createElement(QName qname)
           
static Element createElement(java.lang.String name)
           
static Entity createEntity(java.lang.String name, java.lang.String text)
           
static Namespace createNamespace(java.lang.String prefix, java.lang.String uri)
           
static Pattern createPattern(java.lang.String xpathPattern)
          createPattern parses the given XPath expression to create an XSLT style Pattern instance which can then be used in an XSLT processing model.
static ProcessingInstruction createProcessingInstruction(java.lang.String target, java.util.Map data)
           
static ProcessingInstruction createProcessingInstruction(java.lang.String target, java.lang.String data)
           
static QName createQName(java.lang.String localName)
           
static QName createQName(java.lang.String localName, Namespace namespace)
           
static Text createText(java.lang.String text)
           
static XPath createXPath(java.lang.String xpathExpression)
          createXPath parses an XPath expression and creates a new XPath XPath instance using the singleton OzoneDocumentFactory.
static XPath createXPath(java.lang.String xpathExpression, org.jaxen.VariableContext variableContext)
          createXPath parses an XPath expression and creates a new XPath XPath instance using the singleton OzoneDocumentFactory.
static NodeFilter createXPathFilter(java.lang.String xpathFilterExpression)
          createXPathFilter parses a NodeFilter from the given XPath filter expression using the singleton OzoneDocumentFactory.
static void deleteDocument(Document doc)
           
static Document fetchDocument(java.lang.String name)
           
static OzoneDocumentFactory getFactory()
           
static SAXReader getSAXReader()
          Should not be used on the client side since the use will be quite slow (every sax event will result in a remote call).
static Element makeElement(Branch source, java.lang.String path)
          makeElement a helper method which navigates from the given Document or Element node to some Element using the path expression, creating any necessary elements along the way.
static Document parse(java.io.InputStream in)
          Since an InputStream is not serializable we convert the content to a String This might cause memory issues on big documents
static Document parse(java.io.InputStream in, java.lang.String objectName)
          Since an InputStream is not serializable we convert the content to a String This might cause memory issues on big documents
static Document parse(java.io.Reader reader)
          Since a Reader is not serializable we convert the content to a String This might cause memory issues on big documents
static Document parse(java.io.Reader reader, java.lang.String objectName)
          Since a Reader is not serializable we convert the content to a String This might cause memory issues on big documents
static Document parseRemote(java.io.InputStream in)
          This will probably not work but something to this effect needs to exist in order to send the stream content through the pipe over to the server
static Document parseText(java.lang.String text)
          parseText parses the given text as an XML document and returns the newly created Document.
static Document parseText(java.lang.String text, java.lang.String objectName)
           
static java.util.List selectNodes(java.lang.String xpathFilterExpression, java.util.List nodes)
          selectNodes performs the given XPath expression on the List of Node instances appending all the results together into a single list.
static java.util.List selectNodes(java.lang.String xpathFilterExpression, Node node)
          selectNodes performs the given XPath expression on the List of Node instances appending all the results together into a single list.
static void sort(java.util.List list, java.lang.String xpathExpression)
          sort sorts the given List of Nodes using an XPath expression as a Comparator.
static void sort(java.util.List list, java.lang.String xpathExpression, boolean distinct)
          sort sorts the given List of Nodes using an XPath expression as a Comparator and optionally removing duplicates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

O3DocumentHelper

public O3DocumentHelper()
Method Detail

configure

public static void configure(org.ozoneDB.OzoneInterface db)
                      throws java.lang.Exception
Throws:
java.lang.Exception

getFactory

public static OzoneDocumentFactory getFactory()
                                       throws java.lang.RuntimeException
Throws:
java.lang.RuntimeException

fetchDocument

public static Document fetchDocument(java.lang.String name)

deleteDocument

public static void deleteDocument(Document doc)

createDocument

public static Document createDocument()
                               throws java.lang.Exception
Throws:
java.lang.Exception

createDocument

public static Document createDocument(Element rootElement)
                               throws java.lang.Exception
Throws:
java.lang.Exception

createDocument

public static Document createDocument(java.lang.String name)
                               throws java.lang.Exception
creates a persistent Object with the given name

Throws:
java.lang.Exception

createDocument

public static Document createDocument(Element rootElement,
                                      java.lang.String name)
                               throws java.lang.Exception
creates a persistent Object with the given name

Throws:
java.lang.Exception

createElement

public static Element createElement(QName qname)
                             throws java.lang.Exception
Throws:
java.lang.Exception

createElement

public static Element createElement(java.lang.String name)
                             throws java.lang.Exception
Throws:
java.lang.Exception

createAttribute

public static Attribute createAttribute(Element owner,
                                        QName qname,
                                        java.lang.String value)
                                 throws java.lang.Exception
Throws:
java.lang.Exception

createAttribute

public static Attribute createAttribute(Element owner,
                                        java.lang.String name,
                                        java.lang.String value)
                                 throws java.lang.Exception
Throws:
java.lang.Exception

createCDATA

public static CDATA createCDATA(java.lang.String text)
                         throws java.lang.Exception
Throws:
java.lang.Exception

createComment

public static Comment createComment(java.lang.String text)
                             throws java.lang.Exception
Throws:
java.lang.Exception

createText

public static Text createText(java.lang.String text)
                       throws java.lang.Exception
Throws:
java.lang.Exception

createEntity

public static Entity createEntity(java.lang.String name,
                                  java.lang.String text)
                           throws java.lang.Exception
Throws:
java.lang.Exception

createNamespace

public static Namespace createNamespace(java.lang.String prefix,
                                        java.lang.String uri)
                                 throws java.lang.Exception
Throws:
java.lang.Exception

createProcessingInstruction

public static ProcessingInstruction createProcessingInstruction(java.lang.String target,
                                                                java.lang.String data)
                                                         throws java.lang.Exception
Throws:
java.lang.Exception

createProcessingInstruction

public static ProcessingInstruction createProcessingInstruction(java.lang.String target,
                                                                java.util.Map data)
                                                         throws java.lang.Exception
Throws:
java.lang.Exception

createQName

public static QName createQName(java.lang.String localName,
                                Namespace namespace)
                         throws java.lang.Exception
Throws:
java.lang.Exception

createQName

public static QName createQName(java.lang.String localName)
                         throws java.lang.Exception
Throws:
java.lang.Exception

createXPath

public static XPath createXPath(java.lang.String xpathExpression)
                         throws InvalidXPathException

createXPath parses an XPath expression and creates a new XPath XPath instance using the singleton OzoneDocumentFactory.

Parameters:
xpathExpression - is the XPath expression to create
Returns:
a new XPath instance
Throws:
InvalidXPathException - if the XPath expression is invalid

createXPath

public static XPath createXPath(java.lang.String xpathExpression,
                                org.jaxen.VariableContext variableContext)
                         throws InvalidXPathException,
                                java.lang.Exception

createXPath parses an XPath expression and creates a new XPath XPath instance using the singleton OzoneDocumentFactory.

Parameters:
xpathExpression - is the XPath expression to create
variableContext - is the variable context to use when evaluating the XPath
Returns:
a new XPath instance
Throws:
InvalidXPathException - if the XPath expression is invalid
java.lang.Exception

createXPathFilter

public static NodeFilter createXPathFilter(java.lang.String xpathFilterExpression)
                                    throws java.lang.Exception

createXPathFilter parses a NodeFilter from the given XPath filter expression using the singleton OzoneDocumentFactory. XPath filter expressions occur within XPath expressions such as self::node()[ filterExpression ]

Parameters:
xpathFilterExpression - is the XPath filter expression to create
Returns:
a new NodeFilter instance
Throws:
java.lang.Exception

createPattern

public static Pattern createPattern(java.lang.String xpathPattern)
                             throws java.lang.Exception

createPattern parses the given XPath expression to create an XSLT style Pattern instance which can then be used in an XSLT processing model.

Parameters:
xpathPattern - is the XPath pattern expression to create
Returns:
a new Pattern instance
Throws:
java.lang.Exception

selectNodes

public static java.util.List selectNodes(java.lang.String xpathFilterExpression,
                                         java.util.List nodes)
                                  throws java.lang.Exception

selectNodes performs the given XPath expression on the List of Node instances appending all the results together into a single list.

Parameters:
xpathFilterExpression - is the XPath filter expression to evaluate
nodes - is the list of nodes on which to evalute the XPath
Returns:
the results of all the XPath evaluations as a single list
Throws:
java.lang.Exception

selectNodes

public static java.util.List selectNodes(java.lang.String xpathFilterExpression,
                                         Node node)
                                  throws java.lang.Exception

selectNodes performs the given XPath expression on the List of Node instances appending all the results together into a single list.

Parameters:
xpathFilterExpression - is the XPath filter expression to evaluate
node - is the Node on which to evalute the XPath
Returns:
the results of all the XPath evaluations as a single list
Throws:
java.lang.Exception

sort

public static void sort(java.util.List list,
                        java.lang.String xpathExpression)
                 throws java.lang.Exception

sort sorts the given List of Nodes using an XPath expression as a Comparator.

Parameters:
list - is the list of Nodes to sort
xpathExpression - is the XPath expression used for comparison
Throws:
java.lang.Exception

sort

public static void sort(java.util.List list,
                        java.lang.String xpathExpression,
                        boolean distinct)
                 throws java.lang.Exception

sort sorts the given List of Nodes using an XPath expression as a Comparator and optionally removing duplicates.

Parameters:
list - is the list of Nodes to sort
xpathExpression - is the XPath expression used for comparison
distinct - if true then duplicate values (using the sortXPath for comparisions) will be removed from the List
Throws:
java.lang.Exception

parseText

public static Document parseText(java.lang.String text)
                          throws DocumentException

parseText parses the given text as an XML document and returns the newly created Document.

Parameters:
text - is the XML text to be parsed
Returns:
a newly parsed Document
Throws:
DocumentException - if the document could not be parsed

parseText

public static Document parseText(java.lang.String text,
                                 java.lang.String objectName)
                          throws DocumentException
Throws:
DocumentException

parse

public static Document parse(java.io.InputStream in)
                      throws DocumentException
Since an InputStream is not serializable we convert the content to a String This might cause memory issues on big documents

Parameters:
in -
Returns:
Throws:
DocumentException

parse

public static Document parse(java.io.InputStream in,
                             java.lang.String objectName)
                      throws DocumentException
Since an InputStream is not serializable we convert the content to a String This might cause memory issues on big documents

Parameters:
in -
Returns:
Throws:
DocumentException

parse

public static Document parse(java.io.Reader reader,
                             java.lang.String objectName)
                      throws DocumentException
Since a Reader is not serializable we convert the content to a String This might cause memory issues on big documents

Parameters:
reader -
Returns:
Throws:
DocumentException

parse

public static Document parse(java.io.Reader reader)
                      throws DocumentException
Since a Reader is not serializable we convert the content to a String This might cause memory issues on big documents

Parameters:
reader -
Returns:
Throws:
DocumentException

parseRemote

public static Document parseRemote(java.io.InputStream in)
                            throws java.lang.Exception
This will probably not work but something to this effect needs to exist in order to send the stream content through the pipe over to the server

Parameters:
in -
Returns:
Throws:
java.lang.Exception

getSAXReader

public static SAXReader getSAXReader()
Should not be used on the client side since the use will be quite slow (every sax event will result in a remote call). But if we are using LocalDatabase this is not the case so we might as well expose it since it gives much more flexibility

Returns:
a SAXREader used for SAX based parsing

makeElement

public static Element makeElement(Branch source,
                                  java.lang.String path)

makeElement

a helper method which navigates from the given Document or Element node to some Element using the path expression, creating any necessary elements along the way. For example the path a/b/c would get the first child <a> element, which would be created if it did not exist, then the next child <b> and so on until finally a <c> element is returned.

Parameters:
source - is the Element or Document to start navigating from
path - is a simple path expression, seperated by '/' which denotes the path from the source to the resulting element such as a/b/c
Returns:
the first Element on the given path which either already existed on the path or were created by this method.


Copyright © 2004 The Ozone Database Project - www.ozone-db.org. All Rights Reserved.