## org.apache.batik.dom.util
Class SAXDocumentFactory

    java.lang.Object
      org.xml.sax.helpers.DefaultHandler
          org.apache.batik.dom.util.SAXDocumentFactory

All Implemented Interfaces:
  org.xml.sax.ContentHandler, DocumentFactory, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.ext.LexicalHandler

Direct Known Subclasses:
  SAXSVGDocumentFactory

public class SAXDocumentFactory
extends org.xml.sax.helpers.DefaultHandler
implements org.xml.sax.ext.LexicalHandler, DocumentFactory

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

Nested Class Summary
`protected static interface` `SAXDocumentFactory.PreInfo`

Field Summary
`protected java.lang.StringBuffer` `cdataBuffer` Whether the parser currently parses a CDATA section.
`protected boolean` `createDocumentDescriptor` Whether a document descriptor must be generated.
`protected org.w3c.dom.Node` `currentNode` The current node.
`protected org.w3c.dom.Document` `document` The created document.
`protected DocumentDescriptor` `documentDescriptor` The created document descriptor.
`protected org.xml.sax.ErrorHandler` `errorHandler` The error handler.
`protected org.w3c.dom.DOMImplementation` `implementation` The DOM implementation used to create the document.
`protected boolean` `inDTD` Whether the parser currently parses a DTD.
`protected boolean` `isValidating` Whether the parser is in validating mode.
`protected org.xml.sax.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(org.w3c.dom.DOMImplementation impl, java.lang.String parser)` Creates a new SAXDocumentFactory object.
`SAXDocumentFactory(org.w3c.dom.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 org.w3c.dom.Document` `createDocument(org.xml.sax.InputSource is)` Creates a Document.
`org.w3c.dom.Document` `createDocument(java.lang.String uri)` Creates a Document instance.
`org.w3c.dom.Document` `createDocument(java.lang.String uri, java.io.InputStream is)` Creates a Document instance.
`org.w3c.dom.Document` `createDocument(java.lang.String uri, java.io.Reader r)` Creates a Document instance.
`org.w3c.dom.Document` `createDocument(java.lang.String ns, java.lang.String root, java.lang.String uri)` Creates a Document instance.
`protected org.w3c.dom.Document` `createDocument(java.lang.String ns, java.lang.String root, java.lang.String uri, org.xml.sax.InputSource is)` Creates a Document.
`org.w3c.dom.Document` `createDocument(java.lang.String ns, java.lang.String root, java.lang.String uri, java.io.InputStream is)` Creates a Document instance.
`org.w3c.dom.Document` `createDocument(java.lang.String ns, java.lang.String root, java.lang.String uri, java.io.Reader r)` Creates a Document instance.
`org.w3c.dom.Document` `createDocument(java.lang.String ns, java.lang.String root, java.lang.String uri, org.xml.sax.XMLReader 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(org.xml.sax.SAXParseException ex)` SAX: Implements `ErrorHandler.error(SAXParseException)`.
`void` `fatalError(org.xml.sax.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(org.xml.sax.Locator l)` SAX: Implements `ContentHandler.setDocumentLocator(Locator)`.
`void` `setErrorHandler(org.xml.sax.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, org.xml.sax.Attributes attributes)` SAX: Implements `ContentHandler#startElement(String,String,String,Attributes)`.
`void` `startEntity(java.lang.String name)` SAX: Implements `LexicalHandler.startEntity(String)`.
`void` `warning(org.xml.sax.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 org.w3c.dom.DOMImplementation implementation

  The DOM implementation used to create the document.

### parserClassName

    protected java.lang.String parserClassName

  The SAX2 parser classname.

### document

    protected org.w3c.dom.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 org.w3c.dom.Node currentNode

  The current node.

### locator

    protected org.xml.sax.Locator locator

  The locator.

### cdataBuffer

    protected java.lang.StringBuffer cdataBuffer

  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 org.xml.sax.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(org.w3c.dom.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(org.w3c.dom.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 org.w3c.dom.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 org.w3c.dom.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 org.w3c.dom.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 org.w3c.dom.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 org.w3c.dom.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 org.w3c.dom.Document createDocument(java.lang.String ns,
                                               java.lang.String root,
                                               java.lang.String uri,
                                               org.xml.sax.XMLReader 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` - an XMLReaderInstance
  Throws:
    `java.io.IOException` - if an error occured while reading the document.

