com.bluecast.xml

Class Piccolo

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 XML 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.
String
getEncoding()
EntityResolver
getEntityResolver()
Return the current entity resolver.
ErrorHandler
getErrorHandler()
Return the current error handler.
boolean
getFeature(String name)
Look up the value of a feature flag.
int
getLineNumber()
Return the line number where the current document event ends.
Object
getProperty(String name)
Look up the value of a property.
String
getPublicId()
Return the public identifier for the current document event.
Locator
getStartLocator()
String
getSystemId()
Return the system identifier for the current document event.
String
getVersion()
void
parse(String sysID)
Parse an XML document from a system identifier (URI).
void
parse(InputSource source)
Methods common to both SAX1 and SAX2
void
setContentHandler(ContentHandler handler)
Allow an application to register a content event handler.
void
setDTDHandler(DTDHandler handler)
Allow an application to register a DTD event handler.
void
setDebug(boolean debug)
void
setDocumentHandler(DocumentHandler handler)
SAX1 methods
void
setEntityResolver(EntityResolver resolver)
Allow an application to register an entity resolver.
void
setErrorHandler(ErrorHandler handler)
Allow an application to register an error event handler.
void
setFeature(String name, boolean value)
Set the value of a feature flag.
void
setLocale(java.util.Locale locale)
void
setProperty(String name, Object value)
Set the value of a property.

Field Details

ANY

public static final short ANY
Field Value:
310

ATTLIST_START

public static final short ATTLIST_START
Field Value:
279

CDATA

public static final short CDATA
Field Value:
257

CLOSE_TAG

public static final short CLOSE_TAG
Field Value:
264

COMMA

public static final short COMMA
Field Value:
312

COMMENT

public static final short COMMENT
Field Value:
301

CONDITIONAL_START

public static final short CONDITIONAL_START
Field Value:
302

DOUBLE_RBRACKET_END

public static final short DOUBLE_RBRACKET_END
Field Value:
282

DTD_START

public static final short DTD_START
Field Value:
267

DTD_START_SKIPEXTERNAL

public static final short DTD_START_SKIPEXTERNAL
Field Value:
268

ELEMENT_DECL_START

public static final short ELEMENT_DECL_START
Field Value:
308

EMPTY

public static final short EMPTY
Field Value:
309

EMPTY_TAG

public static final short EMPTY_TAG
Field Value:
265

ENTITIES

public static final short ENTITIES
Field Value:
290

ENTITY

public static final short ENTITY
Field Value:
289

ENTITY_DECL_START

public static final short ENTITY_DECL_START
Field Value:
278

ENTITY_END

public static final short ENTITY_END
Field Value:
294

ENTITY_REF

public static final short ENTITY_REF
Field Value:
293

ENUMERATION

public static final short ENUMERATION
Field Value:
284

EQ

public static final short EQ
Field Value:
262

EXTERNAL_ENTITY_REF

public static final short EXTERNAL_ENTITY_REF
Field Value:
296

FIXED

public static final short FIXED
Field Value:
273

ID

public static final short ID
Field Value:
286

IDREF

public static final short IDREF
Field Value:
287

IDREFS

public static final short IDREFS
Field Value:
288

IGNORE

public static final short IGNORE
Field Value:
305

IGNORED_CONDITIONAL_START

public static final short IGNORED_CONDITIONAL_START
Field Value:
303

IMPLIED

public static final short IMPLIED
Field Value:
272

INCLUDE

public static final short INCLUDE
Field Value:
304

INTERNAL_ENTITY_REF

public static final short INTERNAL_ENTITY_REF
Field Value:
295

LBRACKET

public static final short LBRACKET
Field Value:
276

LPAREN

public static final short LPAREN
Field Value:
274

MODIFIER

public static final short MODIFIER
Field Value:
306

NAME

public static final short NAME
Field Value:
260

NDATA

public static final short NDATA
Field Value:
300

NMTOKEN

public static final short NMTOKEN
Field Value:
291

NMTOKENS

public static final short NMTOKENS
Field Value:
292

NOTATION

public static final short NOTATION
Field Value:
285

NOTATION_START

public static final short NOTATION_START
Field Value:
280

OPEN_TAG

public static final short OPEN_TAG
Field Value:
263

PCDATA

public static final short PCDATA
Field Value:
307

PERCENT

public static final short PERCENT
Field Value:
283

PI

public static final short PI
Field Value:
259

PIPE

public static final short PIPE
Field Value:
277

PLUS

public static final short PLUS
Field Value:
314

PREFIXED_NAME

public static final short PREFIXED_NAME
Field Value:
298

PUBLIC

public static final short PUBLIC
Field Value:
270

QUESTION

public static final short QUESTION
Field Value:
313

