Top Description Fields Constructors Methods
org.jdom2.input

public Class SAXBuilder

extends Object
implements SAXEngine
Class Inheritance
All Implemented Interfaces
org.jdom2.input.sax.SAXEngine
Static Imports
org.jdom2.JDOMConstants.SAX_PROPERTY_DECLARATION_HANDLER, .JDOMConstants.SAX_PROPERTY_LEXICAL_HANDLER, .JDOMConstants.SAX_PROPERTY_LEXICAL_HANDLER_ALT

Builds a JDOM Document using a SAX parser.

SAXbuilder uses a third-party SAX parser (chosen by JAXP by default, or you can configure it manually) to handle the parsing duties and uses an instance of a SAXHandler to listen to the SAX events in order to construct a document with JDOM content using a JDOMFactory. Information about SAX can be found at http://www.saxproject.org.

For a complete description of how SAXBuilder is used, and how to customise the process you should look at the org.jdom2.input.sax package documentation.

JDOM users needing to customise the SAX parsing process have traditionally sub-classed this SAXBuilder class. In JDOM2 this should never be necessary. Please read the full documentation of this class, SAXHandler, SAXHandlerFactory, JDOMFactory, and the package documentation for org.jdom2.input.sax before overriding this class. Future versions of JDOM2 may make this class 'final'. I you feel you have a good reason to subclass SAXBuilder please mention it on jdom-interest mailing list so that SAXBuilder can be extended or adapted to handle your use-case.

Neither SAXBuilder nor anything derived from SAXBuilder is thread-safe. You must ensure that SAXBuilder is used in a single thread, or that sufficient locking is in place to ensure that SAXBuilder is not concurrently accessed. See the special note on buildEngine().

Known issues:

Authors
Jason Hunter, Brett McLaughlin, Dan Schaffer, Philip Nelson, Alex Rosen, Rolf Lear
See Also
org.jdom2.input.sax

Field Summary

Modifier and TypeField and Description
private static final JDOMFactory
DEFAULTJDOMFAC

Default source of JDOM Content

private static final SAXHandlerFactory
DEFAULTSAXHANDLERFAC

Default source of SAXHandlers

private SAXEngine
engine

The current SAX parser, if parser reuse has been activated.

private final HashMap<String, Boolean>
features

User-specified features to be set on the SAX parser

private SAXHandlerFactory
handlerfac

The SAXHandler pillar of SAXBuilder

private boolean
ignoringBoundaryWhite

Whether to ignore all whitespace content

private boolean
ignoringWhite

Whether to ignore ignorable whitespace

private JDOMFactory
jdomfac

The JDOMFactory pillar for creating new JDOM objects

private final HashMap<String, Object>
properties

User-specified properties to be set on the SAX parser

private XMLReaderJDOMFactory
readerfac

The XMLReader pillar of SAXBuilder

private boolean
reuseParser

Whether parser reuse is allowed.

private DTDHandler
saxDTDHandler

DTDHandler class to use

private EntityResolver
saxEntityResolver

EntityResolver class to use

private ErrorHandler
saxErrorHandler

ErrorHandler class to use

private XMLFilter
saxXMLFilter

XMLFilter instance to use

Constructor Summary

AccessConstructor and Description
public
SAXBuilder()

Creates a new JAXP-based SAXBuilder.

public
SAXBuilder(final boolean
boolean indicating if DTD validation should occur.
validate
)

Creates a new JAXP-based SAXBuilder.
public
SAXBuilder(final String
String name of SAX Driver to use for parsing.
saxDriverClass
)

Creates a new SAXBuilder using the specified SAX parser.
public
SAXBuilder(final String
String name of SAX Driver to use for parsing.
saxDriverClass
,
final boolean
boolean indicating if validation should occur.
validate
)

Creates a new SAXBuilder using the specified SAX2.0 parser source.
public
SAXBuilder(final XMLReaderJDOMFactory
the XMLReaderJDOMFactory that supplies XMLReaders. If the value is null then a Non-Validating JAXP-based SAX2.0 parser will be used.
readersouce
)

Creates a new SAXBuilder with the specified XMLReaderJDOMFactory.

public
SAXBuilder(final XMLReaderJDOMFactory
a XMLReaderJDOMFactory that creates XMLReaders. Specify null for the default.
xmlreaderfactory
,
final SAXHandlerFactory
a SAXHandlerFactory that creates SAXHandlers Specify null for the default.
handlerfactory
,
final JDOMFactory
a JDOMFactory that creates JDOM Content. Specify null for the default.
jdomfactory
)

