com.icl.saxon
Class Builder

java.lang.Object
  |
  +--com.icl.saxon.Builder
All Implemented Interfaces:
Emitter, org.xml.sax.ErrorHandler, org.xml.sax.Locator
Direct Known Subclasses:
TinyBuilder, TreeBuilder

public abstract class Builder
extends java.lang.Object
implements Emitter, org.xml.sax.ErrorHandler, org.xml.sax.Locator

The abstract Builder class is responsible for taking a stream of SAX events and constructing a Document tree. There is one concrete subclass for each tree implementation.


Field Summary
protected  java.lang.String baseURI
           
protected  DocumentInfo currentDocument
           
protected  boolean discardComments
           
protected  int documentNumber
           
protected  org.xml.sax.ErrorHandler errorHandler
           
protected  java.io.Writer errorOutput
           
protected  int estimatedLength
           
protected  boolean failed
           
protected  boolean inDTD
           
protected  boolean lineNumbering
           
protected  org.xml.sax.Locator locator
           
protected  NamePool namePool
           
protected  Sequencer nodeSequencer
           
protected  org.xml.sax.XMLReader parser
           
protected  PreviewManager previewManager
           
static int STANDARD_TREE
           
protected  boolean started
           
protected  Stripper stripper
           
protected  boolean timing
           
static int TINY_TREE
           
 
Constructor Summary
Builder()
          create a Builder and initialise variables
 
Method Summary
 DocumentInfo build(org.xml.sax.InputSource in)
          Build the tree from an input source.
abstract  void characters(char[] ch, int start, int length)
          Callback interface for SAX: not for application use
abstract  void comment(char[] ch, int start, int length)
          Callback interface for SAX (part of LexicalHandler interface): not for application use
abstract  void endDocument()
          Callback interface for SAX: not for application use
abstract  void endElement(int nameCode)
          Callback interface for SAX: not for application use
 void error(org.xml.sax.SAXParseException e)
          Callback interface for SAX: not for application use
 void fatalError(org.xml.sax.SAXParseException e)
          Callback interface for SAX: not for application use
 int getColumnNumber()
           
 DocumentInfo getCurrentDocument()
          Get the current document
 int getDocumentNumber()
          Get the sequence number for the document
 int getLineNumber()
           
 NamePool getNamePool()
          Get the namepool used for this document
 Sequencer getNodeSequencer()
          Get the sequencer used for allocating node numbers
 java.lang.String getPublicId()
           
 java.lang.String getSystemId()
           
 org.xml.sax.XMLReader getXMLReader()
          Get the SAX2 parser in use.
 boolean isTiming()
          Get timing option
abstract  void processingInstruction(java.lang.String name, java.lang.String remainder)
          Callback interface for SAX: not for application use
Note: because SAX1 does not deliver comment nodes, we get these in the form of a processing instruction with a null name.
protected  void reportError(org.xml.sax.SAXParseException e, boolean isFatal)
          Common routine for errors and fatal errors
 void setCharacterSet(CharacterSet charset)
          Set the CharacterSet to be used.
 void setDiscardCommentsAndPIs(boolean discard)
          Indicate whether comments and Processing Instructions should be discarded
 void setDocumentLocator(org.xml.sax.Locator locator)
          Callback interface for SAX: not for application use
 void setDocumentNumber(int seq)
          Set the sequence number for the document
 void setErrorHandler(org.xml.sax.ErrorHandler eh)
          Set the error handler to use.
 void setErrorOutput(java.io.Writer writer)
          Set output for error messages produced by the default error handler.
The default error handler does not throw an exception for parse errors or input I/O errors, rather it returns a result code and writes diagnostics to a user-specified output writer, which defaults to System.err
This call has no effect if setErrorHandler() has been called to supply a user-defined error handler
 void setEscaping(boolean escaping)
          Switch escaping on or off.
 void setLineNumbering(boolean onOrOff)
          Set line numbering on or off
 void setNamePool(NamePool pool)
          Set the namepool to be used for all names in the document
 void setNodeSequencer(Sequencer seq)
          Set the sequencer used for allocating node numbers
 void setOutputDetails(OutputDetails details)
          Set output details.
 void setParser(org.xml.sax.Parser parser)
          Set the SAX1-compliant parser to use.
 void setPreviewManager(PreviewManager pm)
          Set the PreviewManager to use
 void setStripAll()
          Request stripping of all whitespace text nodes.
 void setStripper(Stripper s)
          Set the Stripper to use
 void setSystemId(java.lang.String uri)
           
 void setTiming(boolean on)
          Set timing option on or off
