com.icl.saxon.tree
Class Builder

java.lang.Object
  |
  +--com.icl.saxon.tree.Builder
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.ErrorHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.Locator

public class Builder
extends java.lang.Object
implements org.xml.sax.ContentHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.ErrorHandler, org.xml.sax.DTDHandler, org.xml.sax.Locator

The Builder class is responsible for taking a stream of SAX events and constructing a Document tree.


Field Summary
protected  boolean failed
           
 
Constructor Summary
Builder()
          create a Builder and initialise variables
 
Method Summary
 DocumentImpl build(org.xml.sax.InputSource in)
          Build the tree from an input source.
 void characters(char[] ch, int start, int length)
          Callback interface for SAX: not for application use
 void comment(char[] ch, int start, int length)
          Callback interface for SAX (part of LexicalHandler interface): not for application use
 void endCDATA()
           
 void endDocument()
          Callback interface for SAX: not for application use
 void endDTD()
           
 void endElement(java.lang.String uri, java.lang.String localname, java.lang.String rawname)
          Callback interface for SAX: not for application use
 void endEntity(java.lang.String name)
           
 void endPrefixMapping(java.lang.String prefix)
           
 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()
           
 DocumentImpl getCurrentDocument()
          Get the current document
 int getLineNumber()
           
 java.lang.String getPublicId()
           
 java.lang.String getSystemId()
           
 org.xml.sax.XMLReader getXMLReader()
          Get the SAX2 parser in use.
 void graftElement(ElementImpl element)
          graftElement() allows an element node to be transferred from one tree to another.
 void ignorableWhitespace(char[] ch, int start, int length)
          Callback interface for SAX: not for application use
 void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
           
 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.
 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 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 setLineNumbering(boolean onOrOff)
          Set line numbering on or off
 void setNodeFactory(NodeFactory factory)
          Set the Node Factory to use.
 void setParser(org.xml.sax.Parser parser)
          Set the SAX-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 setXMLReader(org.xml.sax.XMLReader parser)
          Set the SAX2-compliant parser to use.
 void skippedEntity(java.lang.String name)
           
 void startCDATA()
           
 void startDocument()
          Callback interface for SAX: not for application use
 void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
           
 void startElement(java.lang.String uri, java.lang.String localname, java.lang.String rawname, org.xml.sax.Attributes attributes)
          Callback interface for SAX: not for application use
 void startEntity(java.lang.String name)
           
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
           
 void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
           
 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

failed

protected boolean failed
Constructor Detail

Builder

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

setParser

public void setParser(org.xml.sax.Parser parser)
Set the SAX-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

setNodeFactory

public void setNodeFactory(NodeFactory factory)
Set the Node Factory to use. If none is specified, the Builder uses its own.

build

public DocumentImpl 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 DocumentImpl getCurrentDocument()
Get the current document
Returns:
the document that has been most recently built using this builder

startDocument

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

endDocument

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

setDocumentLocator

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

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localname,
                         java.lang.String rawname,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
startElement in interface org.xml.sax.ContentHandler

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localname,
                       java.lang.String rawname)
                throws org.xml.sax.SAXException
Callback interface for SAX: not for application use
Specified by:
endElement in interface org.xml.sax.ContentHandler

characters

public 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 org.xml.sax.ContentHandler

ignorableWhitespace

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

processingInstruction

public 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. This requires a specially-adapted SAX driver.
Specified by:
processingInstruction in interface org.xml.sax.ContentHandler

comment

public 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 org.xml.sax.ext.LexicalHandler

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
Specified by:
skippedEntity in interface org.xml.sax.ContentHandler

startDTD

public void startDTD(java.lang.String name,
                     java.lang.String publicId,
                     java.lang.String systemId)
              throws org.xml.sax.SAXException
Specified by:
startDTD in interface org.xml.sax.ext.LexicalHandler

endDTD

public void endDTD()
            throws org.xml.sax.SAXException
Specified by:
endDTD in interface org.xml.sax.ext.LexicalHandler

startEntity

public void startEntity(java.lang.String name)
                 throws org.xml.sax.SAXException
Specified by:
startEntity in interface org.xml.sax.ext.LexicalHandler

endEntity

public void endEntity(java.lang.String name)
               throws org.xml.sax.SAXException
Specified by:
endEntity in interface org.xml.sax.ext.LexicalHandler

startCDATA

public void startCDATA()
                throws org.xml.sax.SAXException
Specified by:
startCDATA in interface org.xml.sax.ext.LexicalHandler

endCDATA

public void endCDATA()
              throws org.xml.sax.SAXException
Specified by:
endCDATA in interface org.xml.sax.ext.LexicalHandler

graftElement

public void graftElement(ElementImpl element)
                  throws org.xml.sax.SAXException
graftElement() allows an element node to be transferred from one tree to another. This is a dangerous internal interface which is used only to contruct a stylesheet tree from a stylesheet using the "literal result element as stylesheet" syntax. The supplied element is grafted onto the current element as its only child.

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

notationDecl

public void notationDecl(java.lang.String name,
                         java.lang.String publicId,
                         java.lang.String systemId)
                  throws org.xml.sax.SAXException
Specified by:
notationDecl in interface org.xml.sax.DTDHandler

unparsedEntityDecl

public void unparsedEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId,
                               java.lang.String notationName)
                        throws org.xml.sax.SAXException
Specified by:
unparsedEntityDecl in interface org.xml.sax.DTDHandler

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