com.bluecast.xml
Class Piccolo

java.lang.Object
  |
  +--com.bluecast.xml.Piccolo
All Implemented Interfaces:
Locator, Parser, XMLReader

public class Piccolo
extends java.lang.Object
implements Parser, Locator, XMLReader

Piccolo is a small, high-performance SAX1 and SAX2 parser. As per the SAX2 specification, namespace handling is on by default. You can improve performance by turning it off. Note that if used in SAX1 mode, namespace handling is automatically turned off.


Field Summary
static short ANY
           
static short ATTLIST_START
           
static short CDATA
           
static short CLOSE_TAG
           
static short COMMA
           
static short COMMENT
           
static short CONDITIONAL_START
           
static short DOUBLE_RBRACKET_END
           
static short DTD_START
           
static short DTD_START_SKIPEXTERNAL
           
static short ELEMENT_DECL_START
           
static short EMPTY
           
static short EMPTY_TAG
           
static short ENTITIES
           
static short ENTITY
           
static short ENTITY_DECL_START
           
static short ENTITY_END
           
static short ENTITY_REF
           
static short ENUMERATION
           
static short EQ
           
static short EXTERNAL_ENTITY_REF
           
static short FIXED
           
static short ID
           
static short IDREF
           
static short IDREFS
           
static short IGNORE
           
static short IGNORED_CONDITIONAL_START
           
static short IMPLIED
           
static short INCLUDE
           
static short INTERNAL_ENTITY_REF
           
static short LBRACKET
           
static short LPAREN
           
static short MODIFIER
           
static short NAME
           
static short NDATA
           
static short NMTOKEN
           
static short NMTOKENS
           
static short NOTATION
           
static short NOTATION_START
           
static short OPEN_TAG
           
static short PCDATA
           
static short PERCENT
           
static short PI
           
static short PIPE
           
static short PLUS
           
static short PREFIXED_NAME
           
static short PUBLIC
           
static short QUESTION
           
static short RBRACKET_END
           
static short REQUIRED
           
static short RPAREN
           
static short SKIPPED_ENTITY_REF
           
static short STAR
           
static short STRING
           
static short SYSTEM
           
static short TAG_END
           
static short UNPREFIXED_NAME
           
static short WHITESPACE
           
static short XML_DOC_DECL
           
static short XML_DOC_OR_TEXT_DECL
           
static short XML_TEXT_DECL
           
static short YYERRCODE
           
 
Constructor Summary
Piccolo()
           
Piccolo(Piccolo template)
          Create an instance with the same configuration as the given instance.
 
Method Summary
 int getColumnNumber()
          Return the column number where the current document event ends.
 ContentHandler getContentHandler()
          SAX2 methods
 DTDHandler getDTDHandler()
          Return the current DTD handler.
 EntityResolver getEntityResolver()
          Return the current entity resolver.
 ErrorHandler getErrorHandler()
          Return the current error handler.
 boolean getFeature(java.lang.String name)
          Look up the value of a feature flag.
 int getLineNumber()
          Return the line number where the current document event ends.
 java.lang.Object getProperty(java.lang.String name)
          Look up the value of a property.
 java.lang.String getPublicId()
          Return the public identifier for the current document event.
 java.lang.String getSystemId()
          Return the system identifier for the current document event.
 void parse(InputSource source)
          Methods common to both SAX1 and SAX2
 void parse(java.lang.String sysID)
          Parse an XML document from a system identifier (URI).
 void setContentHandler(ContentHandler handler)
          Allow an application to register a content event handler.
 void setDebug(boolean debug)
           
 void setDocumentHandler(DocumentHandler handler)
          SAX1 methods
 void setDTDHandler(DTDHandler handler)
          Allow an application to register a DTD event handler.
 void setEntityResolver(EntityResolver resolver)
          Allow an application to register a custom entity resolver.
 void setErrorHandler(ErrorHandler handler)
          Allow an application to register an error event handler.
 void setFeature(java.lang.String name, boolean value)
          Set the value of a feature flag.
 void setLocale(java.util.Locale locale)
          Allow an application to request a locale for errors and warnings.
 void setProperty(java.lang.String name, java.lang.Object value)
          Set the value of a property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CDATA

public static final short CDATA
See Also:
Constant Field Values

