org.aeonscope.xml
Class JDOMKit

java.lang.Object
  extended by org.aeonscope.xml.JDOMKit

public class JDOMKit
extends Object

General JDOM utilities for XML manipulation.

Author:
Brooke Kuhlmann

Constructor Summary
JDOMKit()
           
 
Method Summary
static String getAttributeValue(String name, org.jdom.Element element)
          Answers the attribute value for an element and attribute name.
static org.jdom.Document getDocument(String path)
          Answers a document for the given file path with no XML to DTD validation.
static org.jdom.Document getDocument(String path, boolean validate)
          Answers a document for the given file path with the option to validate the XML against the DTD.
static org.jdom.Element getRootElement(String path)
          Answers the root element of a given XML file with no XML to DTD validation.
static org.jdom.Element getRootElement(String path, boolean validate)
          Answers the root element of a given XML file with the option to validate the XML against the DTD.
static void print(org.jdom.Document doc)
          Prints the document to the system console.
static void print(org.jdom.Element element)
          Prints an element to the system console.
static void print(List<org.jdom.Element> elements)
          Prints an element list to the system console.
static void transform(String xmlPath, String outputPath)
          Transforms an XML file into a new file (assumes the XSLT file is referenced in the XML).
static void transform(String xmlPath, String xsltPath, String resultPath)
          Transforms the given XML file using the given XSLT file into a new file (based on the given file path).
static void write(org.jdom.Document doc, File file)
          Writes a document to a file.
static void write(org.jdom.Document doc, OutputStream stream)
          Writes a document to an output steam.
static void write(org.jdom.Document doc, String path)
          Writes a document to a file path.
static void write(org.jdom.Element root, Collection producers, String path)
          Writes a given root element by adding the collection of element producers to a given file path.
static void write(org.jdom.Element element, File file)
          Writes an element to a file.
static void write(org.jdom.Element element, OutputStream stream)
          Writes an element to an output steam.
static void write(org.jdom.Element element, String path)
          Writes an element to a file path.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDOMKit

public JDOMKit()
Method Detail

getDocument

public static org.jdom.Document getDocument(String path,
                                            boolean validate)
Answers a document for the given file path with the option to validate the XML against the DTD.

Parameters:
path - The file path of the XML file.
validate - true = perform validation, false = do not validate.
Returns:
The XML document, otherwise null.

getDocument

public static org.jdom.Document getDocument(String path)
Answers a document for the given file path with no XML to DTD validation.

Parameters:
path - The file path to the XML file.
Returns:
The XML document, otherwise null.

getRootElement

public static org.jdom.Element getRootElement(String path)
Answers the root element of a given XML file with no XML to DTD validation.

Parameters:
path - The path to the XML file.
Returns:
The root XML element, otherwise null.

getRootElement

public static org.jdom.Element getRootElement(String path,
                                              boolean validate)
Answers the root element of a given XML file with the option to validate the XML against the DTD.

Parameters:
path - The path to the XML file.
validate - true = perform validation, false = do not validate.
Returns:
The root XML element, otherwise null.

getAttributeValue

public static String getAttributeValue(String name,
                                       org.jdom.Element element)
Answers the attribute value for an element and attribute name. Safely checks that the element is not null before attempting to acquire the attribute value.

Parameters:
name - The name of the attribute to search for.
element - The element to acquire the attribute value from.
Returns:
The attribute value if it exists, otherwise null.

transform

public static void transform(String xmlPath,
                             String xsltPath,
                             String resultPath)
Transforms the given XML file using the given XSLT file into a new file (based on the given file path).

Visit Xalan-Java for more information.

Parameters:
xmlPath - The file path of the XML file to transform.
xsltPath - The file path of the XSLT file to do the transforming.
resultPath - The file path of the result file created from the transform.

transform

public static void transform(String xmlPath,
                             String outputPath)
Transforms an XML file into a new file (assumes the XSLT file is referenced in the XML).

Visit Xalan-Java for more information.

Parameters:
xmlPath - The XML file path.
outputPath - The output file path.

print

public static void print(org.jdom.Element element)
Prints an element to the system console.

Parameters:
element - The element to print.

print

public static void print(List<org.jdom.Element> elements)
Prints an element list to the system console.

Parameters:
elements - The list of elements to print.

print

public static void print(org.jdom.Document doc)
Prints the document to the system console.

Parameters:
doc - The document to print.

write

public static void write(org.jdom.Element element,
                         String path)
Writes an element to a file path.

Parameters:
element - The element to write.
path - The file path to write to.

write

public static void write(org.jdom.Element element,
                         File file)
Writes an element to a file.

Parameters:
element - The element to write.
file - The file to write to.

write

public static void write(org.jdom.Element root,
                         Collection producers,
                         String path)
Writes a given root element by adding the collection of element producers to a given file path.

Parameters:
root - The root element.
producers - The collection of element producers to add to the root element.
path - The path to create the XML file at.

write

public static void write(org.jdom.Element element,
                         OutputStream stream)
Writes an element to an output steam.

Parameters:
element - The element to write.
stream - The output stream to write to.

write

public static void write(org.jdom.Document doc,
                         String path)
Writes a document to a file path.

Parameters:
doc - The document to write.
path - The file path to write to.

write

public static void write(org.jdom.Document doc,
                         File file)
Writes a document to a file.

Parameters:
doc - The document to write.
file - The file to write to.

write

public static void write(org.jdom.Document doc,
                         OutputStream stream)
Writes a document to an output steam.

Parameters:
doc - The document to write.
stream - The output stream to write to.