RBRACKET_END

public static final short RBRACKET_END
Field Value:
281

REQUIRED

public static final short REQUIRED
Field Value:
271

RPAREN

public static final short RPAREN
Field Value:
275

SKIPPED_ENTITY_REF

public static final short SKIPPED_ENTITY_REF
Field Value:
297

STAR

public static final short STAR
Field Value:
311

STRING

public static final short STRING
Field Value:
261

SYSTEM

public static final short SYSTEM
Field Value:
269

TAG_END

public static final short TAG_END
Field Value:
258

UNPREFIXED_NAME

public static final short UNPREFIXED_NAME
Field Value:
299

WHITESPACE

public static final short WHITESPACE
Field Value:
266

XML_DOC_DECL

public static final short XML_DOC_DECL
Field Value:
315

XML_DOC_OR_TEXT_DECL

public static final short XML_DOC_OR_TEXT_DECL
Field Value:
317

XML_TEXT_DECL

public static final short XML_TEXT_DECL
Field Value:
316

YYERRCODE

public static final short YYERRCODE
Field Value:
256

Constructor Details

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 Details

getColumnNumber

public int getColumnNumber()
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.

getContentHandler

public ContentHandler getContentHandler()
SAX2 methods
Specified by:
getContentHandler in interface XMLReader

getDTDHandler

public DTDHandler getDTDHandler()
Return the current DTD handler.
Specified by:
getDTDHandler in interface XMLReader
Returns:
The current DTD handler, or null if none has been registered.

getEncoding

public String getEncoding()

getEntityResolver

public EntityResolver getEntityResolver()
Return the current entity resolver.
Specified by:
getEntityResolver in interface XMLReader
Returns:
The current entity resolver, or null if none has been registered.

getErrorHandler

public ErrorHandler getErrorHandler()
Return the current error handler.
Specified by:
getErrorHandler in interface XMLReader
Returns:
The current error handler, or null if none has been registered.

getFeature

public boolean getFeature(String name)
            throws SAXNotSupportedException,
                   SAXNotRecognizedException
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).
Throws:
SAXNotRecognizedException - If the feature value can't be assigned or retrieved.
SAXNotSupportedException - When the XMLReader recognizes the feature name but cannot determine its value at this time.

getLineNumber

public int getLineNumber()
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.

getProperty

public Object getProperty(String name)
            throws SAXNotRecognizedException,
                   SAXNotSupportedException
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:
SAXNotRecognizedException - If the property value can't be assigned or retrieved.
SAXNotSupportedException - When the XMLReader recognizes the property name but cannot determine its value at this time.

getPublicId

public String getPublicId()
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.

getStartLocator

public Locator getStartLocator()

getSystemId

public String getSystemId()
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.

getVersion

public String getVersion()

parse

public void parse(String sysID)
            throws IOException,
                   SAXException
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
parse in interface XMLReader
Parameters:
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

parse

public void parse(InputSource source)
            throws IOException,
                   SAXException
Methods common to both SAX1 and SAX2
Specified by:
parse in interface Parser
parse in interface XMLReader

setContentHandler

public void setContentHandler(ContentHandler handler)
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.

setDTDHandler

public void setDTDHandler(DTDHandler handler)
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.

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
setDTDHandler in interface XMLReader
Parameters:
handler - The DTD handler.

setDebug

public void setDebug(boolean debug)

setDocumentHandler

public void setDocumentHandler(DocumentHandler handler)
SAX1 methods
Specified by:
setDocumentHandler in interface Parser

setEntityResolver

public void setEntityResolver(EntityResolver resolver)
Allow an application to register an entity resolver.

If the application does not register an entity resolver, the XMLReader will perform its own default resolution.

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

Specified by:
setEntityResolver in interface Parser
setEntityResolver in interface XMLReader
Parameters:
resolver - The entity resolver.

setErrorHandler

public void setErrorHandler(ErrorHandler handler)
Allow an application to register an error event handler.

If the application does not register an error handler, all error events reported by the SAX parser will be silently ignored; however, normal processing may not continue. It is highly recommended that all SAX applications implement an error handler to avoid unexpected bugs.

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
setErrorHandler in interface XMLReader
Parameters:
handler - The error handler.

setFeature

public void setFeature(String name,
                       boolean value)
            throws SAXNotSupportedException,
                   SAXNotRecognizedException
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.

setLocale

public void setLocale(java.util.Locale locale)
            throws SAXException

setProperty

public void setProperty(String name,
                        Object value)
            throws SAXNotRecognizedException,
                   SAXNotSupportedException
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:
SAXNotRecognizedException - If the property value can't be assigned or retrieved.
SAXNotSupportedException - When the XMLReader recognizes the property name but cannot set the requested value.