TAG_END

public static final short TAG_END
See Also:
Constant Field Values

PI

public static final short PI
See Also:
Constant Field Values

NAME

public static final short NAME
See Also:
Constant Field Values

STRING

public static final short STRING
See Also:
Constant Field Values

EQ

public static final short EQ
See Also:
Constant Field Values

OPEN_TAG

public static final short OPEN_TAG
See Also:
Constant Field Values

CLOSE_TAG

public static final short CLOSE_TAG
See Also:
Constant Field Values

EMPTY_TAG

public static final short EMPTY_TAG
See Also:
Constant Field Values

WHITESPACE

public static final short WHITESPACE
See Also:
Constant Field Values

DTD_START

public static final short DTD_START
See Also:
Constant Field Values

DTD_START_SKIPEXTERNAL

public static final short DTD_START_SKIPEXTERNAL
See Also:
Constant Field Values

SYSTEM

public static final short SYSTEM
See Also:
Constant Field Values

PUBLIC

public static final short PUBLIC
See Also:
Constant Field Values

REQUIRED

public static final short REQUIRED
See Also:
Constant Field Values

IMPLIED

public static final short IMPLIED
See Also:
Constant Field Values

FIXED

public static final short FIXED
See Also:
Constant Field Values

LPAREN

public static final short LPAREN
See Also:
Constant Field Values

RPAREN

public static final short RPAREN
See Also:
Constant Field Values

LBRACKET

public static final short LBRACKET
See Also:
Constant Field Values

PIPE

public static final short PIPE
See Also:
Constant Field Values

ENTITY_DECL_START

public static final short ENTITY_DECL_START
See Also:
Constant Field Values

ATTLIST_START

public static final short ATTLIST_START
See Also:
Constant Field Values

NOTATION_START

public static final short NOTATION_START
See Also:
Constant Field Values

RBRACKET_END

public static final short RBRACKET_END
See Also:
Constant Field Values

DOUBLE_RBRACKET_END

public static final short DOUBLE_RBRACKET_END
See Also:
Constant Field Values

PERCENT

public static final short PERCENT
See Also:
Constant Field Values

ENUMERATION

public static final short ENUMERATION
See Also:
Constant Field Values

NOTATION

public static final short NOTATION
See Also:
Constant Field Values

ID

public static final short ID
See Also:
Constant Field Values

IDREF

public static final short IDREF
See Also:
Constant Field Values

IDREFS

public static final short IDREFS
See Also:
Constant Field Values

ENTITY

public static final short ENTITY
See Also:
Constant Field Values

ENTITIES

public static final short ENTITIES
See Also:
Constant Field Values

NMTOKEN

public static final short NMTOKEN
See Also:
Constant Field Values

NMTOKENS

public static final short NMTOKENS
See Also:
Constant Field Values

ENTITY_REF

public static final short ENTITY_REF
See Also:
Constant Field Values

ENTITY_END

public static final short ENTITY_END
See Also:
Constant Field Values

INTERNAL_ENTITY_REF

public static final short INTERNAL_ENTITY_REF
See Also:
Constant Field Values

EXTERNAL_ENTITY_REF

public static final short EXTERNAL_ENTITY_REF
See Also:
Constant Field Values

SKIPPED_ENTITY_REF

public static final short SKIPPED_ENTITY_REF
See Also:
Constant Field Values

PREFIXED_NAME

public static final short PREFIXED_NAME
See Also:
Constant Field Values

UNPREFIXED_NAME

public static final short UNPREFIXED_NAME
See Also:
Constant Field Values

NDATA

public static final short NDATA
See Also:
Constant Field Values

COMMENT

public static final short COMMENT
See Also:
Constant Field Values

CONDITIONAL_START

public static final short CONDITIONAL_START
See Also:
Constant Field Values

IGNORED_CONDITIONAL_START

public static final short IGNORED_CONDITIONAL_START
See Also:
Constant Field Values

INCLUDE

public static final short INCLUDE
See Also:
Constant Field Values

IGNORE

public static final short IGNORE
See Also:
Constant Field Values

MODIFIER

public static final short MODIFIER
See Also:
Constant Field Values

PCDATA

public static final short PCDATA
See Also:
Constant Field Values

ELEMENT_DECL_START

