org.apache.batik.dom.util
Class SAXDocumentFactory

java.lang.Object
  |
  +--org.xml.sax.helpers.DefaultHandler
        |
        +--org.apache.batik.dom.util.SAXDocumentFactory
All Implemented Interfaces:
ContentHandler, DocumentFactory, DTDHandler, EntityResolver, ErrorHandler, LexicalHandler
Direct Known Subclasses:
SAXSVGDocumentFactory

public class SAXDocumentFactory
extends DefaultHandler
implements LexicalHandler, DocumentFactory

This class contains methods for creating Document instances from an URI using SAX2.


Field Summary
protected  boolean createDocumentDescriptor
          Whether a document descriptor must be generated.
protected  Node currentNode
          The current node.
protected  Document document
          The created document.
protected  DocumentDescriptor documentDescriptor
          The created document descriptor.
protected  ErrorHandler errorHandler
          The error handler.
protected  DOMImplementation implementation
          The DOM implementation used to create the document.
protected  boolean inCDATA
          Whether the parser currently parses a CDATA section.
protected  boolean inDTD
          Whether the parser currently parses a DTD.
protected  boolean isValidating
          Whether the parser is in validating mode.
protected  Locator locator
          The locator.
protected  HashTableStack namespaces
          The stack used to store the namespace URIs.
protected  java.lang.String parserClassName
          The SAX2 parser classname.
protected  java.util.List preInfo
          Various elements encountered prior to real document root element.
 
Constructor Summary
SAXDocumentFactory(DOMImplementation impl, java.lang.String parser)
          Creates a new SAXDocumentFactory object.
SAXDocumentFactory(DOMImplementation impl, java.lang.String parser, boolean dd)
          Creates a new SAXDocumentFactory object.
 
Method Summary
 void characters(char[] ch, int start, int length)
          SAX: Implements ContentHandler.characters(char[],int,int).
 void comment(char[] ch, int start, int length)
          SAX: Implements LexicalHandler.comment(char[],int,int).
protected  Document createDocument(InputSource is)
          Creates a Document.
 Document createDocument(java.lang.String uri)
          Creates a Document instance.
 Document createDocument(java.lang.String uri, java.io.InputStream is)
          Creates a Document instance.
 Document createDocument(java.lang.String uri, java.io.Reader r)
          Creates a Document instance.
 Document createDocument(java.lang.String ns, java.lang.String root, java.lang.String uri)
          Creates a Document instance.
protected  Document createDocument(java.lang.String ns, java.lang.String root, java.lang.String uri, InputSource is)
          Creates a Document.
 Document createDocument(java.lang.String ns, java.lang.String root, java.lang.String uri, java.io.InputStream is)
          Creates a Document instance.
 Document createDocument(java.lang.String ns, java.lang.String root, java.lang.String uri, java.io.Reader r)
          Creates a Document instance.
 void endCDATA()
          SAX: Implements LexicalHandler.endCDATA().
 void endDTD()
          SAX: Implements LexicalHandler.endDTD().
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String rawName)
          SAX: Implements ContentHandler.endElement(String,String,String).
 void endEntity(java.lang.String name)
          SAX: Implements LexicalHandler.endEntity(String).
 void error(SAXParseException ex)
          SAX: Implements ErrorHandler.error(SAXParseException).
 void fatalError(SAXParseException ex)
          SAX: Implements ErrorHandler.fatalError(SAXParseException).
 DocumentDescriptor getDocumentDescriptor()
          Returns the document descriptor associated with the latest created document.
 boolean isValidating()
          Returns true if the XML parser validates the XML stream, false otherwise.
 void processingInstruction(java.lang.String target, java.lang.String data)
          SAX: Implements ContentHandler.processingInstruction(String,String).
 void setDocumentLocator(Locator l)
          SAX: Implements ContentHandler.setDocumentLocator(Locator).
 void setErrorHandler(ErrorHandler eh)
          Sets a custom error handler.
 void setValidating(boolean isValidating)
          Sets whether or not the XML parser will validate the XML document depending on the specified parameter.
 void startCDATA()
          SAX: Implements LexicalHandler.startCDATA().
 void startDocument()
          SAX: Implements ContentHandler.startDocument().
 void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          SAX: Implements LexicalHandler.startDTD(String,String,String).
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String rawName, Attributes attributes)
          SAX: Implements ContentHandler.startElement(String,String,String,Attributes).
 void startEntity(java.lang.String name)
          SAX: Implements LexicalHandler.startEntity(String).
 void warning(SAXParseException ex)
          SAX: Implements ErrorHandler.warning(SAXParseException).
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, ignorableWhitespace, notationDecl, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