Creates a new SAXBuilder.

Method Summary

Modifier and TypeMethod and Description
public Document

Returns:

Document resultant Document object
build
(final InputSource
InputSource to read from
in
)

Implements org.jdom2.input.sax.SAXEngine.build.

This builds a document from the supplied input source.
public Document

Returns:

Document resultant Document object
build
(final InputStream
InputStream to read from
in
)

Implements org.jdom2.input.sax.SAXEngine.build.

This builds a document from the supplied input stream.

public Document

Returns:

Document resultant Document object
build
(final File
File to read from
file
)

Implements org.jdom2.input.sax.SAXEngine.build.

This builds a document from the supplied filename.

public Document

Returns:

Document - resultant Document object.
build
(final URL
URL to read from.
url
)

Implements org.jdom2.input.sax.SAXEngine.build.

This builds a document from the supplied URL.

public Document

Returns:

Document resultant Document object
build
(final InputStream
InputStream to read from.
in
,
final String
base for resolving relative URIs
systemId
)

Implements org.jdom2.input.sax.SAXEngine.build.

This builds a document from the supplied input stream.

public Document

Returns:

Document resultant Document object
build
(final Reader
Reader to read from
characterStream
)

Implements org.jdom2.input.sax.SAXEngine.build.

This builds a document from the supplied Reader.

public Document

Returns:

Document resultant Document object
build
(final Reader
Reader to read from.
characterStream
,
final String
base for resolving relative URIs
systemId
)

Implements org.jdom2.input.sax.SAXEngine.build.

This builds a document from the supplied Reader.

public Document

Returns:

Document resultant Document object
build
(final String
URI for the input
systemId
)

Implements org.jdom2.input.sax.SAXEngine.build.

This builds a document from the supplied URI.

public SAXEngine

Returns:

a SAXEngine representing the current state of the current SAXBuilder settings.
buildEngine
()

This method builds a new and reusable SAXEngine.

protected void
configureParser(final XMLReader
the XMLReader to configure.
parser
,
final SAXHandler
The SAXHandler to use for the XMLReader
contentHandler
)

This configures the XMLReader to be used for reading the XML document.

protected XMLReader

Returns:

a XMLReader parser.
createParser
()

Allow overriding classes access to the Parser before it is used in a SAXBuilderEngine.

public String

Returns:

the driver class assigned in the constructor
getDriverClass
()

Deprecated as the driver class is only available in limited situations and anyway it had to be supplied in a constructor as either a direct value or as an XMLReaderSAX2Factory instance.
Returns the driver class assigned in the constructor, or null if none.
public DTDHandler

Returns:

the DTDHandler assigned
getDTDHandler
()

Implements org.jdom2.input.sax.SAXEngine.getDTDHandler.

Returns the DTDHandler assigned, or null if the assigned SAXHandler will be used for DTD SAX events.
private SAXEngine

Returns:

a SAXBuilderEngine representing the current state of the current SAXBuilder settings.
getEngine
()

This method retrieves (or builds) a SAXBuilderEngine that represents the current SAXBuilder state.

public EntityResolver

Returns:

the EntityResolver assigned
getEntityResolver
()

Implements org.jdom2.input.sax.SAXEngine.getEntityResolver.

Returns the EntityResolver assigned, or null if none.
public ErrorHandler

Returns:

the ErrorHandler assigned, or null if SAXBuilder will create a default ErrorHandler when needed.
getErrorHandler
()

Implements org.jdom2.input.sax.SAXEngine.getErrorHandler.

Returns the ErrorHandler assigned, or null if none.
public boolean

Returns:

whether entities are being expanded
getExpandEntities
()

Implements org.jdom2.input.sax.SAXEngine.getExpandEntities.

Returns whether or not entities are being expanded into normal text content.
public JDOMFactory

Returns:

the factory in use
getFactory
()

Deprecated as it is replaced by getJDOMFactory()
Returns the current org.jdom2.JDOMFactory in use.
public boolean

Returns:

boolean - whether only whitespace content will be ignored during build.
getIgnoringBoundaryWhitespace
()

Implements org.jdom2.input.sax.SAXEngine.getIgnoringBoundaryWhitespace.

Returns whether or not the parser will eliminate element content containing only whitespace.
public boolean

Returns:

whether element content whitespace is to be ignored during the build
getIgnoringElementContentWhitespace
()

Implements org.jdom2.input.sax.SAXEngine.getIgnoringElementContentWhitespace.