abstract  void setUnparsedEntity(java.lang.String name, java.lang.String uri)
          Set the URI for an unparsed entity in the document.
 void setWriter(java.io.Writer writer)
          Methods to satisfy the Emitter interface
 void setXMLReader(org.xml.sax.XMLReader parser)
          Set the SAX2-compliant parser to use.
abstract  void startDocument()
          Callback interface for SAX: not for application use
abstract  void startElement(int nameCode, org.xml.sax.Attributes attributes, int[] namespaces, int nscount)
          Callback interface for SAX: not for application use
 void warning(org.xml.sax.SAXParseException e)
          Callback interface for SAX: not for application use
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STANDARD_TREE

public static final int STANDARD_TREE

TINY_TREE

public static final int TINY_TREE

estimatedLength

protected int estimatedLength

errorOutput

protected java.io.Writer errorOutput

stripper

protected Stripper stripper

previewManager

protected PreviewManager previewManager

discardComments

protected boolean discardComments

documentNumber

protected int documentNumber

nodeSequencer

protected Sequencer nodeSequencer

currentDocument

protected DocumentInfo currentDocument

parser

protected org.xml.sax.XMLReader parser

errorHandler

protected org.xml.sax.ErrorHandler errorHandler

locator

protected org.xml.sax.Locator locator

baseURI

protected java.lang.String baseURI

namePool

protected NamePool namePool

failed

protected boolean failed

started

protected boolean started

timing

protected boolean timing

inDTD

protected boolean inDTD

lineNumbering

protected boolean lineNumbering
Constructor Detail

Builder

public Builder()
create a Builder and initialise variables
Method Detail

setTiming

public void setTiming(boolean on)
Set timing option on or off

isTiming

public boolean isTiming()
Get timing option

setNamePool

public void setNamePool(NamePool pool)
Set the namepool to be used for all names in the document
Specified by:
setNamePool in interface Emitter

getNamePool

public NamePool getNamePool()
Get the namepool used for this document

setDocumentNumber

public void setDocumentNumber(int seq)
Set the sequence number for the document

getDocumentNumber

public int getDocumentNumber()
Get the sequence number for the document

setNodeSequencer

public void setNodeSequencer(Sequencer seq)
Set the sequencer used for allocating node numbers

getNodeSequencer

public Sequencer getNodeSequencer()
Get the sequencer used for allocating node numbers

setParser

public void setParser(org.xml.sax.Parser parser)
Set the SAX1-compliant parser to use. If no parser is specified, the parser is obtained from the ParserManager.properties file.
Parameters:
parser - The XML parser to use. This must be an instance of a class that implements the org.xml.sax.Parser interface.
See Also:
ParserManager

setXMLReader

public void setXMLReader(org.xml.sax.XMLReader parser)
Set the SAX2-compliant parser to use. If no parser is specified, the parser is obtained from the ParserManager.properties file.
Parameters:
parser - The XML parser to use. This must be an instance of a class that implements the org.xml.sax.XMLReader interface.
See Also:
ParserManager

getXMLReader

public org.xml.sax.XMLReader getXMLReader()
Get the SAX2 parser in use.

setLineNumbering

public void setLineNumbering(boolean onOrOff)
Set line numbering on or off

setStripper

public void setStripper(Stripper s)
Set the Stripper to use

setStripAll

public void setStripAll()
Request stripping of all whitespace text nodes. This is a simple shortcut to avoid allocating a separate Stripper object

setPreviewManager

public void setPreviewManager(PreviewManager pm)
Set the PreviewManager to use

setDiscardCommentsAndPIs

public void setDiscardCommentsAndPIs(boolean discard)
Indicate whether comments and Processing Instructions should be discarded

setErrorHandler

public void setErrorHandler(org.xml.sax.ErrorHandler eh)
Set the error handler to use. If none is specified, SAXON supplies its own, which writes error messages to the selected error output writer.
Parameters:
eh - The error handler to use. It must conform to the interface org.xml.sax.ErrorHandler

setErrorOutput

public void setErrorOutput(java.io.Writer writer)
Set output for error messages produced by the default error handler.
The default error handler does not throw an exception for parse errors or input I/O errors, rather it returns a result code and writes diagnostics to a user-specified output writer, which defaults to System.err
This call has no effect if setErrorHandler() has been called to supply a user-defined error handler
Parameters:
writer - The Writer to use for error messages

build

public DocumentInfo build(org.xml.sax.InputSource in)
                   throws org.xml.sax.SAXException