implementation

protected DOMImplementation implementation
The DOM implementation used to create the document.

parserClassName

protected java.lang.String parserClassName
The SAX2 parser classname.

document

protected Document document
The created document.

documentDescriptor

protected DocumentDescriptor documentDescriptor
The created document descriptor.

createDocumentDescriptor

protected boolean createDocumentDescriptor
Whether a document descriptor must be generated.

currentNode

protected Node currentNode
The current node.

locator

protected Locator locator
The locator.

inCDATA

protected boolean inCDATA
Whether the parser currently parses a CDATA section.

inDTD

protected boolean inDTD
Whether the parser currently parses a DTD.

isValidating

protected boolean isValidating
Whether the parser is in validating mode.

namespaces

protected HashTableStack namespaces
The stack used to store the namespace URIs.

errorHandler

protected ErrorHandler errorHandler
The error handler.

preInfo

protected java.util.List preInfo
Various elements encountered prior to real document root element. List of PreInfo objects.
Constructor Detail

SAXDocumentFactory

public SAXDocumentFactory(DOMImplementation impl,
                          java.lang.String parser)
Creates a new SAXDocumentFactory object. No document descriptor will be created while generating a document.
Parameters:
impl - The DOM implementation to use for building the DOM tree.
parser - The SAX2 parser classname.

SAXDocumentFactory

public SAXDocumentFactory(DOMImplementation impl,
                          java.lang.String parser,
                          boolean dd)
Creates a new SAXDocumentFactory object.
Parameters:
impl - The DOM implementation to use for building the DOM tree.
parser - The SAX2 parser classname.
dd - Whether a document descriptor must be generated.
Method Detail

createDocument

public Document createDocument(java.lang.String ns,
                               java.lang.String root,
                               java.lang.String uri)
                        throws java.io.IOException
Creates a Document instance.
Specified by:
createDocument in interface DocumentFactory
Parameters:
ns - The namespace URI of the root element of the document.
root - The name of the root element of the document.
uri - The document URI.
Throws:
java.io.IOException - if an error occured while reading the document.

createDocument

public Document createDocument(java.lang.String uri)
                        throws java.io.IOException
Creates a Document instance.
Parameters:
uri - The document URI.
Throws:
java.io.IOException - if an error occured while reading the document.

createDocument

public Document createDocument(java.lang.String ns,
                               java.lang.String root,
                               java.lang.String uri,
                               java.io.InputStream is)
                        throws java.io.IOException
Creates a Document instance.
Specified by:
createDocument in interface DocumentFactory
Parameters:
ns - The namespace URI of the root element of the document.
root - The name of the root element of the document.
uri - The document URI.
is - The document input stream.
Throws:
java.io.IOException - if an error occured while reading the document.

createDocument

public Document createDocument(java.lang.String uri,
                               java.io.InputStream is)
                        throws java.io.IOException
Creates a Document instance.
Parameters:
uri - The document URI.
is - The document input stream.
Throws:
java.io.IOException - if an error occured while reading the document.

createDocument

public Document createDocument(java.lang.String ns,
                               java.lang.String root,
                               java.lang.String uri,
                               java.io.Reader r)
                        throws java.io.IOException
Creates a Document instance.
Specified by:
createDocument in interface DocumentFactory
Parameters:
ns - The namespace URI of the root element of the document.
root - The name of the root element of the document.
uri - The document URI.
r - The document reader.
Throws:
java.io.IOException - if an error occured while reading the document.