public static final short ELEMENT_DECL_START
See Also:
Constant Field Values

EMPTY

public static final short EMPTY
See Also:
Constant Field Values

ANY

public static final short ANY
See Also:
Constant Field Values

STAR

public static final short STAR
See Also:
Constant Field Values

COMMA

public static final short COMMA
See Also:
Constant Field Values

QUESTION

public static final short QUESTION
See Also:
Constant Field Values

PLUS

public static final short PLUS
See Also:
Constant Field Values

XML_DOC_DECL

public static final short XML_DOC_DECL
See Also:
Constant Field Values

XML_TEXT_DECL

public static final short XML_TEXT_DECL
See Also:
Constant Field Values

XML_DOC_OR_TEXT_DECL

public static final short XML_DOC_OR_TEXT_DECL
See Also:
Constant Field Values

YYERRCODE

public static final short YYERRCODE
See Also:
Constant Field Values
Constructor Detail

Piccolo

public Piccolo()

Piccolo

public Piccolo(Piccolo template)
Create an instance with the same configuration as the given instance. ContentHandler, DTDHandler, etc. will not be copied.

Method Detail

setDebug

public void setDebug(boolean debug)

parse

public void parse(InputSource source)
           throws java.io.IOException,
                  SAXException
Methods common to both SAX1 and SAX2

Specified by:
parse in interface Parser
Parameters:
source - The input source for the top-level of the XML document.
Throws:
java.io.IOException - An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
InputSource, Parser.parse(java.lang.String), Parser.setEntityResolver(org.xml.sax.EntityResolver), Parser.setDTDHandler(org.xml.sax.DTDHandler), Parser.setDocumentHandler(org.xml.sax.DocumentHandler), Parser.setErrorHandler(org.xml.sax.ErrorHandler)

parse

public void parse(java.lang.String sysID)
           throws java.io.IOException,
                  SAXException
Description copied from interface: Parser
Parse an XML document from a system identifier (URI).

This method is a shortcut for the common case of reading a document from a system identifier. It is the exact equivalent of the following:

 parse(new InputSource(systemId));
 

If the system identifier is a URL, it must be fully resolved by the application before it is passed to the parser.

Specified by:
parse in interface Parser
Parameters:
sysID - The system identifier (URI).
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
java.io.IOException - An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
See Also:
Parser.parse(org.xml.sax.InputSource)

setDocumentHandler

public void setDocumentHandler(DocumentHandler handler)
SAX1 methods

Specified by:
setDocumentHandler in interface Parser
Parameters:
handler - The document handler.
See Also:
DocumentHandler, HandlerBase

setDTDHandler

public void setDTDHandler(DTDHandler handler)
Description copied from interface: Parser
Allow an application to register a DTD event handler.

If the application does not register a DTD handler, all DTD events reported by the SAX parser will be silently ignored (this is the default behaviour implemented by HandlerBase).

Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.

Specified by:
setDTDHandler in interface Parser
Parameters:
handler - The DTD handler.
See Also:
DTDHandler, HandlerBase

setEntityResolver

public void setEntityResolver(EntityResolver resolver)
Description copied from interface: Parser
Allow an application to register a custom entity resolver.

If the application does not register an entity resolver, the SAX parser will resolve system identifiers and open connections to entities itself (this is the default behaviour implemented in HandlerBase).

Applications may register a new or different entity resolver in the middle of a parse, and the SAX parser must begin using the new resolver immediately.

Specified by:
setEntityResolver in interface Parser
Parameters:
resolver - The object for resolving entities.
See Also:
EntityResolver, HandlerBase

setErrorHandler

public void setErrorHandler(ErrorHandler handler)
Description copied from interface: Parser
Allow an application to register an error event handler.

If the application does not register an error event handler, all error events reported by the SAX parser will be silently ignored, except for fatalError, which will throw a SAXException (this is the default behaviour implemented by HandlerBase).

Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.

Specified by:
setErrorHandler in interface Parser
Parameters:
handler - The error handler.
See Also:
ErrorHandler, SAXException, HandlerBase

setLocale

public void setLocale(java.util.Locale locale)
Description copied from interface: Parser
Allow an application to request a locale for errors and warnings.

SAX parsers are not required to provide localisation for errors and warnings; if they cannot support the requested locale, however, they must throw a SAX exception. Applications may not request a locale change in the middle of a parse.

