org.jdom.input
public class SAXBuilder extends Object
Known issues: Relative paths for a {@link DocType} or {@link EntityRef} may be converted by the SAX parser into absolute paths.
Version: $Revision: 1.89 $, $Date: 2004/09/03 18:24:28 $
Constructor Summary | |
---|---|
SAXBuilder()
Creates a new SAXBuilder which will attempt to first locate
a parser via JAXP, then will try to use a set of default
SAX Drivers. | |
SAXBuilder(boolean validate)
Creates a new SAXBuilder which will attempt to first locate
a parser via JAXP, then will try to use a set of default
SAX Drivers. | |
SAXBuilder(String saxDriverClass)
Creates a new SAXBuilder using the specified SAX parser.
| |
SAXBuilder(String saxDriverClass, boolean validate)
Creates a new SAXBuilder using the specified SAX parser.
|
Method Summary | |
---|---|
Document | build(InputSource in)
This builds a document from the supplied
input source.
|
Document | build(InputStream in) This builds a document from the supplied input stream. |
Document | build(File file) This builds a document from the supplied filename. |
Document | build(URL url) This builds a document from the supplied URL. |
Document | build(InputStream in, String systemId) This builds a document from the supplied input stream. |
Document | build(Reader characterStream) This builds a document from the supplied Reader. |
Document | build(Reader characterStream, String systemId) This builds a document from the supplied Reader. |
Document | build(String systemId) This builds a document from the supplied URI. |
protected void | configureContentHandler(SAXHandler contentHandler)
This configures the SAXHandler that will be used to build the Document.
|
protected void | configureParser(XMLReader parser, SAXHandler contentHandler)
This configures the XMLReader to be used for reading the XML document.
|
protected SAXHandler | createContentHandler()
This creates the SAXHandler that will be used to build the Document.
|
protected XMLReader | createParser()
This creates the XMLReader to be used for reading the XML document.
|
String | getDriverClass()
Returns the driver class assigned in the constructor, or null if none.
|
DTDHandler | getDTDHandler()
Returns the {@link DTDHandler} assigned, or null if none.
|
EntityResolver | getEntityResolver()
Returns the {@link EntityResolver} assigned, or null if none.
|
ErrorHandler | getErrorHandler()
Returns the {@link ErrorHandler} assigned, or null if none. |
boolean | getExpandEntities()
Returns whether or not entities are being expanded into normal text
content.
|
JDOMFactory | getFactory()
Returns the current {@link org.jdom.JDOMFactory} in use. |
boolean | getIgnoringElementContentWhitespace()
Returns whether element content whitespace is to be ignored during the
build.
|
boolean | getReuseParser()
Returns whether the contained SAX parser instance is reused across
multiple parses. |
boolean | getValidation()
Returns whether validation is to be performed during the build.
|
XMLFilter | getXMLFilter()
Returns the {@link XMLFilter} used during parsing, or null if none.
|
void | setDTDHandler(DTDHandler dtdHandler)
This sets custom DTDHandler for the Builder .
|
void | setEntityResolver(EntityResolver entityResolver)
This sets custom EntityResolver for the Builder .
|
void | setErrorHandler(ErrorHandler errorHandler)
This sets custom ErrorHandler for the Builder .
|
void | setExpandEntities(boolean expand) This sets whether or not to expand entities for the builder. |
void | setFactory(JDOMFactory factory)
This sets a custom JDOMFactory for the builder. |
void | setFeature(String name, boolean value)
This sets a feature on the SAX parser. |
void | setIgnoringElementContentWhitespace(boolean ignoringWhite)
Specifies whether or not the parser should elminate whitespace in
element content (sometimes known as "ignorable whitespace") when
building the document. |
void | setProperty(String name, Object value)
This sets a property on the SAX parser. |
void | setReuseParser(boolean reuseParser)
Specifies whether this builder shall reuse the same SAX parser
when performing subsequent parses or allocate a new parser for
each parse. |
void | setValidation(boolean validate)
This sets validation for the builder.
|
void | setXMLFilter(XMLFilter xmlFilter)
This sets a custom {@link org.xml.sax.XMLFilter} for the builder.
|
Parameters: validate boolean
indicating if
validation should occur.
Parameters: saxDriverClass String
name of SAX Driver
to use for parsing.
Parameters: saxDriverClass String
name of SAX Driver
to use for parsing. validate boolean
indicating if
validation should occur.
Parameters: in InputSource
to read from
Returns: Document
resultant Document object
Throws: JDOMException when errors occur in parsing IOException when an I/O error prevents a document from being fully parsed
This builds a document from the supplied input stream.
Parameters: in InputStream
to read from
Returns: Document
resultant Document object
Throws: JDOMException when errors occur in parsing IOException when an I/O error prevents a document from being fully parsed.
This builds a document from the supplied filename.
Parameters: file File
to read from
Returns: Document
resultant Document object
Throws: JDOMException when errors occur in parsing IOException when an I/O error prevents a document from being fully parsed
This builds a document from the supplied URL.
Parameters: url URL
to read from.
Returns: Document
- resultant Document object.
Throws: JDOMException when errors occur in parsing IOException when an I/O error prevents a document from being fully parsed.
This builds a document from the supplied input stream.
Parameters: in InputStream
to read from. systemId base for resolving relative URIs
Returns: Document
resultant Document object
Throws: JDOMException when errors occur in parsing IOException when an I/O error prevents a document from being fully parsed
This builds a document from the supplied Reader. It's the programmer's responsibility to make sure the reader matches the encoding of the file. It's often easier and safer to use an InputStream rather than a Reader, and to let the parser auto-detect the encoding from the XML declaration.
Parameters: characterStream Reader
to read from
Returns: Document
resultant Document object
Throws: JDOMException when errors occur in parsing IOException when an I/O error prevents a document from being fully parsed
This builds a document from the supplied Reader. It's the programmer's responsibility to make sure the reader matches the encoding of the file. It's often easier and safer to use an InputStream rather than a Reader, and to let the parser auto-detect the encoding from the XML declaration.
Parameters: characterStream Reader
to read from. systemId base for resolving relative URIs
Returns: Document
resultant Document object
Throws: JDOMException when errors occur in parsing IOException when an I/O error prevents a document from being fully parsed
This builds a document from the supplied URI.
Parameters: systemId URI for the input
Returns: Document
resultant Document object
Throws: JDOMException when errors occur in parsing IOException when an I/O error prevents a document from being fully parsed
The default implementation simply passes through some configuration settings that were set on the SAXBuilder: setExpandEntities() and setIgnoringElementContentWhitespace().
The default implementation sets various options on the given XMLReader,
such as validation, DTD resolution, entity handlers, etc., according
to the options that were set (e.g. via setEntityResolver
)
and set various SAX properties and features that are required for JDOM
internals. These features may change in future releases, so change this
behavior at your own risk.
Returns: SAXHandler
- resultant SAXHandler object.
The default behavior is to (1) use the saxDriverClass, if it has been set, (2) try to obtain a parser from JAXP, if it is available, and (3) if all else fails, use a hard-coded default parser (currently the Xerces parser). Subclasses may override this method to determine the parser to use in a different way.
Returns: XMLReader
- resultant XMLReader object.
Returns: the driver class assigned in the constructor
Returns: the DTDHandler assigned
Returns: the EntityResolver assigned
Returns: the ErrorHandler assigned, or null if none
Returns: whether entities are being expanded
Returns: the factory in use
Returns: whether element content whitespace is to be ignored during the build
Returns: whether the contained SAX parser instance is reused across multiple parses
Returns: whether validation is to be performed during the build
Returns: the XMLFilter used during parsing
Builder
.
Parameters: dtdHandler DTDHandler
Builder
.
Parameters: entityResolver EntityResolver
Builder
.
Parameters: errorHandler ErrorHandler
This sets whether or not to expand entities for the builder.
A true means to expand entities as normal content. A false means to
leave entities unexpanded as EntityRef
objects. The
default is true.
When this setting is false, the internal DTD subset is retained; when this setting is true, the internal DTD subset is not retained.
Note that Xerces (at least up to 1.4.4) has a bug where entities in attribute values will be misreported if this flag is turned off, resulting in entities to appear within element content. When turning entity expansion off either avoid entities in attribute values, or use another parser like Crimson. http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6111
Parameters: expand boolean
indicating whether entity expansion
should occur.
Parameters: factory JDOMFactory
to use
NOTE: SAXBuilder requires that some particular features of the SAX parser be set up in certain ways for it to work properly. The list of such features may change in the future. Therefore, the use of this method may cause parsing to break, and even if it doesn't break anything today it might break parsing in a future JDOM version, because what JDOM parsers require may change over time. Use with caution.
Parameters: name The feature name, which is a fully-qualified URI. value The requested state of the feature (true or false).
false
.
Parameters: ignoringWhite Whether to ignore ignorable whitespace
NOTE: SAXBuilder requires that some particular properties of the SAX parser be set up in certain ways for it to work properly. The list of such properties may change in the future. Therefore, the use of this method may cause parsing to break, and even if it doesn't break anything today it might break parsing in a future JDOM version, because what JDOM parsers require may change over time. Use with caution.
Parameters: name The property name, which is a fully-qualified URI. value The requested value for the property.
true
(parser reuse).
Note: As SAX parser instances are not thread safe, the parser reuse feature should not be used with SAXBuilder instances shared among threads.
Parameters: reuseParser Whether to reuse the SAX parser.
Parameters: validate boolean
indicating whether validation
should occur.
Parameters: xmlFilter the filter to use