createDocument

public Document createDocument(java.lang.String uri,
                               java.io.Reader r)
                        throws java.io.IOException
Creates a Document instance.
Parameters:
uri - The document URI.
r - The document reader.
Throws:
java.io.IOException - if an error occured while reading the document.

createDocument

protected Document createDocument(java.lang.String ns,
                                  java.lang.String root,
                                  java.lang.String uri,
                                  InputSource is)
                           throws java.io.IOException
Creates a Document.
Parameters:
ns - The namespace URI of the root element.
root - The name of the root element.
uri - The document URI.
is - The document input source.
Throws:
java.io.IOException - if an error occured while reading the document.

createDocument

protected Document createDocument(InputSource is)
                           throws java.io.IOException
Creates a Document.
Parameters:
ns - The namespace URI of the root element.
root - The name of the root element.
uri - The document URI.
is - The document input source.
Throws:
java.io.IOException - if an error occured while reading the document.

getDocumentDescriptor

public DocumentDescriptor getDocumentDescriptor()
Returns the document descriptor associated with the latest created document.
Specified by:
getDocumentDescriptor in interface DocumentFactory
Returns:
null if no document or descriptor was previously generated.

setDocumentLocator

public void setDocumentLocator(Locator l)
SAX: Implements ContentHandler.setDocumentLocator(Locator).
Overrides:
setDocumentLocator in class DefaultHandler
Following copied from class: org.xml.sax.helpers.DefaultHandler
Parameters:
locator - A locator for all SAX document events.
See Also:
ContentHandler.setDocumentLocator(org.xml.sax.Locator), Locator

setValidating

public void setValidating(boolean isValidating)
Sets whether or not the XML parser will validate the XML document depending on the specified parameter.
Specified by:
setValidating in interface DocumentFactory
Parameters:
isValidating - indicates that the XML parser will validate the XML document

isValidating

public boolean isValidating()
Returns true if the XML parser validates the XML stream, false otherwise.
Specified by:
isValidating in interface DocumentFactory

setErrorHandler

public void setErrorHandler(ErrorHandler eh)
Sets a custom error handler.

startDocument

public void startDocument()
                   throws SAXException
SAX: Implements ContentHandler.startDocument().
Overrides:
startDocument in class DefaultHandler
Following copied from class: org.xml.sax.helpers.DefaultHandler
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.startDocument()

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String rawName,
                         Attributes attributes)
                  throws SAXException
SAX: Implements ContentHandler.startElement(String,String,String,Attributes).
Overrides:
startElement in class DefaultHandler
Following copied from class: org.xml.sax.helpers.DefaultHandler
Parameters:
name - The element type name.
attributes - The specified or defaulted attributes.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

fatalError

public void fatalError(SAXParseException ex)
                throws SAXException
SAX: Implements ErrorHandler.fatalError(SAXParseException).
Overrides:
fatalError in class DefaultHandler
Following copied from class: org.xml.sax.helpers.DefaultHandler
Parameters:
e - The error information encoded as an exception.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ErrorHandler.fatalError(org.xml.sax.SAXParseException), SAXParseException

error

public void error(SAXParseException ex)
           throws SAXException
SAX: Implements ErrorHandler.error(SAXParseException).
Overrides:
error in class DefaultHandler
Following copied from class: org.xml.sax.helpers.DefaultHandler
Parameters:
e - The warning information encoded as an exception.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ErrorHandler.warning(org.xml.sax.SAXParseException), SAXParseException

warning

public void warning(SAXParseException ex)
             throws SAXException
SAX: Implements ErrorHandler.warning(SAXParseException).
Overrides:
warning in class DefaultHandler
Following copied from class: org.xml.sax.helpers.DefaultHandler
Parameters:
e - The warning information encoded as an exception.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ErrorHandler.warning(org.xml.sax.SAXParseException), SAXParseException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String rawName)
                throws SAXException