Returns whether element content whitespace is to be ignored during the build.
public JDOMFactory

Returns:

the factory in use
getJDOMFactory
()

Implements org.jdom2.input.sax.SAXEngine.getJDOMFactory.

Returns the current org.jdom2.JDOMFactory in use.
public boolean

Returns:

whether the contained SAX parser instance is reused across multiple parses
getReuseParser
()

Returns whether the contained SAX parser instance is reused across multiple parses.

public SAXHandlerFactory

Returns:

the current SAXHandlerFactory (never null).
getSAXHandlerFactory
()

Get the SAXHandlerFactory used to supply SAXHandlers to this SAXBuilder.

public boolean

Returns:

whether validation is to be performed during the build
getValidation
()

Deprecated in lieu of isValidating()
Returns whether validation is to be performed during the build.
public XMLFilter

Returns:

the XMLFilter used during parsing
getXMLFilter
()

Returns the XMLFilter used during parsing, or null if none.

public XMLReaderJDOMFactory

Returns:

the current JDOMXMLReaderFactory
getXMLReaderFactory
()

Get the current XMLReader factory.

private void
internalSetFeature(final XMLReader parser, final String feature, final boolean value, final String displayName)

Tries to set a feature on the parser.

private void
internalSetProperty(final XMLReader parser, final String property, final Object value, final String displayName)

Tries to set a property on the parser.

public boolean

Returns:

whether validation is to be performed during the build
isValidating
()

Implements org.jdom2.input.sax.SAXEngine.isValidating.

Returns whether validation is to be performed during the build.
public void
setDTDHandler(final DTDHandler
DTDHandler
dtdHandler
)

This sets custom DTDHandler for the Builder.

public void
setEntityResolver(final EntityResolver
EntityResolver
entityResolver
)

This sets custom EntityResolver for the Builder.

public void
setErrorHandler(final ErrorHandler
ErrorHandler
errorHandler
)

This sets custom ErrorHandler for the Builder.

public void
setExpandEntities(final boolean
boolean indicating whether entity expansion should occur.
expand
)

This sets whether or not to expand entities for the builder.

public void
setFactory(final JDOMFactory
JDOMFactory to use
factory
)

Deprecated as it is replaced by setJDOMFactory(JDOMFactory)
This sets a custom JDOMFactory for the builder.
public void
setFastReconfigure(final boolean
Whether to do a fast reconfiguration of the parser
fastReconfigure
)

Deprecated All reused Parsers are now fast-reconfigured. No need to set it.
Specifies whether this builder will do fast reconfiguration of the underlying SAX parser when reuseParser is true.
public void
setFeature(final String
The feature name, which is a fully-qualified URI.
name
,
final boolean
The requested state of the feature (true or false).
value
)

This sets a feature on the SAX parser.

public void
setIgnoringBoundaryWhitespace(final boolean
Whether to ignore whitespace-only text nodes
ignoringBoundaryWhite
)

Specifies whether or not the parser should eliminate boundary whitespace, a term that indicates whitespace-only text between element tags.

public void
setIgnoringElementContentWhitespace(final boolean
Whether to ignore ignorable whitespace
ignoringWhite
)

Specifies whether or not the parser should eliminate whitespace in element content (sometimes known as "ignorable whitespace") when building the document.

public void
setJDOMFactory(final JDOMFactory
JDOMFactory to use
factory
)

This sets a custom JDOMFactory for the builder.

public void
setProperty(final String
The property name, which is a fully-qualified URI.
name
,
final Object
The requested value for the property.
value
)

This sets a property on the SAX parser.

public void
setReuseParser(final boolean
Whether to reuse the SAX parser.
reuseParser
)

Specifies whether this builder will reuse the same SAX parser when performing subsequent parses or allocate a new parser for each parse.

public void
setSAXHandlerFactory(final SAXHandlerFactory
the required SAXHandlerFactory. A null input factory will request the DefaultSAXHandlerFactory.
factory
)

Set the SAXHandlerFactory to be used by this SAXBuilder.

public void
setValidation(final boolean
boolean indicating whether validation should occur.
validate
)

This sets validation for the builder.
public void
setXMLFilter(final XMLFilter
the XMLFilter to use
xmlFilter
)

This sets a custom org.xml.sax.XMLFilter for the builder.

public void
setXMLReaderFactory(final XMLReaderJDOMFactory
the JDOMXMLReaderFactory to set. A null rfac will indicate the default XMLReaders#NONVALIDATING
rfac
)

Set the current XMLReader factory.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait