org.ceryle.xml
Class XMLProcessor

java.lang.Object
  extended by org.ceryle.xml.XMLProcessor
All Implemented Interfaces:
ErrorHandler

public class XMLProcessor
extends Object
implements ErrorHandler

Provides an XML processor for parsing XML files.

Since:
JDK1.3
Version:
$Id: XMLProcessor.java,v 3.10 2007-06-15 12:10:29 altheim Exp $
Author:
Murray Altheim

Field Summary
static String ELEMENT_CONTENT_WS_FEATURE
          Feature identifier: ignoring element content whitespace feature.
static String EXPAND_ENTITY_REF_FEATURE
          Feature identifier: expand entity references feature.
static String INCLUDE_COMMENTS_FEATURE
          Feature identifier: include comments feature.
protected  org.apache.xml.resolver.tools.CatalogResolver m_catalogResolver
          The CatalogResolver used to resolve XML entity references.
protected  DocumentBuilder m_db
          The DocumentBuilder used to process XML Documents.
static String NAMESPACE_FEATURE
          Feature identifier: namespaces.
static String VALIDATION_FEATURE
          Feature identifier: validation feature.
static String XML_FEATURE_PFX
          XML Processor Feature prefix.
 
Constructor Summary
XMLProcessor()
          Constructor that creates an XMLProcessor with default values.
XMLProcessor(boolean validation, boolean xmlnsAware)
          Constructor that creates an XMLProcessor (a DOM parser) provided a boolean validation and xmlnsAware settings, with defaults used for other settings: ignore ignorable element content whitespace don't expand entity references
XMLProcessor(Properties properties)
          Constructor provided a set of Properties.
 
Method Summary
 void error(SAXParseException exception)
          Tunnel an existing SAXParseException.
 void fatalError(SAXParseException exception)
          A method which handles a fatal exception given a tunneled SAXParseException.
 org.apache.xml.resolver.tools.CatalogResolver getCatalogResolver()
          Returns the CatalogResolver used with this XMLProcessor.
 Iterator getErrors()
          Returns an Iterator over the parse errors (as Exceptions) encountered during the last document parse, null if there were none.
 DocumentBuilder getParser()
          Returns the DocumentBuilder (parser) used by this XMLProcessor, null if this is unavailable.
 boolean hadErrors()
          Returns true if the previous parse contained any parsing errors.
 boolean isValidating()
          Returns true if the DocumentBuilder (XML parser) is validating, false if a well-formed parser.
 Document process(InputSource source)
          Returns the XML Document resulting from processing the source file, throwing an XMLParseException if a parsing error occurs.
 TypedInputSource resolveEntity(TypedInputSource source)
          Attempts to resolve the public and system identifiers in the provided TypedInputSource source using the catalog resolver.
protected  void setCatalogResolver(org.apache.xml.resolver.tools.CatalogResolver resolver)
          Sets the CatalogResolver used with this XMLProcessor.
 void warning(SAXParseException exception)
          Tunnel an existing SAXParseException.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XML_FEATURE_PFX

public static final String XML_FEATURE_PFX
XML Processor Feature prefix.

See Also:
Constant Field Values

NAMESPACE_FEATURE

public static final String NAMESPACE_FEATURE
Feature identifier: namespaces.

See Also:
Constant Field Values

VALIDATION_FEATURE

public static final String VALIDATION_FEATURE
Feature identifier: validation feature.

See Also:
Constant Field Values

EXPAND_ENTITY_REF_FEATURE

public static final String EXPAND_ENTITY_REF_FEATURE
Feature identifier: expand entity references feature.

See Also:
Constant Field Values

INCLUDE_COMMENTS_FEATURE

public static final String INCLUDE_COMMENTS_FEATURE
Feature identifier: include comments feature.

See Also:
Constant Field Values

ELEMENT_CONTENT_WS_FEATURE

public static final String ELEMENT_CONTENT_WS_FEATURE
Feature identifier: ignoring element content whitespace feature.

See Also:
Constant Field Values

m_db

protected DocumentBuilder m_db
The DocumentBuilder used to process XML Documents.


m_catalogResolver

protected org.apache.xml.resolver.tools.CatalogResolver m_catalogResolver
The CatalogResolver used to resolve XML entity references.

Constructor Detail

XMLProcessor

public XMLProcessor()
             throws ProcessException
Constructor that creates an XMLProcessor with default values. These are:

Throws:
ProcessException - if parser configuration errors.

XMLProcessor

public XMLProcessor(boolean validation,
                    boolean xmlnsAware)
             throws ProcessException
Constructor that creates an XMLProcessor (a DOM parser) provided a boolean validation and xmlnsAware settings, with defaults used for other settings:

Parameters:
validation - if true, the parser will validate.
xmlnsAware - if true, the parser will be aware of XML namespaces.
Throws:
ProcessException - if parser configuration errors.

XMLProcessor

public XMLProcessor(Properties properties)
             throws ProcessException
Constructor provided a set of Properties. Boolean values may be provided for the settings (which are provided as String constants by the class):
http://purl.org/ceryle/xml/features/validation
Specifies that the parser will validate documents as they are parsed. (default false)
http://purl.org/ceryle/xml/features/namespaces
Specifies that the parser will provide support for XML namespaces. (default true)
http://purl.org/ceryle/features/dom/include-comments
Specifies that the parser will include comments. (default true)
http://purl.org/ceryle/features/dom/expand-entity-references
Specifies that the parser will expand entity reference nodes. (default true)
http://purl.org/ceryle/features/dom/element-content-whitespace
Specifies that the parsers must eliminate whitespace in element content (sometimes known loosely as 'ignorable whitespace') when parsing XML documents (see XML Rec 2.10). (default false)

Note that these features mirror those found in Xerces2.

Note:

The first time XMLProcessor is instantiated, the XML catalog resolver must be manually established with setCatalogResolver(). This is so that the PropertyManager can be created without requiring the CatalogResolver first. This can be done by first creating a WF XMLProcessor, then the validating one.

Parameters:
properties - processor settings
Throws:
ProcessException - if parser configuration errors
Method Detail

setCatalogResolver

protected void setCatalogResolver(org.apache.xml.resolver.tools.CatalogResolver resolver)
Sets the CatalogResolver used with this XMLProcessor.


getCatalogResolver

public org.apache.xml.resolver.tools.CatalogResolver getCatalogResolver()
Returns the CatalogResolver used with this XMLProcessor.


resolveEntity

public TypedInputSource resolveEntity(TypedInputSource source)
Attempts to resolve the public and system identifiers in the provided TypedInputSource source using the catalog resolver. If the catalog resolves either reference to a different system identifier, the system identifier of the provided TypedInputSource will be altered to the new value.


getParser

public DocumentBuilder getParser()
Returns the DocumentBuilder (parser) used by this XMLProcessor, null if this is unavailable.


isValidating

public boolean isValidating()
Returns true if the DocumentBuilder (XML parser) is validating, false if a well-formed parser.


hadErrors

public boolean hadErrors()
Returns true if the previous parse contained any parsing errors. If not parse has occurred, returns false.


getErrors

public Iterator getErrors()
Returns an Iterator over the parse errors (as Exceptions) encountered during the last document parse, null if there were none.


process

public Document process(InputSource source)
                 throws XMLParseException,
                        ProcessException
Returns the XML Document resulting from processing the source file, throwing an XMLParseException if a parsing error occurs.

Parameters:
source - a SAX InputSource to be parsed.
Throws:
XMLParseException - an exception encountered during XML parsing
ProcessException - encapsulating any of the other ten thousand possible exceptions

warning

public void warning(SAXParseException exception)
Tunnel an existing SAXParseException. Displays a non-fatal warning.

Specified by:
warning in interface ErrorHandler
Parameters:
exception - the tunneled SAXParseException.

error

public void error(SAXParseException exception)
Tunnel an existing SAXParseException. An XML error is generally fatal.

Specified by:
error in interface ErrorHandler
Parameters:
exception - the tunneled SAXParseException.

fatalError

public void fatalError(SAXParseException exception)
A method which handles a fatal exception given a tunneled SAXParseException.

Specified by:
fatalError in interface ErrorHandler
Parameters:
exception - the tunneled SAXParseException.


The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.