public class JdomHelper extends Object
Modifier and Type | Field and Description |
---|---|
static 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 and Description |
---|
JdomHelper() |
Modifier and Type | Method and Description |
---|---|
static org.jdom.Document |
buildDocument(File file)
Creates an instance of the JDOM Document for the specified file.
|
static org.jdom.Document |
buildDocument(InputStream stream)
Creates an instance of the JDOM Document for the specified stream.
|
static org.jdom.Document |
buildDocument(InputStream stream,
boolean validateXML)
Creates an instance of the JDOM Document for the specified stream.
|
static org.jdom.Document |
buildDocument(Reader stream)
Creates an instance of the JDOM Document for the specified stream.
|
static org.jdom.Document |
buildDocument(Reader stream,
boolean validateXML)
Creates an instance of the JDOM Document for the specified stream.
|
static org.jdom.Document |
buildDocument(String filename)
Creates an instance of the JDOM Document for the specified file.
|
static org.jdom.Document |
buildDocument(String filename,
boolean validateXML)
Creates an instance of the JDOM Document for the specified file.
|
static org.jdom.Document |
buildDocument(String saxDriverClass,
File file,
boolean validateXML)
Creates an instance of the JDOM Document for the specified file.
|
static org.jdom.Document |
buildDocument(String saxDriverClass,
InputStream stream,
boolean validateXML)
Creates an instance of the JDOM Document for the specified stream.
|
static org.jdom.Document |
buildDocument(String saxDriverClass,
Reader stream,
boolean validateXML)
Creates an instance of the JDOM Document for the specified stream.
|
static org.jdom.Document |
buildDocument(String saxDriverClass,
String filename,
boolean validateXML)
Creates an instance of the JDOM Document for the specified file.
|
static org.jdom.Document |
createNewDocument(String rootTag)
Create a new JDOM Docment with a root Element of the specified name.
|
static org.jdom.Element |
findElement(org.jdom.Element parent,
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,
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 String |
getContentValue(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,
String name)
This returns the number of elements that are descendents of this element
with the given local name.
|
static List |
getDescendents(org.jdom.Element parent)
This returns a List of Element objects that are descendents of this element.
|
static 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 List |
getDescendents(org.jdom.Element parent,
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 List |
getDescendents(org.jdom.Element parent,
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 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(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(PrintStream stream,
org.jdom.Document doc) |
static String |
write(org.jdom.Document doc)
Return the current JDOM
Document as a String. |
static void |
write(org.jdom.Document doc,
OutputStream stream)
Ouput the current JDOM
Document to the output stream. |
static void |
write(org.jdom.Document doc,
OutputStream stream,
String indent,
boolean newlines)
Ouput the current JDOM
Document to the output stream. |
static void |
write(org.jdom.Document doc,
String filename)
Ouput this JDOM
Document to a file with the specified name. |
static String |
write(org.jdom.Document doc,
String indent,
boolean newlines)
Ouput the current JDOM
Document as a String. |
static void |
write(org.jdom.Document doc,
String filename,
String indent,
boolean newlines)
Ouput the current JDOM
Document to a file with the specified name. |
static void |
write(org.jdom.Document doc,
Writer writer)
Ouput the current JDOM
Document to the output stream. |
static void |
write(org.jdom.Document doc,
Writer writer,
String indent,
boolean newlines)
Ouput the current JDOM
Document to the writter. |
public static final String DEFAULT_INDENT
public static final boolean DEFAULT_VALIDATION
public static final int PRE_ORDER_TRAVERSAL
public static final int POST_ORDER_TRAVERSAL
public static final int LEVEL_ORDER_TRAVERSAL
public static org.jdom.Document buildDocument(String filename) throws IOException, org.jdom.JDOMException
Creates an instance of the JDOM Document for the specified file.
filename
- String
name of file.the
- document instanceIOException
- if the file does not exist.org.jdom.JDOMException
- when errors occur in parsing.public static org.jdom.Document buildDocument(File file) throws IOException, org.jdom.JDOMException
Creates an instance of the JDOM Document for the specified file.
file
- File
.the
- document instanceIOException
- if the file does not exist.org.jdom.JDOMException
- when errors occur in parsing.public static org.jdom.Document buildDocument(String filename, boolean validateXML) throws IOException, org.jdom.JDOMException
Creates an instance of the JDOM Document for the specified file.
filename
- String
name of file.validateXML
- indicates whether to validate the XML document
using the DTD referenced in the XML file.the
- document instanceIOException
- if the file does not exist.org.jdom.JDOMException
- when errors occur in parsing.public static org.jdom.Document buildDocument(String saxDriverClass, String filename, boolean validateXML) throws IOException, org.jdom.JDOMException
Creates an instance of the JDOM Document for the specified file.
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 instanceIOException
- if the file does not exist.org.jdom.JDOMException
- when errors occur in parsing.public static org.jdom.Document buildDocument(String saxDriverClass, File file, boolean validateXML) throws IOException, org.jdom.JDOMException
Creates an instance of the JDOM Document for the specified file.
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 instanceIOException
- if the file does not exist.org.jdom.JDOMException
- when errors occur in parsing.public static org.jdom.Document buildDocument(InputStream stream) throws IOException, org.jdom.JDOMException
Creates an instance of the JDOM Document for the specified stream.
stream
- the input stream from which the document is to be readthe
- document instanceIOException
- if the file does not exist.org.jdom.JDOMException
- when errors occur in parsing.public static org.jdom.Document buildDocument(InputStream stream, boolean validateXML) throws IOException, org.jdom.JDOMException
Creates an instance of the JDOM Document for the specified stream.
stream
- the input stream from which the document is to be readvalidateXML
- indicates whether to validate the XML document
using the DTD referenced in the XML file.the
- document instanceIOException
- if the file does not exist.org.jdom.JDOMException
- when errors occur in parsing.public static org.jdom.Document buildDocument(String saxDriverClass, InputStream stream, boolean validateXML) throws IOException, org.jdom.JDOMException
Creates an instance of the JDOM Document for the specified stream.
saxDriverClass
- String
name of driver class to use.stream
- the input stream from which the document is to be readvalidateXML
- indicates whether to validate the XML document
using the DTD referenced in the XML file.the
- document instanceIOException
- if the file does not exist.org.jdom.JDOMException
- when errors occur in parsing.public static org.jdom.Document buildDocument(Reader stream) throws IOException, org.jdom.JDOMException
Creates an instance of the JDOM Document for the specified stream.
stream
- the Reader from which the document is to be readthe
- document instanceIOException
- if the file does not exist.org.jdom.JDOMException
- when errors occur in parsing.public static org.jdom.Document buildDocument(Reader stream, boolean validateXML) throws IOException, org.jdom.JDOMException
Creates an instance of the JDOM Document for the specified stream.
stream
- the Reader from which the document is to be readvalidateXML
- indicates whether to validate the XML document
using the DTD referenced in the XML file.the
- document instanceIOException
- if the file does not exist.org.jdom.JDOMException
- when errors occur in parsing.public static org.jdom.Document buildDocument(String saxDriverClass, Reader stream, boolean validateXML) throws IOException, org.jdom.JDOMException
Creates an instance of the JDOM Document for the specified stream.
saxDriverClass
- String
name of driver class to use.stream
- the Reader from which the document is to be readvalidateXML
- indicates whether to validate the XML document
using the DTD referenced in the XML file.the
- document instanceIOException
- if the file does not exist.org.jdom.JDOMException
- when errors occur in parsing.public static org.jdom.Document createNewDocument(String rootTag)
Create a new JDOM Docment with a root Element of the specified name.
rootTag
- the name of the root tag for the new document.the
- new document instance
public static 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.
traversalMethod
- the method used to traverse the JDOM tree.parent
- the JDOM Element
to get descendents for.ns
- the Namespace to matchElement
s or an empty list
if none exist.public static 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.
parent
- the JDOM Element
to get descendents for.Element
s or an empty list
if none exist.public static List getDescendents(org.jdom.Element parent, 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.
parent
- the JDOM Element
to get descendents for.name
- tag name for the descendents to matchElement
s or an empty list
if none exist.public static 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.
parent
- the JDOM Element
to get descendents for.ns
- the Namespace to matchElement
s or an empty list
if none exist.public static List getDescendents(org.jdom.Element parent, 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.
parent
- the JDOM Element
to get descendents for.name
- tag name for the descendents to matchns
- the Namespace to matchElement
s or an empty list
if none exist.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.
parent
- the JDOM Element
to use as the root for a count.Element
s nested within the parentpublic 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.
parent
- the JDOM Element
to use as the root for a count.ns
- the Namespace to matchElement
s nested within the parentpublic static int getDescendentCount(org.jdom.Element parent, 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.
parent
- the JDOM Element
to use as the root for a count.name
- tag name for the descendents to matchElement
s nested within the parentpublic static org.jdom.Element findElement(org.jdom.Element parent, String name)
This returns the first element that is a descendent of this element and matches given local name.
parent
- the JDOM Element
to check descendents for.name
- tag name for the descendents to matchElement
s that
matches the specified name or null if no such element exists.public static org.jdom.Element findElement(org.jdom.Element parent, 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.
parent
- the JDOM Element
to check descendents for.name
- tag name for the descendents to matchns
- the Namespace to matchElement
s that
matches the specified name or null if no such element exists.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.
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.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.
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.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.
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.public static void write(org.jdom.Document doc, String filename) throws IOException
Ouput this JDOM Document
to a file with the specified name.
doc
- the document to be outputfilename
- the fully qualified name of the file to output the XML to.IOException
- if there are problems writing to the file.public static void write(org.jdom.Document doc, String filename, String indent, boolean newlines) throws IOException
Ouput the current JDOM Document
to a file with the specified name.
doc
- the document to be outputfilename
- the fully qualified name of the file to output the XML to.indent
- the indent String, usually some number of spacesnewlines
- true indicates new lines should be printed, else new
lines are ignored (compacted).IOException
- if there are problems writing to the file.public static void write(org.jdom.Document doc, OutputStream stream) throws IOException
Ouput the current JDOM Document
to the output stream.
doc
- the document to be outputstream
- the output streamIOException
- if there are problems writing to the file.public static void write(org.jdom.Document doc, OutputStream stream, String indent, boolean newlines) throws IOException
Ouput the current JDOM Document
to the output stream.
doc
- the document to be outputstream
- the output streamindent
- the indent String, usually some number of spacesnewlines
- true indicates new lines should be printed, else new
lines are ignored (compacted).IOException
- if there are problems writing to the file.public static void write(org.jdom.Document doc, Writer writer) throws IOException
Ouput the current JDOM Document
to the output stream.
doc
- the document to be outputwriter
- the output writerIOException
- if there are problems writing to the file.public static void write(org.jdom.Document doc, Writer writer, String indent, boolean newlines) throws IOException
Ouput the current JDOM Document
to the writter.
doc
- the document to be outputwriter
- the output writerindent
- the indent String, usually some number of spacesnewlines
- true indicates new lines should be printed, else new
lines are ignored (compacted).IOException
- if there are problems writing to the file.public static String write(org.jdom.Document doc) throws IOException
Return the current JDOM Document
as a String.
doc
- the document to be outputIOException
- if there are problems writing to the file.public static String write(org.jdom.Document doc, String indent, boolean newlines) throws IOException
Ouput the current JDOM Document
as a String.
doc
- the document to be outputindent
- the indent String, usually some number of spacesnewlines
- true indicates new lines should be printed, else new
lines are ignored (compacted).IOException
- if there are problems writing to the file.public static void print(PrintStream stream, org.jdom.Document doc)
public static String getContentValue(Object jdomObject)
jdomObject
- JDOM object such as Element, Attribute, Text, Namespace, Comment, ProcessingInstruction, Stringpublic static org.jdom.output.Format getFormat(String indent, boolean newlines)
Copyright © 2019. All rights reserved.