org.jdesktop.dom
Class SimpleDocumentBuilder

java.lang.Object
  extended by javax.xml.parsers.DocumentBuilder
      extended by org.jdesktop.dom.SimpleDocumentBuilder

public class SimpleDocumentBuilder
extends DocumentBuilder

A DOM DocumentBuilder implementation that does not require the factory pattern for creation. Most of the time calling one of the static simpleParse methods is all that is required. Occasionally you may need to create an instance of SimpleDocumentBuilder to tweak some of the builder settings (such as setting an ErrorHandler or EntityResolver).


Constructor Summary
SimpleDocumentBuilder()
          Create a new SimpleDocumentBuilder.
SimpleDocumentBuilder(boolean namespaceAware)
           
SimpleDocumentBuilder(DocumentBuilderFactory factory)
          Create a SimpleDocumentBuilder that will wrap builders created from the given factory.
 
Method Summary
 DOMImplementation getDOMImplementation()
          Obtain an instance of a DOMImplementation object.
 Schema getSchema()
          Get a reference to the the Schema being used by the XML processor.
 boolean isNamespaceAware()
          Indicates whether or not this parser is configured to understand namespaces.
 boolean isValidating()
          Indicates whether or not this parser is configured to validate XML documents.
 boolean isXIncludeAware()
          Get the XInclude processing mode for this parser.
 SimpleDocument newDocument()
          Obtain a new instance of a DOM Document object to build a DOM tree with.
 SimpleDocument parse(File f)
          Parse the content of the given file as an XML document and return a new DOM Document object.
 SimpleDocument parse(InputSource is)
          Parse the content of the given input source as an XML document and return a new DOM Document object.
 SimpleDocument parse(InputStream is)
          Parse the content of the given InputStream as an XML document and return a new DOM Document object.
 SimpleDocument parse(InputStream is, String systemId)
          Parse the content of the given InputStream as an XML document and return a new DOM Document object.
 SimpleDocument parse(String uri)
          Parse the content of the given URI as an XML document and return a new DOM Document object.
 SimpleDocument parseString(String xml)
          Parse the content of the given String as an XML document and return a new DOM SimpleDocument object.
 void reset()
          Reset this DocumentBuilder to its original configuration.
 void setEntityResolver(EntityResolver er)
          Specify the EntityResolver to be used to resolve entities present in the XML document to be parsed.
 void setErrorHandler(ErrorHandler eh)
          Specify the ErrorHandler to be used by the parser.
static SimpleDocument simpleParse(InputSource is)
          Parse the content of the given input source as an XML document and return a new DOM SimpleDocument object.
static SimpleDocument simpleParse(InputSource is, boolean namespaceAware)
          Parse the content of the given input source as an XML document and return a new DOM SimpleDocument object.
static SimpleDocument simpleParse(InputStream in)
          Parse the content of the given InputStream as an XML document and return a new DOM SimpleDocument object.
static SimpleDocument simpleParse(InputStream in, boolean namespaceAware)
          Parse the content of the given InputStream as an XML document and return a new DOM SimpleDocument object.
static SimpleDocument simpleParse(String xml)
          Parse the content of the given String as an XML document and return a new DOM SimpleDocument object.
static SimpleDocument simpleParse(String xml, boolean namespaceAware)
          Parse the content of the given String as an XML document and return a new DOM SimpleDocument object.
static SimpleDocument simpleParse(URL url)
          Parse the content of the given URL as an XML document and return a new DOM SimpleDocument object.
static SimpleDocument simpleParse(URL url, boolean namespaceAware)
          Parse the content of the given URL as an XML document and return a new DOM SimpleDocument object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleDocumentBuilder

public SimpleDocumentBuilder()
Create a new SimpleDocumentBuilder. SimpleDocumentBuilder will delegate parsing to the default DocumentBuilder constructed via the default DocumentBuilderFactory. This builder factory will be constructed to be namespace aware by default, unlike the traditional Document builders.


SimpleDocumentBuilder

public SimpleDocumentBuilder(boolean namespaceAware)

SimpleDocumentBuilder

public SimpleDocumentBuilder(DocumentBuilderFactory factory)
Create a SimpleDocumentBuilder that will wrap builders created from the given factory. This can be used to construct non-namespace aware documents, for example.

Method Detail

parseString

public SimpleDocument parseString(String xml)
                           throws SAXException,
                                  IOException
Parse the content of the given String as an XML document and return a new DOM SimpleDocument object. An IllegalArgumentException is thrown if the String is null.

Parameters:
xml - String containing the content to be parsed.
Returns:
SimpleDocument result of parsing the String
Throws:
IOException - If any IO errors occur.
SAXException - If any parse errors occur.
IllegalArgumentException - When xml is null
See Also:
DocumentHandler

parse

public SimpleDocument parse(InputSource is)
                     throws SAXException,
                            IOException
Description copied from class: javax.xml.parsers.DocumentBuilder
Parse the content of the given input source as an XML document and return a new DOM Document object. An IllegalArgumentException is thrown if the InputSource is null null.

Specified by:
parse in class DocumentBuilder
Parameters:
is - InputSource containing the content to be parsed.
Returns:
A new DOM Document object.
Throws:
SAXException - If any parse errors occur.
IOException - If any IO errors occur.
See Also:
DocumentHandler

parse

public SimpleDocument parse(InputStream is)
                     throws SAXException,
                            IOException
Description copied from class: javax.xml.parsers.DocumentBuilder
Parse the content of the given InputStream as an XML document and return a new DOM Document object. An IllegalArgumentException is thrown if the InputStream is null.

Overrides:
parse in class DocumentBuilder
Parameters:
is - InputStream containing the content to be parsed.
Returns:
Document result of parsing the InputStream
Throws:
SAXException - If any parse errors occur.
IOException - If any IO errors occur.
See Also:
DocumentHandler

parse

public SimpleDocument parse(InputStream is,
                            String systemId)
                     throws SAXException,
                            IOException
Description copied from class: javax.xml.parsers.DocumentBuilder
Parse the content of the given InputStream as an XML document and return a new DOM Document object. An IllegalArgumentException is thrown if the InputStream is null.

Overrides:
parse in class DocumentBuilder
Parameters:
is - InputStream containing the content to be parsed.
systemId - Provide a base for resolving relative URIs.
Returns:
A new DOM Document object.
Throws:
SAXException - If any parse errors occur.
IOException - If any IO errors occur.
See Also:
DocumentHandler

parse

public SimpleDocument parse(String uri)
                     throws SAXException,
                            IOException
Description copied from class: javax.xml.parsers.DocumentBuilder
Parse the content of the given URI as an XML document and return a new DOM Document object. An IllegalArgumentException is thrown if the URI is null null.

Overrides:
parse in class DocumentBuilder
Parameters:
uri - The location of the content to be parsed.
Returns:
A new DOM Document object.
Throws:
SAXException - If any parse errors occur.
IOException - If any IO errors occur.
See Also:
DocumentHandler

parse

public SimpleDocument parse(File f)
                     throws SAXException,
                            IOException
Description copied from class: javax.xml.parsers.DocumentBuilder
Parse the content of the given file as an XML document and return a new DOM Document object. An IllegalArgumentException is thrown if the File is null null.

Overrides:
parse in class DocumentBuilder
Parameters:
f - The file containing the XML to parse.
Returns:
A new DOM Document object.
Throws:
SAXException - If any parse errors occur.
IOException - If any IO errors occur.
See Also:
DocumentHandler

isNamespaceAware

public boolean isNamespaceAware()
Description copied from class: javax.xml.parsers.DocumentBuilder
Indicates whether or not this parser is configured to understand namespaces.

Specified by:
isNamespaceAware in class DocumentBuilder
Returns:
true if this parser is configured to understand namespaces; false otherwise.

isValidating

public boolean isValidating()
Description copied from class: javax.xml.parsers.DocumentBuilder
Indicates whether or not this parser is configured to validate XML documents.

Specified by:
isValidating in class DocumentBuilder
Returns:
true if this parser is configured to validate XML documents; false otherwise.

setEntityResolver

public void setEntityResolver(EntityResolver er)
Description copied from class: javax.xml.parsers.DocumentBuilder
Specify the EntityResolver to be used to resolve entities present in the XML document to be parsed. Setting this to null will result in the underlying implementation using it's own default implementation and behavior.

Specified by:
setEntityResolver in class DocumentBuilder
Parameters:
er - The EntityResolver to be used to resolve entities present in the XML document to be parsed.

setErrorHandler

public void setErrorHandler(ErrorHandler eh)
Description copied from class: javax.xml.parsers.DocumentBuilder
Specify the ErrorHandler to be used by the parser. Setting this to null will result in the underlying implementation using it's own default implementation and behavior.

Specified by:
setErrorHandler in class DocumentBuilder
Parameters:
eh - The ErrorHandler to be used by the parser.

newDocument

public SimpleDocument newDocument()
Description copied from class: javax.xml.parsers.DocumentBuilder
Obtain a new instance of a DOM Document object to build a DOM tree with.

Specified by:
newDocument in class DocumentBuilder
Returns:
A new instance of a DOM Document object.

getDOMImplementation

public DOMImplementation getDOMImplementation()
Description copied from class: javax.xml.parsers.DocumentBuilder
Obtain an instance of a DOMImplementation object.

Specified by:
getDOMImplementation in class DocumentBuilder
Returns:
A new instance of a DOMImplementation.

reset

public void reset()
Description copied from class: javax.xml.parsers.DocumentBuilder

Reset this DocumentBuilder to its original configuration.

DocumentBuilder is reset to the same state as when it was created with DocumentBuilderFactory.newDocumentBuilder(). reset() is designed to allow the reuse of existing DocumentBuilders thus saving resources associated with the creation of new DocumentBuilders.

The reset DocumentBuilder is not guaranteed to have the same EntityResolver or ErrorHandler Objects, e.g. Object.equals(Object obj). It is guaranteed to have a functionally equal EntityResolver and ErrorHandler.

Overrides:
reset in class DocumentBuilder

getSchema