Build the tree from an input source. After building the tree, it can be walked as often as required using run(Document doc).
Parameters:
source - The InputSource to use. InputSource is a SAX-defined class that allows input from a URL, a byte stream, or a character stream. SAXON also provides a subclass, ExtendedInputSource, that allows input directly from a File.
Returns:
The DocumentInfo object that results from parsing the input.
Throws:
org.xml.sax.SAXException - if the input document could not be read or if it was not parsed correctly.

getCurrentDocument

public DocumentInfo getCurrentDocument()
Get the current document
Returns:
the document that has been most recently built using this builder

startDocument

public abstract void startDocument()
                            throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
startDocument in interface Emitter

endDocument

public abstract void endDocument()
                          throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
endDocument in interface Emitter

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Callback interface for SAX: not for application use
Specified by:
setDocumentLocator in interface Emitter

startElement

public abstract void startElement(int nameCode,
                                  org.xml.sax.Attributes attributes,
                                  int[] namespaces,
                                  int nscount)
                           throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
startElement in interface Emitter
Following copied from interface: com.icl.saxon.output.Emitter
Parameters:
namespaces - Array of namespace codes identifying the namespace prefix/uri pairs associated with this element
nscount - Number of significant entries within namespaces array

endElement

public abstract void endElement(int nameCode)
                         throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
endElement in interface Emitter

characters

public abstract void characters(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
characters in interface Emitter

processingInstruction

public abstract void processingInstruction(java.lang.String name,
                                           java.lang.String remainder)
                                    throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Note: because SAX1 does not deliver comment nodes, we get these in the form of a processing instruction with a null name. This requires a specially-adapted SAX driver.
Specified by:
processingInstruction in interface Emitter

comment

public abstract void comment(char[] ch,
                             int start,
                             int length)
                      throws org.xml.sax.SAXException
Callback interface for SAX (part of LexicalHandler interface): not for application use
Specified by:
comment in interface Emitter

warning

public void warning(org.xml.sax.SAXParseException e)
Callback interface for SAX: not for application use
Specified by:
warning in interface org.xml.sax.ErrorHandler

error

public void error(org.xml.sax.SAXParseException e)
           throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
error in interface org.xml.sax.ErrorHandler

fatalError

public void fatalError(org.xml.sax.SAXParseException e)
                throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
fatalError in interface org.xml.sax.ErrorHandler

reportError

protected void reportError(org.xml.sax.SAXParseException e,
                           boolean isFatal)
Common routine for errors and fatal errors

setUnparsedEntity

public abstract void setUnparsedEntity(java.lang.String name,
                                       java.lang.String uri)
Set the URI for an unparsed entity in the document. Abstract method to be implemented in each subclass.
Specified by:
setUnparsedEntity in interface Emitter

setWriter

public void setWriter(java.io.Writer writer)
               throws org.xml.sax.SAXException
Methods to satisfy the Emitter interface
Specified by:
setWriter in interface Emitter

setCharacterSet

public void setCharacterSet(CharacterSet charset)
                     throws org.xml.sax.SAXException
Description copied from interface: Emitter
Set the CharacterSet to be used. The CharacterSet is a property of the encoding, it defines which characters are available in the output encoding. If no character set is supplied, the UnicodeCharacterSet should be assumed. It is the job of the emitter to provide a fallback representation of characters that the Writer cannot handle.
Specified by:
setCharacterSet in interface Emitter

setEscaping

public void setEscaping(boolean escaping)
                 throws org.xml.sax.SAXException
Description copied from interface: Emitter
Switch escaping on or off. This is called when the XSLT disable-output-escaping attribute is used to switch escaping on or off. It is also called at the start and end of a CDATA section It is not called for other sections of output (e.g. comments) where escaping is inappropriate.
Specified by:
setEscaping in interface Emitter

setOutputDetails

public void setOutputDetails(OutputDetails details)
                      throws org.xml.sax.SAXException
Description copied from interface: Emitter
Set output details. This supplies all the current output details to the emitter. Most of these are derived directly from the xsl:output or saxon:output element in the stylesheet.
Specified by:
setOutputDetails in interface Emitter
Following copied from interface: com.icl.saxon.output.Emitter
Parameters:
details - The details of the required output

setSystemId

public void setSystemId(java.lang.String uri)

getSystemId

public java.lang.String getSystemId()
Specified by:
getSystemId in interface org.xml.sax.Locator

getPublicId

public java.lang.String getPublicId()
Specified by:
getPublicId in interface org.xml.sax.Locator

getLineNumber

public int getLineNumber()
Specified by:
getLineNumber in interface org.xml.sax.Locator

getColumnNumber

public int getColumnNumber()
Specified by:
getColumnNumber in interface org.xml.sax.Locator