org.teiid.internal.core.xml
Class JdomHelper

java.lang.Object
  extended by org.teiid.internal.core.xml.JdomHelper

public class JdomHelper
extends java.lang.Object


Field Summary
static java.lang.String DEFAULT_INDENT
          Default indentation upon write
static boolean DEFAULT_VALIDATION
          Default validation upon reading
static int LEVEL_ORDER_TRAVERSAL
           
static int POST_ORDER_TRAVERSAL
           
static int PRE_ORDER_TRAVERSAL
          JDOM tree navigation specifiers
 
Constructor Summary
JdomHelper()
           
 
Method Summary
static org.jdom.Document buildDocument(java.io.File file)
           Creates an instance of the JDOM Document for the specified file.
static org.jdom.Document buildDocument(java.io.InputStream stream)
           Creates an instance of the JDOM Document for the specified stream.
static org.jdom.Document buildDocument(java.io.InputStream stream, boolean validateXML)
           Creates an instance of the JDOM Document for the specified stream.
static org.jdom.Document buildDocument(java.io.Reader stream)
           Creates an instance of the JDOM Document for the specified stream.
static org.jdom.Document buildDocument(java.io.Reader stream, boolean validateXML)
           Creates an instance of the JDOM Document for the specified stream.
static org.jdom.Document buildDocument(java.lang.String filename)
           Creates an instance of the JDOM Document for the specified file.
static org.jdom.Document buildDocument(java.lang.String filename, boolean validateXML)
           Creates an instance of the JDOM Document for the specified file.
static org.jdom.Document buildDocument(java.lang.String saxDriverClass, java.io.File file, boolean validateXML)
           Creates an instance of the JDOM Document for the specified file.
static org.jdom.Document buildDocument(java.lang.String saxDriverClass, java.io.InputStream stream, boolean validateXML)
           Creates an instance of the JDOM Document for the specified stream.
static org.jdom.Document buildDocument(java.lang.String saxDriverClass, java.io.Reader stream, boolean validateXML)
           Creates an instance of the JDOM Document for the specified stream.
static org.jdom.Document buildDocument(java.lang.String saxDriverClass, java.lang.String filename, boolean validateXML)
           Creates an instance of the JDOM Document for the specified file.
static org.jdom.Document createNewDocument(java.lang.String rootTag)
           Create a new JDOM Docment with a root Element of the specified name.
static org.jdom.Element findElement(org.jdom.Element parent, java.lang.String name)
           This returns the first element that is a descendent of this element and matches given local name.
static org.jdom.Element findElement(org.jdom.Element parent, java.lang.String name, org.jdom.Namespace ns)
           This returns the first element that is a descendent of this element and matches the specified local name and Namespace.
static java.lang.String getContentValue(java.lang.Object jdomObject)
          Get the best content value for a JDOM object.
static int getDescendentCount(org.jdom.Element parent)
           This returns the number of elements that are descendents of this element.
static int getDescendentCount(org.jdom.Element parent, org.jdom.Namespace ns)
           This returns the number of elements that are descendents of this element and belonging to the specified Namespace.
static int getDescendentCount(org.jdom.Element parent, java.lang.String name)
           This returns the number of elements that are descendents of this element with the given local name.
static java.util.List getDescendents(org.jdom.Element parent)
           This returns a List of Element objects that are descendents of this element.
static java.util.List getDescendents(org.jdom.Element parent, org.jdom.Namespace ns)
           This returns a List of all elements that are descendents of this element belonging to the specified Namespace, returned as Element objects.
static java.util.List getDescendents(org.jdom.Element parent, java.lang.String name)
           This returns a List of all elements that are descendents of this element with the given local name, returned as Element objects.
static java.util.List getDescendents(org.jdom.Element parent, java.lang.String name, org.jdom.Namespace ns)
           This returns a List of all elements that are descendents of this element with the given local name and belonging to the specified Namespace, returned as Element objects.
static java.util.List getDescendents(int traversalMethod, org.jdom.Element parent, org.jdom.Namespace ns)
           This returns a List of Element objects that are descendents of this element and within the specified Namespace.
static org.jdom.output.Format getFormat(java.lang.String indent, boolean newlines)
           
static void levelOrderTraversal(org.jdom.Element parent, org.teiid.internal.core.xml.XMLVisitor v)
           Implements a level order traversal of the JDOM tree in which all nodes of the tree are recursively visited by depth: first children of the parent, then grandchildren of the parent (children of children) and so on.
static void postOrderTraversal(org.jdom.Element parent, org.teiid.internal.core.xml.XMLVisitor v)
           Implements a post-order traversal of the JDOM tree in which any subtrees are processed first then parent The visit method of the specified XMLVisitor is invoked on each node during the traversal.
static void preOrderTraversal(org.jdom.Element parent, org.teiid.internal.core.xml.XMLVisitor v)
           Implements a pre-order traversal of the JDOM tree in which a parent node is processed first then an subtrees.
static void print(java.io.PrintStream stream, org.jdom.Document doc)
           
static java.lang.String write(org.jdom.Document doc)
           Return the current JDOM Document as a String.
static void write(org.jdom.Document doc, java.io.OutputStream stream)
           Ouput the current JDOM Document to the output stream.
static void write(org.jdom.Document doc, java.io.OutputStream stream, java.lang.String indent, boolean newlines)
           Ouput the current JDOM Document to the output stream.
static void write(org.jdom.Document doc, java.lang.String filename)
           Ouput this JDOM Document to a file with the specified name.
static java.lang.String write(org.jdom.Document doc, java.lang.String indent, boolean newlines)
           Ouput the current JDOM Document as a String.
static void write(org.jdom.Document doc, java.lang.String filename, java.lang.String indent, boolean newlines)
           Ouput the current JDOM Document to a file with the specified name.
static void write(org.jdom.Document doc, java.io.Writer writer)
           Ouput the current JDOM Document to the output stream.
static void write(org.jdom.Document doc, java.io.Writer writer, java.lang.String indent, boolean newlines)
           Ouput the current JDOM Document to the writter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INDENT

public static final java.lang.String DEFAULT_INDENT
Default indentation upon write

See Also:
Constant Field Values

DEFAULT_VALIDATION

public static final boolean DEFAULT_VALIDATION
Default validation upon reading

See Also:
Constant Field Values

PRE_ORDER_TRAVERSAL

public static final int PRE_ORDER_TRAVERSAL
JDOM tree navigation specifiers

See Also:
Constant Field Values

POST_ORDER_TRAVERSAL

public static final int POST_ORDER_TRAVERSAL
See Also:
Constant Field Values

LEVEL_ORDER_TRAVERSAL

public static final int LEVEL_ORDER_TRAVERSAL
See Also:
Constant Field Values
Constructor Detail

JdomHelper

public JdomHelper()
Method Detail

buildDocument

public static org.jdom.Document buildDocument(java.lang.String filename)
                                       throws java.io.IOException,
                                              org.jdom.JDOMException

Creates an instance of the JDOM Document for the specified file.

Parameters:
filename - String name of file.
the - document instance
Throws:
java.io.IOException - if the file does not exist.
org.jdom.JDOMException - when errors occur in parsing.

buildDocument

public static org.jdom.Document buildDocument(java.io.File file)
                                       throws java.io.IOException,
                                              org.jdom.JDOMException

Creates an instance of the JDOM Document for the specified file.

Parameters:
file - File .
the - document instance
Throws:
java.io.IOException - if the file does not exist.
org.jdom.JDOMException - when errors occur in parsing.

buildDocument

public static org.jdom.Document buildDocument(java.lang.String filename,
                                              boolean validateXML)
                                       throws java.io.IOException,
                                              org.jdom.JDOMException

Creates an instance of the JDOM Document for the specified file.

Parameters:
filename - String name of file.
validateXML - indicates whether to validate the XML document using the DTD referenced in the XML file.
the - document instance
Throws:
java.io.IOException - if the file does not exist.
org.jdom.JDOMException - when errors occur in parsing.

buildDocument

public static org.jdom.Document buildDocument(java.lang.String saxDriverClass,
                                              java.lang.String filename,
                                              boolean validateXML)
                                       throws java.io.IOException,
                                              org.jdom.JDOMException

Creates an instance of the JDOM Document for the specified file.

Parameters:
saxDriverClass - String name of driver class to use.
filename - String name of file.
validateXML - indicates whether to validate the XML document using the DTD referenced in the XML file.
the - document instance
Throws:
java.io.IOException - if the file does not exist.
org.jdom.JDOMException - when errors occur in parsing.

buildDocument