Specified by:
setLocale in interface Parser
Parameters:
locale - A Java Locale object.
See Also:
SAXException, SAXParseException

getColumnNumber

public int getColumnNumber()
Description copied from interface: Locator
Return the column number where the current document event ends. This is one-based number of Java char values since the last line end.

Warning: The return value from the method is intended only as an approximation for the sake of diagnostics; it is not intended to provide sufficient information to edit the character content of the original XML document. For example, when lines contain combining character sequences, wide characters, surrogate pairs, or bi-directional text, the value may not correspond to the column in a text editor's display.

The return value is an approximation of the column number in the document entity or external parsed entity where the markup triggering the event appears.

If possible, the SAX driver should provide the line position of the first character after the text associated with the document event. The first column in each line is column 1.

Specified by:
getColumnNumber in interface Locator
Returns:
The column number, or -1 if none is available.
See Also:
Locator.getLineNumber()

getLineNumber

public int getLineNumber()
Description copied from interface: Locator
Return the line number where the current document event ends. Lines are delimited by line ends, which are defined in the XML specification.

Warning: The return value from the method is intended only as an approximation for the sake of diagnostics; it is not intended to provide sufficient information to edit the character content of the original XML document. In some cases, these "line" numbers match what would be displayed as columns, and in others they may not match the source text due to internal entity expansion.

The return value is an approximation of the line number in the document entity or external parsed entity where the markup triggering the event appears.

If possible, the SAX driver should provide the line position of the first character after the text associated with the document event. The first line is line 1.

Specified by:
getLineNumber in interface Locator
Returns:
The line number, or -1 if none is available.
See Also:
Locator.getColumnNumber()

getPublicId

public java.lang.String getPublicId()
Description copied from interface: Locator
Return the public identifier for the current document event.

The return value is the public identifier of the document entity or of the external parsed entity in which the markup triggering the event appears.

Specified by:
getPublicId in interface Locator
Returns:
A string containing the public identifier, or null if none is available.
See Also:
Locator.getSystemId()

getSystemId

public java.lang.String getSystemId()
Description copied from interface: Locator
Return the system identifier for the current document event.

The return value is the system identifier of the document entity or of the external parsed entity in which the markup triggering the event appears.

If the system identifier is a URL, the parser must resolve it fully before passing it to the application. For example, a file name must always be provided as a file:... URL, and other kinds of relative URI are also resolved against their bases.

Specified by:
getSystemId in interface Locator
Returns:
A string containing the system identifier, or null if none is available.
See Also:
Locator.getPublicId()

getContentHandler

public ContentHandler getContentHandler()
SAX2 methods

Specified by:
getContentHandler in interface XMLReader
Returns:
The current content handler, or null if none has been registered.
See Also:
XMLReader.setContentHandler(org.xml.sax.ContentHandler)

setContentHandler

public void setContentHandler(ContentHandler handler)
Description copied from interface: XMLReader
Allow an application to register a content event handler.

If the application does not register a content handler, all content events reported by the SAX parser will be silently ignored.

Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.

Specified by:
setContentHandler in interface XMLReader
Parameters:
handler - The content handler.
See Also:
XMLReader.getContentHandler()

getDTDHandler

public DTDHandler getDTDHandler()
Description copied from interface: XMLReader
Return the current DTD handler.

Specified by:
getDTDHandler in interface XMLReader
Returns:
The current DTD handler, or null if none has been registered.
See Also:
XMLReader.setDTDHandler(org.xml.sax.DTDHandler)

getEntityResolver

public EntityResolver getEntityResolver()
Description copied from interface: XMLReader
Return the current entity resolver.

Specified by:
getEntityResolver in interface XMLReader
Returns:
The current entity resolver, or null if none has been registered.
See Also:
XMLReader.setEntityResolver(org.xml.sax.EntityResolver)

getErrorHandler

public ErrorHandler getErrorHandler()
Description copied from interface: XMLReader
Return the current error handler.

Specified by:
getErrorHandler in interface XMLReader
Returns:
The current error handler, or null if none has been registered.
See Also:
XMLReader.setErrorHandler(org.xml.sax.ErrorHandler)

getFeature