### createDocument

    public org.w3c.dom.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 org.w3c.dom.Document createDocument(java.lang.String ns,
                                                  java.lang.String root,
                                                  java.lang.String uri,
                                                  org.xml.sax.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 org.w3c.dom.Document createDocument(org.xml.sax.InputSource is)
                                           throws java.io.IOException

  Creates a Document.

  Parameters:
    `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(org.xml.sax.Locator l)

  SAX: Implements `ContentHandler.setDocumentLocator(Locator)`.

  Specified by:
    `setDocumentLocator` in interface `org.xml.sax.ContentHandler`

### 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(org.xml.sax.ErrorHandler eh)

  Sets a custom error handler.

### startDocument

    public void startDocument()
                       throws org.xml.sax.SAXException

  SAX: Implements `ContentHandler.startDocument()`.

  Specified by:
    `startDocument` in interface `org.xml.sax.ContentHandler`
  Throws:
    `org.xml.sax.SAXException`

### 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

  SAX: Implements `ContentHandler#startElement(String,String,String,Attributes)`.

  Specified by:
    `startElement` in interface `org.xml.sax.ContentHandler`
  Throws:
    `org.xml.sax.SAXException`

### fatalError

    public void fatalError(org.xml.sax.SAXParseException ex)
                    throws org.xml.sax.SAXException

  SAX: Implements `ErrorHandler.fatalError(SAXParseException)`.

  Specified by:
    `fatalError` in interface `org.xml.sax.ErrorHandler`
  Throws:
    `org.xml.sax.SAXException`

### error

    public void error(org.xml.sax.SAXParseException ex)
               throws org.xml.sax.SAXException

  SAX: Implements `ErrorHandler.error(SAXParseException)`.

  Specified by:
    `error` in interface `org.xml.sax.ErrorHandler`
  Throws:
    `org.xml.sax.SAXException`

### warning

    public void warning(org.xml.sax.SAXParseException ex)
                 throws org.xml.sax.SAXException

  SAX: Implements `ErrorHandler.warning(SAXParseException)`.

  Specified by:
    `warning` in interface `org.xml.sax.ErrorHandler`
  Throws:
    `org.xml.sax.SAXException`

### endElement

    public void endElement(java.lang.String uri,
                           java.lang.String localName,
                           java.lang.String rawName)
                    throws org.xml.sax.SAXException

  SAX: Implements `ContentHandler.endElement(String,String,String)`.

  Specified by:
    `endElement` in interface `org.xml.sax.ContentHandler`
  Throws:
    `org.xml.sax.SAXException`

### characters

    public void characters(char[] ch,
                           int start,
                           int length)
                    throws org.xml.sax.SAXException

  SAX: Implements `ContentHandler.characters(char[],int,int)`.

  Specified by:
    `characters` in interface `org.xml.sax.ContentHandler`
  Throws:
    `org.xml.sax.SAXException`

### processingInstruction

    public void processingInstruction(java.lang.String target,
                                      java.lang.String data)
                               throws org.xml.sax.SAXException

  SAX: Implements `ContentHandler.processingInstruction(String,String)`.

  Specified by:
    `processingInstruction` in interface `org.xml.sax.ContentHandler`
  Throws:
    `org.xml.sax.SAXException`

### startDTD

    public void startDTD(java.lang.String name,
                         java.lang.String publicId,
                         java.lang.String systemId)
                  throws org.xml.sax.SAXException

  SAX: Implements `LexicalHandler.startDTD(String,String,String)`.

  Specified by:
    `startDTD` in interface `org.xml.sax.ext.LexicalHandler`
  Throws:
    `org.xml.sax.SAXException`

### endDTD

    public void endDTD()
                throws org.xml.sax.SAXException

  SAX: Implements `LexicalHandler.endDTD()`.

  Specified by:
    `endDTD` in interface `org.xml.sax.ext.LexicalHandler`
  Throws:
    `org.xml.sax.SAXException`

### startEntity

    public void startEntity(java.lang.String name)
                     throws org.xml.sax.SAXException

  SAX: Implements `LexicalHandler.startEntity(String)`.

  Specified by:
    `startEntity` in interface `org.xml.sax.ext.LexicalHandler`
  Throws:
    `org.xml.sax.SAXException`

### endEntity

    public void endEntity(java.lang.String name)
                   throws org.xml.sax.SAXException

  SAX: Implements `LexicalHandler.endEntity(String)`.

  Specified by:
    `endEntity` in interface `org.xml.sax.ext.LexicalHandler`
  Throws:
    `org.xml.sax.SAXException`

### startCDATA

    public void startCDATA()
                    throws org.xml.sax.SAXException

  SAX: Implements `LexicalHandler.startCDATA()`.

  Specified by:
    `startCDATA` in interface `org.xml.sax.ext.LexicalHandler`
  Throws:
    `org.xml.sax.SAXException`

### endCDATA

    public void endCDATA()
                  throws org.xml.sax.SAXException

  SAX: Implements `LexicalHandler.endCDATA()`.

  Specified by:
    `endCDATA` in interface `org.xml.sax.ext.LexicalHandler`
  Throws:
    `org.xml.sax.SAXException`

### comment

    public void comment(char[] ch,
                        int start,
                        int length)
                 throws org.xml.sax.SAXException

  SAX: Implements `LexicalHandler.comment(char[],int,int)`.

  Specified by:
    `comment` in interface `org.xml.sax.ext.LexicalHandler`
  Throws:
    `org.xml.sax.SAXException`

Copyright © 2004 Apache Software Foundation. All Rights Reserved.