public static org.jdom.Document buildDocument(java.lang.String saxDriverClass,
                                              java.io.File file,
                                              boolean validateXML)
                                       throws java.io.IOException,
                                              org.jdom.JDOMException

Creates an instance of the JDOM Document for the specified file.

Parameters:
saxDriverClass - String name of driver class to use.
file - File.
validateXML - indicates whether to validate the XML document using the DTD referenced in the XML file.
the - document instance
Throws:
java.io.IOException - if the file does not exist.
org.jdom.JDOMException - when errors occur in parsing.

buildDocument

public static org.jdom.Document buildDocument(java.io.InputStream stream)
                                       throws java.io.IOException,
                                              org.jdom.JDOMException

Creates an instance of the JDOM Document for the specified stream.

Parameters:
stream - the input stream from which the document is to be read
the - document instance
Throws:
java.io.IOException - if the file does not exist.
org.jdom.JDOMException - when errors occur in parsing.

buildDocument

public static org.jdom.Document buildDocument(java.io.InputStream stream,
                                              boolean validateXML)
                                       throws java.io.IOException,
                                              org.jdom.JDOMException

Creates an instance of the JDOM Document for the specified stream.

Parameters:
stream - the input stream from which the document is to be read
validateXML - indicates whether to validate the XML document using the DTD referenced in the XML file.
the - document instance
Throws:
java.io.IOException - if the file does not exist.
org.jdom.JDOMException - when errors occur in parsing.

buildDocument

public static org.jdom.Document buildDocument(java.lang.String saxDriverClass,
                                              java.io.InputStream stream,
                                              boolean validateXML)
                                       throws java.io.IOException,
                                              org.jdom.JDOMException

Creates an instance of the JDOM Document for the specified stream.

Parameters:
saxDriverClass - String name of driver class to use.
stream - the input stream from which the document is to be read
validateXML - indicates whether to validate the XML document using the DTD referenced in the XML file.
the - document instance
Throws:
java.io.IOException - if the file does not exist.
org.jdom.JDOMException - when errors occur in parsing.

buildDocument

public static org.jdom.Document buildDocument(java.io.Reader stream)
                                       throws java.io.IOException,
                                              org.jdom.JDOMException

Creates an instance of the JDOM Document for the specified stream.

Parameters:
stream - the Reader from which the document is to be read
the - document instance
Throws:
java.io.IOException - if the file does not exist.
org.jdom.JDOMException - when errors occur in parsing.

buildDocument

public static org.jdom.Document buildDocument(java.io.Reader stream,
                                              boolean validateXML)
                                       throws java.io.IOException,
                                              org.jdom.JDOMException

Creates an instance of the JDOM Document for the specified stream.

Parameters:
stream - the Reader from which the document is to be read
validateXML - indicates whether to validate the XML document using the DTD referenced in the XML file.
the - document instance
Throws:
java.io.IOException - if the file does not exist.
org.jdom.JDOMException - when errors occur in parsing.

buildDocument

public static org.jdom.Document buildDocument(java.lang.String saxDriverClass,
                                              java.io.Reader stream,
                                              boolean validateXML)
                                       throws java.io.IOException,
                                              org.jdom.JDOMException

Creates an instance of the JDOM Document for the specified stream.

Parameters:
saxDriverClass - String name of driver class to use.
stream - the Reader from which the document is to be read
validateXML - indicates whether to validate the XML document using the DTD referenced in the XML file.
the - document instance
Throws:
java.io.IOException - if the file does not exist.
org.jdom.JDOMException - when errors occur in parsing.

createNewDocument

public static org.jdom.Document createNewDocument(java.lang.String rootTag)

Create a new JDOM Docment with a root Element of the specified name.

Parameters:
rootTag - the name of the root tag for the new document.
the - new document instance


getDescendents

public static java.util.List getDescendents(int traversalMethod,
                                            org.jdom.Element parent,
                                            org.jdom.Namespace ns)

This returns a List of Element objects that are descendents of this element and within the specified Namespace. If this target element has no nested elements within this namespace, an empty List is returned. The returned list is "live" and changes to it affect the element's actual contents.

Parameters:
traversalMethod - the method used to traverse the JDOM tree.
parent - the JDOM Element to get descendents for.
ns - the Namespace to match
Returns:
list of descendent JDOM Elements or an empty list if none exist.

getDescendents

public static java.util.List getDescendents(org.jdom.Element parent)