public Schema getSchema()
Description copied from class: javax.xml.parsers.DocumentBuilder

Get a reference to the the Schema being used by the XML processor.

If no schema is being used, null is returned.

Overrides:
getSchema in class DocumentBuilder
Returns:
Schema being used or null if none in use

isXIncludeAware

public boolean isXIncludeAware()
Description copied from class: javax.xml.parsers.DocumentBuilder

Get the XInclude processing mode for this parser.

Overrides:
isXIncludeAware in class DocumentBuilder
Returns:
the return value of the DocumentBuilderFactory.isXIncludeAware() when this parser was created from factory.
See Also:
DocumentBuilderFactory.setXIncludeAware(boolean)

simpleParse

public static SimpleDocument simpleParse(InputSource is)
                                  throws SAXException,
                                         IOException
Parse the content of the given input source as an XML document and return a new DOM SimpleDocument object. An IllegalArgumentException is thrown if the InputSource is null null.

Parameters:
is - InputSource containing the content to be parsed.
Returns:
A new DOM SimpleDocument object.
Throws:
IOException - If any IO errors occur.
SAXException - If any parse errors occur.
IllegalArgumentException - When is is null
See Also:
DocumentHandler

simpleParse

public static SimpleDocument simpleParse(InputStream in)
                                  throws SAXException,
                                         IOException
Parse the content of the given InputStream as an XML document and return a new DOM SimpleDocument object. An IllegalArgumentException is thrown if the InputStream is null.

Parameters:
is - InputStream containing the content to be parsed.
Returns:
SimpleDocument result of parsing the InputStream
Throws:
IOException - If any IO errors occur.
SAXException - If any parse errors occur.
IllegalArgumentException - When is is null
See Also:
DocumentHandler

simpleParse

public static SimpleDocument simpleParse(URL url)
                                  throws SAXException,
                                         IOException
Parse the content of the given URL as an XML document and return a new DOM SimpleDocument object. An IllegalArgumentException is thrown if the URI is null null.

Parameters:
uri - The location of the content to be parsed.
Returns:
A new DOM SimpleDocument object.
Throws:
IOException - If any IO errors occur.
SAXException - If any parse errors occur.
IllegalArgumentException - When url is null
See Also:
DocumentHandler

simpleParse

public static SimpleDocument simpleParse(String xml)
                                  throws SAXException,
                                         IOException
Parse the content of the given String as an XML document and return a new DOM SimpleDocument object. An IllegalArgumentException is thrown if the String is null.

Parameters:
xml - String containing the content to be parsed.
Returns:
SimpleDocument result of parsing the String
Throws:
IOException - If any IO errors occur.
SAXException - If any parse errors occur.
IllegalArgumentException - When xml is null
See Also:
DocumentHandler

simpleParse

public static SimpleDocument simpleParse(InputSource is,
                                         boolean namespaceAware)
                                  throws SAXException,
                                         IOException
Parse the content of the given input source as an XML document and return a new DOM SimpleDocument object. An IllegalArgumentException is thrown if the InputSource is null null.

Parameters:
is - InputSource containing the content to be parsed.
namespaceAware - whether the parser should be namespace aware
Returns:
A new DOM SimpleDocument object.
Throws:
IOException - If any IO errors occur.
SAXException - If any parse errors occur.
IllegalArgumentException - When is is null
See Also:
DocumentHandler

simpleParse

public static SimpleDocument simpleParse(InputStream in,
                                         boolean namespaceAware)
                                  throws SAXException,
                                         IOException
Parse the content of the given InputStream as an XML document and return a new DOM SimpleDocument object. An IllegalArgumentException is thrown if the InputStream is null.

Parameters:
in - InputStream containing the content to be parsed.
namespaceAware - whether the parser should be namespace aware
Returns:
SimpleDocument result of parsing the InputStream
Throws:
IOException - If any IO errors occur.
SAXException - If any parse errors occur.
IllegalArgumentException - When is is null
See Also:
DocumentHandler

simpleParse

public static SimpleDocument simpleParse(URL url,
                                         boolean namespaceAware)
                                  throws SAXException,
                                         IOException
Parse the content of the given URL as an XML document and return a new DOM SimpleDocument object. An IllegalArgumentException is thrown if the URI is null null.

Parameters:
url - The location of the content to be parsed.
namespaceAware - whether the parser should be namespace aware
Returns:
A new DOM SimpleDocument object.
Throws:
IOException - If any IO errors occur.
SAXException - If any parse errors occur.
IllegalArgumentException - When url is null
See Also:
DocumentHandler

simpleParse

public static SimpleDocument simpleParse(String xml,
                                         boolean namespaceAware)
                                  throws SAXException,
                                         IOException
Parse the content of the given String as an XML document and return a new DOM SimpleDocument object. An IllegalArgumentException is thrown if the String is null.

Parameters:
xml - String containing the content to be parsed.
namespaceAware - whether the parser should be namespace aware
Returns:
SimpleDocument result of parsing the String
Throws:
IOException - If any IO errors occur.
SAXException - If any parse errors occur.
IllegalArgumentException - When xml is null
See Also:
DocumentHandler