public boolean getFeature(java.lang.String name)
Description copied from interface: XMLReader
Look up the value of a feature flag.

The feature name is any fully-qualified URI. It is possible for an XMLReader to recognize a feature name but temporarily be unable to return its value. Some feature values may be available only in specific contexts, such as before, during, or after a parse. Also, some feature values may not be programmatically accessible. (In the case of an adapter for SAX1 Parser, there is no implementation-independent way to expose whether the underlying parser is performing validation, expanding external entities, and so forth.)

All XMLReaders are required to recognize the http://xml.org/sax/features/namespaces and the http://xml.org/sax/features/namespace-prefixes feature names.

Typical usage is something like this:

 XMLReader r = new MySAXDriver();

                         // try to activate validation
 try {
   r.setFeature("http://xml.org/sax/features/validation", true);
 } catch (SAXException e) {
   System.err.println("Cannot activate validation."); 
 }

                         // register event handlers
 r.setContentHandler(new MyContentHandler());
 r.setErrorHandler(new MyErrorHandler());

                         // parse the first document
 try {
   r.parse("http://www.foo.com/mydoc.xml");
 } catch (IOException e) {
   System.err.println("I/O exception reading XML document");
 } catch (SAXException e) {
   System.err.println("XML exception reading document.");
 }
 

Implementors are free (and encouraged) to invent their own features, using names built on their own URIs.

Specified by:
getFeature in interface XMLReader
Parameters:
name - The feature name, which is a fully-qualified URI.
Returns:
The current value of the feature (true or false).
See Also:
XMLReader.setFeature(java.lang.String, boolean)

setFeature

public void setFeature(java.lang.String name,
                       boolean value)
                throws SAXNotSupportedException,
                       SAXNotRecognizedException
Description copied from interface: XMLReader
Set the value of a feature flag.

The feature name is any fully-qualified URI. It is possible for an XMLReader to expose a feature value but to be unable to change the current value. Some feature values may be immutable or mutable only in specific contexts, such as before, during, or after a parse.

All XMLReaders are required to support setting http://xml.org/sax/features/namespaces to true and http://xml.org/sax/features/namespace-prefixes to false.

Specified by:
setFeature in interface XMLReader
Parameters:
name - The feature name, which is a fully-qualified URI.
value - The requested value of the feature (true or false).
Throws:
SAXNotRecognizedException - If the feature value can't be assigned or retrieved.
SAXNotSupportedException - When the XMLReader recognizes the feature name but cannot set the requested value.
See Also:
XMLReader.getFeature(java.lang.String)

getProperty

public java.lang.Object getProperty(java.lang.String name)
                             throws SAXNotRecognizedException,
                                    SAXNotSupportedException
Description copied from interface: XMLReader
Look up the value of a property.

The property name is any fully-qualified URI. It is possible for an XMLReader to recognize a property name but temporarily be unable to return its value. Some property values may be available only in specific contexts, such as before, during, or after a parse.

XMLReaders are not required to recognize any specific property names, though an initial core set is documented for SAX2.

Implementors are free (and encouraged) to invent their own properties, using names built on their own URIs.

Specified by:
getProperty in interface XMLReader
Parameters:
name - The property name, which is a fully-qualified URI.
Returns:
The current value of the property.
Throws:
SAXNotSupportedException - When the XMLReader recognizes the property name but cannot determine its value at this time.
SAXNotRecognizedException - If the property value can't be assigned or retrieved.
See Also:
XMLReader.setProperty(java.lang.String, java.lang.Object)

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
                 throws SAXNotRecognizedException,
                        SAXNotSupportedException
Description copied from interface: XMLReader
Set the value of a property.

The property name is any fully-qualified URI. It is possible for an XMLReader to recognize a property name but to be unable to change the current value. Some property values may be immutable or mutable only in specific contexts, such as before, during, or after a parse.

XMLReaders are not required to recognize setting any specific property names, though a core set is defined by SAX2.

This method is also the standard mechanism for setting extended handlers.

Specified by:
setProperty in interface XMLReader
Parameters:
name - The property name, which is a fully-qualified URI.
value - The requested value for the property.
Throws:
SAXNotSupportedException - When the XMLReader recognizes the property name but cannot set the requested value.
SAXNotRecognizedException - If the property value can't be assigned or retrieved.