This returns a List of Element objects that are descendents of this element. If this target element has no nested elements, an empty List is returned. The returned list is "live" and changes to it affect the element's actual contents.

Parameters:
parent - the JDOM Element to get descendents for.
Returns:
list of descendent JDOM Elements or an empty list if none exist.

getDescendents

public static java.util.List getDescendents(org.jdom.Element parent,
                                            java.lang.String name)

This returns a List of all elements that are descendents of this element with the given local name, returned as Element objects. If this target element has no nested elements with the given name, an empty List is returned. The returned list is "live" and changes to it affect the element's actual contents.

Parameters:
parent - the JDOM Element to get descendents for.
name - tag name for the descendents to match
Returns:
list of descendent JDOM Elements or an empty list if none exist.

getDescendents

public static java.util.List getDescendents(org.jdom.Element parent,
                                            org.jdom.Namespace ns)

This returns a List of all elements that are descendents of this element belonging to the specified Namespace, returned as Element objects. If this target element has no nested elements within this Namespace, an empty List is returned. The returned list is "live" and changes to it affect the element's actual contents.

Parameters:
parent - the JDOM Element to get descendents for.
ns - the Namespace to match
Returns:
list of descendent JDOM Elements or an empty list if none exist.

getDescendents

public static java.util.List getDescendents(org.jdom.Element parent,
                                            java.lang.String name,
                                            org.jdom.Namespace ns)

This returns a List of all elements that are descendents of this element with the given local name and belonging to the specified Namespace, returned as Element objects. If this target element has no nested elements with the given name in the specified Namespace, an empty List is returned. The returned list is "live" and changes to it affect the element's actual contents.

Parameters:
parent - the JDOM Element to get descendents for.
name - tag name for the descendents to match
ns - the Namespace to match
Returns:
list of descendent JDOM Elements or an empty list if none exist.

getDescendentCount

public static int getDescendentCount(org.jdom.Element parent)

This returns the number of elements that are descendents of this element. The resulting count excludes the specified parent Element.

Parameters:
parent - the JDOM Element to use as the root for a count.
Returns:
the number of JDOM Elements nested within the parent

getDescendentCount

public static int getDescendentCount(org.jdom.Element parent,
                                     org.jdom.Namespace ns)

This returns the number of elements that are descendents of this element and belonging to the specified Namespace. The resulting count excludes the specified parent Element.

Parameters:
parent - the JDOM Element to use as the root for a count.
ns - the Namespace to match
Returns:
the number of JDOM Elements nested within the parent

getDescendentCount

public static int getDescendentCount(org.jdom.Element parent,
                                     java.lang.String name)

This returns the number of elements that are descendents of this element with the given local name. The resulting count excludes the specified parent Element.

Parameters:
parent - the JDOM Element to use as the root for a count.
name - tag name for the descendents to match
Returns:
the number of JDOM Elements nested within the parent

findElement

public static org.jdom.Element findElement(org.jdom.Element parent,
                                           java.lang.String name)

This returns the first element that is a descendent of this element and matches given local name.

Parameters:
parent - the JDOM Element to check descendents for.
name - tag name for the descendents to match
Returns:
first occurrence of a descendent JDOM Elements that matches the specified name or null if no such element exists.

findElement

public static org.jdom.Element findElement(org.jdom.Element parent,
                                           java.lang.String name,
                                           org.jdom.Namespace ns)

This returns the first element that is a descendent of this element and matches the specified local name and Namespace.

Parameters:
parent - the JDOM Element to check descendents for.
name - tag name for the descendents to match
ns - the Namespace to match
Returns:
first occurrence of a descendent JDOM Elements that matches the specified name or null if no such element exists.

levelOrderTraversal

public static void levelOrderTraversal(org.jdom.Element parent,
                                       org.teiid.internal.core.xml.XMLVisitor v)

Implements a level order traversal of the JDOM tree in which all nodes of the tree are recursively visited by depth: first children of the parent, then grandchildren of the parent (children of children) and so on. The visit method of the specified XMLVisitor is invoked on each node during the traversal. This is equivalent to a breadth first search.

Parameters:
parent - the JDOM Element to use as the root for the traversal.
v - the XMLVisitor to apply at each node as the tree is traversed.

preOrderTraversal

public static void preOrderTraversal(org.jdom.Element parent,
                                     org.teiid.internal.core.xml.XMLVisitor v)