SAX: Implements ContentHandler.endElement(String,String,String).
Overrides:
endElement in class DefaultHandler
Following copied from class: org.xml.sax.helpers.DefaultHandler
Parameters:
name - The element type name.
attributes - The specified or defaulted attributes.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
SAX: Implements ContentHandler.characters(char[],int,int).
Overrides:
characters in class DefaultHandler
Following copied from class: org.xml.sax.helpers.DefaultHandler
Parameters:
ch - The characters.
start - The start position in the character array.
length - The number of characters to use from the character array.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.characters(char[], int, int)

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws SAXException
SAX: Implements ContentHandler.processingInstruction(String,String).
Overrides:
processingInstruction in class DefaultHandler
Following copied from class: org.xml.sax.helpers.DefaultHandler
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none is supplied.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ContentHandler.processingInstruction(java.lang.String, java.lang.String)

startDTD

public void startDTD(java.lang.String name,
                     java.lang.String publicId,
                     java.lang.String systemId)
              throws SAXException
SAX: Implements LexicalHandler.startDTD(String,String,String).
Specified by:
startDTD in interface LexicalHandler
Following copied from interface: org.xml.sax.ext.LexicalHandler
Parameters:
name - The document type name.
publicId - The declared public identifier for the external DTD subset, or null if none was declared.
systemId - The declared system identifier for the external DTD subset, or null if none was declared.
Throws:
SAXException - The application may raise an exception.
See Also:
LexicalHandler.endDTD(), LexicalHandler.startEntity(java.lang.String)

endDTD

public void endDTD()
            throws SAXException
SAX: Implements LexicalHandler.endDTD().
Specified by:
endDTD in interface LexicalHandler
Following copied from interface: org.xml.sax.ext.LexicalHandler
Throws:
SAXException - The application may raise an exception.
See Also:
LexicalHandler.startDTD(java.lang.String, java.lang.String, java.lang.String)

startEntity

public void startEntity(java.lang.String name)
                 throws SAXException
SAX: Implements LexicalHandler.startEntity(String).
Specified by:
startEntity in interface LexicalHandler
Following copied from interface: org.xml.sax.ext.LexicalHandler
Parameters:
name - The name of the entity. If it is a parameter entity, the name will begin with '%'.
Throws:
SAXException - The application may raise an exception.
See Also:
LexicalHandler.endEntity(java.lang.String), DeclHandler.internalEntityDecl(java.lang.String, java.lang.String), DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)

endEntity

public void endEntity(java.lang.String name)
               throws SAXException
SAX: Implements LexicalHandler.endEntity(String).
Specified by:
endEntity in interface LexicalHandler
Following copied from interface: org.xml.sax.ext.LexicalHandler
Parameters:
name - The name of the entity that is ending.
Throws:
SAXException - The application may raise an exception.
See Also:
LexicalHandler.startEntity(java.lang.String)

startCDATA

public void startCDATA()
                throws SAXException
SAX: Implements LexicalHandler.startCDATA().
Specified by:
startCDATA in interface LexicalHandler
Following copied from interface: org.xml.sax.ext.LexicalHandler
Throws:
SAXException - The application may raise an exception.
See Also:
LexicalHandler.endCDATA()

endCDATA

public void endCDATA()
              throws SAXException
SAX: Implements LexicalHandler.endCDATA().
Specified by:
endCDATA in interface LexicalHandler
Following copied from interface: org.xml.sax.ext.LexicalHandler
Throws:
SAXException - The application may raise an exception.
See Also:
LexicalHandler.startCDATA()

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
SAX: Implements LexicalHandler.comment(char[],int,int).
Specified by:
comment in interface LexicalHandler
Following copied from interface: org.xml.sax.ext.LexicalHandler
Parameters:
ch - An array holding the characters in the comment.
start - The starting position in the array.
length - The number of characters to use from the array.
Throws:
SAXException - The application may raise an exception.


Copyright © 2002 Apache Software Foundation. All Rights Reserved.