Implements a pre-order traversal of the JDOM tree in which a parent node is processed first then an subtrees. The visit method of the specified XMLVisitor is invoked on each node during the traversal.

Parameters:
parent - the JDOM Element to use as the root for the traversal.
v - the XMLVisitor to apply at each node as the tree is traversed.

postOrderTraversal

public static void postOrderTraversal(org.jdom.Element parent,
                                      org.teiid.internal.core.xml.XMLVisitor v)

Implements a post-order traversal of the JDOM tree in which any subtrees are processed first then parent The visit method of the specified XMLVisitor is invoked on each node during the traversal.

Parameters:
parent - the JDOM Element to use as the root for the traversal.
v - the XMLVisitor to apply at each node as the tree is traversed.

write

public static void write(org.jdom.Document doc,
                         java.lang.String filename)
                  throws java.io.IOException

Ouput this JDOM Document to a file with the specified name.

Parameters:
doc - the document to be output
filename - the fully qualified name of the file to output the XML to.
Throws:
java.io.IOException - if there are problems writing to the file.

write

public static void write(org.jdom.Document doc,
                         java.lang.String filename,
                         java.lang.String indent,
                         boolean newlines)
                  throws java.io.IOException

Ouput the current JDOM Document to a file with the specified name.

Parameters:
doc - the document to be output
filename - the fully qualified name of the file to output the XML to.
indent - the indent String, usually some number of spaces
newlines - true indicates new lines should be printed, else new lines are ignored (compacted).
Throws:
java.io.IOException - if there are problems writing to the file.

write

public static void write(org.jdom.Document doc,
                         java.io.OutputStream stream)
                  throws java.io.IOException

Ouput the current JDOM Document to the output stream.

Parameters:
doc - the document to be output
stream - the output stream
Throws:
java.io.IOException - if there are problems writing to the file.

write

public static void write(org.jdom.Document doc,
                         java.io.OutputStream stream,
                         java.lang.String indent,
                         boolean newlines)
                  throws java.io.IOException

Ouput the current JDOM Document to the output stream.

Parameters:
doc - the document to be output
stream - the output stream
indent - the indent String, usually some number of spaces
newlines - true indicates new lines should be printed, else new lines are ignored (compacted).
Throws:
java.io.IOException - if there are problems writing to the file.

write

public static void write(org.jdom.Document doc,
                         java.io.Writer writer)
                  throws java.io.IOException

Ouput the current JDOM Document to the output stream.

Parameters:
doc - the document to be output
writer - the output writer
Throws:
java.io.IOException - if there are problems writing to the file.

write

public static void write(org.jdom.Document doc,
                         java.io.Writer writer,
                         java.lang.String indent,
                         boolean newlines)
                  throws java.io.IOException

Ouput the current JDOM Document to the writter.

Parameters:
doc - the document to be output
writer - the output writer
indent - the indent String, usually some number of spaces
newlines - true indicates new lines should be printed, else new lines are ignored (compacted).
Throws:
java.io.IOException - if there are problems writing to the file.

write

public static java.lang.String write(org.jdom.Document doc)
                              throws java.io.IOException

Return the current JDOM Document as a String.

Parameters:
doc - the document to be output
Returns:
the document in string form
Throws:
java.io.IOException - if there are problems writing to the file.

write

public static java.lang.String write(org.jdom.Document doc,
                                     java.lang.String indent,
                                     boolean newlines)
                              throws java.io.IOException

Ouput the current JDOM Document as a String.

Parameters:
doc - the document to be output
indent - the indent String, usually some number of spaces
newlines - true indicates new lines should be printed, else new lines are ignored (compacted).
Returns:
the document in string form
Throws:
java.io.IOException - if there are problems writing to the file.

print

public static void print(java.io.PrintStream stream,
                         org.jdom.Document doc)

getContentValue

public static java.lang.String getContentValue(java.lang.Object jdomObject)
Get the best content value for a JDOM object. For elements, the content text is returned. For attributes, the attribute value is returned. For namespaces, the URI is returned. Etc...

Parameters:
jdomObject - JDOM object such as Element, Attribute, Text, Namespace, Comment, ProcessingInstruction, String
Returns:
Content value for the specified JDOM object
Since:
4.2

getFormat

public static org.jdom.output.Format getFormat(java.lang.String indent,
                                               boolean newlines)


Copyright © 2011. All Rights Reserved.