org.apache.xml.dtm.ref.sax2dtm
public class SAX2DTM extends DTMDefaultBaseIterators implements EntityResolver, DTDHandler, ContentHandler, ErrorHandler, DeclHandler, LexicalHandler
Constructor Summary | |
---|---|
SAX2DTM(DTMManager mgr, Source source, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing)
Construct a SAX2DTM object using the default block size.
| |
SAX2DTM(DTMManager mgr, Source source, int dtmIdentity, DTMWSFilter whiteSpaceFilter, XMLStringFactory xstringfactory, boolean doIndexing, int blocksize, boolean usePrevsib, boolean newNameTable)
Construct a SAX2DTM object ready to be constructed from SAX2
ContentHandler events.
|
Method Summary | |
---|---|
void | attributeDecl(String eName, String aName, String type, String valueDefault, String value)
Report an attribute type declaration.
|
void | characters(char[] ch, int start, int length)
Receive notification of character data inside an element.
|
void | clearCoRoutine()
Ask the CoRoutine parser to doTerminate and clear the reference. |
void | clearCoRoutine(boolean callDoTerminate)
Ask the CoRoutine parser to doTerminate and clear the reference. |
void | comment(char[] ch, int start, int length)
Report an XML comment anywhere in the document.
|
void | dispatchCharactersEvents(int nodeHandle, ContentHandler ch, boolean normalize)
Directly call the
characters method on the passed ContentHandler for the
string-value of the given node (see http://www.w3.org/TR/xpath#data-model
for the definition of a node's string-value). |
void | dispatchToEvents(int nodeHandle, ContentHandler ch)
Directly create SAX parser events from a subtree.
|
void | elementDecl(String name, String model)
Report an element type declaration.
|
void | endCDATA()
Report the end of a CDATA section.
|
void | endDocument()
Receive notification of the end of the document.
|
void | endDTD()
Report the end of DTD declarations.
|
void | endElement(String uri, String localName, String qName)
Receive notification of the end of an element.
|
void | endEntity(String name)
Report the end of an entity.
|
void | endPrefixMapping(String prefix)
Receive notification of the end of a Namespace mapping.
|
void | error(SAXParseException e)
Receive notification of a recoverable parser error.
|
void | externalEntityDecl(String name, String publicId, String systemId)
Report a parsed external entity declaration.
|
void | fatalError(SAXParseException e)
Report a fatal XML parsing error.
|
int | getAttributeNode(int nodeHandle, String namespaceURI, String name)
Retrieves an attribute node by by qualified name and namespace URI.
|
ContentHandler | getContentHandler()
getContentHandler returns "our SAX builder" -- the thing that
someone else should send SAX events to in order to extend this
DTM model.
|
DeclHandler | getDeclHandler()
Return this DTM's DeclHandler.
|
String | getDocumentTypeDeclarationPublicIdentifier()
Return the public identifier of the external subset,
normalized as described in 4.2.2 External Entities [XML]. |
String | getDocumentTypeDeclarationSystemIdentifier()
A document type declaration information item has the following properties:
1. [system identifier] The system identifier of the external subset, if
it exists. |
DTDHandler | getDTDHandler()
Return this DTM's DTDHandler.
|
int | getElementById(String elementId)
Returns the Element whose ID is given by
elementId . |
EntityResolver | getEntityResolver()
Return this DTM's EntityResolver.
|
ErrorHandler | getErrorHandler()
Return this DTM's ErrorHandler.
|
String | getFixedNames(int type) |
int | getIdForNamespace(String uri)
Get a prefix either from the uri mapping, or just make
one up!
|
LexicalHandler | getLexicalHandler()
Return this DTM's lexical handler.
|
String | getLocalName(int nodeHandle)
Given a node handle, return its XPath-style localname.
|
String | getNamespaceURI(int nodeHandle)
Given a node handle, return its DOM-style namespace URI
(As defined in Namespaces, this is the declared URI which this node's
prefix -- or default in lieu thereof -- was mapped to.)
|
String | getNamespaceURI(String prefix)
Get a prefix either from the qname or from the uri mapping, or just make
one up!
|
String | getNodeName(int nodeHandle)
Given a node handle, return its DOM-style node name. |
String | getNodeNameX(int nodeHandle)
Given a node handle, return the XPath node name. |
String | getNodeValue(int nodeHandle)
Given a node handle, return its node value. |
int | getNumberOfNodes()
Get the number of nodes that have been added.
|
String | getPrefix(int nodeHandle)
Given a namespace handle, return the prefix that the namespace decl is
mapping.
|
String | getPrefix(String qname, String uri)
Get a prefix either from the qname or from the uri mapping, or just make
one up!
|
SourceLocator | getSourceLocatorFor(int node) Retrieve the SourceLocator associated with a specific node.
|
XMLString | getStringValue(int nodeHandle)
Get the string-value of a node as a String object
(see http://www.w3.org/TR/xpath#data-model
for the definition of a node's string-value).
|
String | getUnparsedEntityURI(String name)
The getUnparsedEntityURI function returns the URI of the unparsed
entity with the specified name in the same document as the context
node (see [3.3 Unparsed Entities]). |
void | ignorableWhitespace(char[] ch, int start, int length)
Receive notification of ignorable whitespace in element content.
|
void | internalEntityDecl(String name, String value)
Report an internal entity declaration.
|
boolean | isAttributeSpecified(int attributeHandle)
5. [specified] A flag indicating whether this attribute was actually
specified in the start-tag of its element, or was defaulted from the
DTD.
|
boolean | isWhitespace(int nodeHandle)
Determine if the string-value of a node is whitespace
|
void | migrateTo(DTMManager manager)
Migrate a DTM built with an old DTMManager to a new DTMManager.
|
boolean | needsTwoThreads() |
void | notationDecl(String name, String publicId, String systemId)
Receive notification of a notation declaration.
|
void | processingInstruction(String target, String data)
Receive notification of a processing instruction.
|
InputSource | resolveEntity(String publicId, String systemId)
Resolve an external entity.
|
void | setDocumentLocator(Locator locator)
Receive a Locator object for document events.
|
void | setIDAttribute(String id, int elem)
Set an ID string to node association in the ID table.
|
void | setIncrementalSAXSource(IncrementalSAXSource incrementalSAXSource)
Bind a IncrementalSAXSource to this DTM. |
void | setProperty(String property, Object value)
Set a run time property for this DTM instance.
|
void | setUseSourceLocation(boolean useSourceLocation)
Set whether information about document source location
should be maintained or not. |
void | skippedEntity(String name)
Receive notification of a skipped entity.
|
void | startCDATA()
Report the start of a CDATA section.
|
void | startDocument()
Receive notification of the beginning of the document.
|
void | startDTD(String name, String publicId, String systemId)
Report the start of DTD declarations, if any.
|
void | startElement(String uri, String localName, String qName, Attributes attributes)
Receive notification of the start of an element.
|
void | startEntity(String name)
Report the beginning of an entity in content.
|
void | startPrefixMapping(String prefix, String uri)
Receive notification of the start of a Namespace mapping.
|
void | unparsedEntityDecl(String name, String publicId, String systemId, String notationName)
Receive notification of an unparsed entity declaration.
|
void | warning(SAXParseException e)
Receive notification of a parser warning.
|
Parameters: mgr The DTMManager who owns this DTM. source the JAXP 1.1 Source object for this DTM. dtmIdentity The DTM identity ID for this DTM. whiteSpaceFilter The white space filter for this DTM, which may be null. xstringfactory XMLString factory for creating character content. doIndexing true if the caller considers it worth it to use indexing schemes.
Parameters: mgr The DTMManager who owns this DTM. source the JAXP 1.1 Source object for this DTM. dtmIdentity The DTM identity ID for this DTM. whiteSpaceFilter The white space filter for this DTM, which may be null. xstringfactory XMLString factory for creating character content. doIndexing true if the caller considers it worth it to use indexing schemes. blocksize The block size of the DTM. usePrevsib true if we want to build the previous sibling node array. newNameTable true if we want to use a new ExpandedNameTable for this DTM.
Only the effective (first) declaration for an attribute will be reported. The type will be one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION", or a parenthesized token group with the separator "|" and all whitespace removed.
Parameters: eName The name of the associated element. aName The name of the attribute. type A string representing the attribute type. valueDefault A string representing the attribute default ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if none of these applies. value A string representing the attribute's default value, or null if there is none.
Throws: SAXException The application may raise an exception.
By default, do nothing. Application writers may override this method to take specific actions for each chunk of character data (such as adding the data to a node or buffer, or printing it to a file).
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: org.xml.sax.ContentHandler#characters
Parameters: callDoTerminate true of doTerminate should be called on the coRoutine parser.
This callback will be used for comments inside or outside the document element, including comments in the external DTD subset (if read).
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.
Parameters: nodeHandle The node ID. ch A non-null reference to a ContentHandler. normalize true if the content should be normalized according to the rules for the XPath normalize-space function.
Throws: SAXException
Parameters: nodeHandle The node ID. ch A non-null reference to a ContentHandler.
Throws: org.xml.sax.SAXException
The content model will consist of the string "EMPTY", the string "ANY", or a parenthesised group, optionally followed by an occurrence indicator. The model will be normalized so that all whitespace is removed,and will include the enclosing parentheses.
Parameters: name The element type name. model The content model as a normalized string.
Throws: SAXException The application may raise an exception.
Throws: SAXException The application may raise an exception.
See Also: SAX2DTM
Throws: SAXException Any SAX exception, possibly wrapping another exception.
See Also: org.xml.sax.ContentHandler#endDocument
Throws: SAXException The application may raise an exception.
See Also: SAX2DTM
By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each element (such as finalising a tree node or writing output to a file).
Parameters: uri The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed. localName The local name (without prefix), or the empty string if Namespace processing is not being performed. qName The qualified XML 1.0 name (with prefix), or the empty string if qualified names are not available.
Throws: SAXException Any SAX exception, possibly wrapping another exception.
See Also: org.xml.sax.ContentHandler#endElement
Parameters: name The name of the entity that is ending.
Throws: SAXException The application may raise an exception.
See Also: SAX2DTM
By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each prefix mapping.
Parameters: prefix The Namespace prefix being declared.
Throws: SAXException Any SAX exception, possibly wrapping another exception.
See Also: org.xml.sax.ContentHandler#endPrefixMapping
The default implementation does nothing. Application writers may override this method in a subclass to take specific actions for each error, such as inserting the message in a log file or printing it to the console.
Parameters: e The warning information encoded as an exception.
Throws: SAXException Any SAX exception, possibly wrapping another exception.
See Also: org.xml.sax.ErrorHandler#warning org.xml.sax.SAXParseException
Only the effective (first) declaration for each entity will be reported.
Parameters: name The name of the entity. If it is a parameter entity, the name will begin with '%'. publicId The declared public identifier of the entity, or null if none was declared. systemId The declared system identifier of the entity.
Throws: SAXException The application may raise an exception.
See Also: SAX2DTM org.xml.sax.DTDHandler#unparsedEntityDecl
The default implementation throws a SAXParseException. Application writers may override this method in a subclass if they need to take specific actions for each fatal error (such as collecting all of the errors into a single report): in any case, the application must stop all regular processing when this method is invoked, since the document is no longer reliable, and the parser may no longer report parsing events.
Parameters: e The error information encoded as an exception.
Throws: SAXException Any SAX exception, possibly wrapping another exception.
See Also: org.xml.sax.ErrorHandler#fatalError org.xml.sax.SAXParseException
Parameters: nodeHandle int Handle of the node upon which to look up this attribute.. namespaceURI The namespace URI of the attribute to retrieve, or null. name The local name of the attribute to retrieve.
Returns: The attribute node handle with the specified name (
nodeName
) or DTM.NULL
if there is no such
attribute.
Returns: null if this model doesn't respond to SAX events, "this" if the DTM object has a built-in SAX ContentHandler, the IncrementalSAXSource if we're bound to one and should receive the SAX stream via it for incremental build purposes...
Returns: null if this model doesn't respond to SAX Decl events.
Returns: the public identifier String object, or null if there is none.
Returns: the system identifier String object, or null if there is none.
Returns: null if this model doesn't respond to SAX dtd events.
Element
whose ID
is given by
elementId
. If no such element exists, returns
DTM.NULL
. Behavior is not defined if more than one element
has this ID
. Attributes (including those
with the name "ID") are not of type ID unless so defined by DTD/Schema
information available to the DTM implementation.
Implementations that do not know whether attributes are of type ID or
not are expected to return DTM.NULL
.
%REVIEW% Presumably IDs are still scoped to a single document, and this operation searches only within a single document, right? Wouldn't want collisions between DTMs in the same process.
Parameters: elementId The unique id
value for an element.
Returns: The handle of the matching element.
Returns: null if this model doesn't respond to SAX entity ref events.
Returns: null if this model doesn't respond to SAX error events.
Parameters: uri The namespace URI, which may be null.
Returns: The prefix if there is one, or null.
Returns: null if this model doesn't respond to lexical SAX events, "this" if the DTM object has a built-in SAX ContentHandler, the IncrementalSAXSource if we're bound to one and should receive the SAX stream via it for incremental build purposes...
Parameters: nodeHandle the id of the node.
Returns: String Local name of this node.
%REVIEW% Null or ""? -sb
Parameters: nodeHandle the id of the node.
Returns: String URI value of this node's namespace, or null if no namespace was resolved.
Returns: The prefix if there is one, or null.
Parameters: nodeHandle the id of the node.
Returns: String Name of this node, which may be an empty string. %REVIEW% Document when empty string is possible... %REVIEW-COMMENT% It should never be empty, should it?
Parameters: nodeHandle the id of the node.
Returns: String Name of this node, which may be an empty string.
Parameters: nodeHandle The node id.
Returns: String Value of this node, or null if not meaningful for this node type.
Returns: The number of that are currently in the tree.
%REVIEW% Are you sure you want "" for no prefix?
%REVIEW-COMMENT% I think so... not totally sure. -sb
Parameters: nodeHandle the id of the node.
Returns: String prefix of this node's name, or "" if no explicit namespace prefix was given.
Parameters: qname The qualified name, which may be null. uri The namespace URI, which may be null.
Returns: The prefix if there is one, or null.
Parameters: nodeHandle The node ID.
Returns: A string object that represents the string-value of the given node.
XML processors may choose to use the System Identifier (if one is provided) to resolve the entity, rather than the URI in the Public Identifier. The details are dependent on the processor, and we would have to support some form of plug-in resolver to handle this properly. Currently, we simply return the System Identifier if present, and hope that it a usable URI or that our caller can map it to one. TODO: Resolve Public Identifiers... or consider changing function name.
If we find a relative URI reference, XML expects it to be resolved in terms of the base URI of the document. The DOM doesn't do that for us, and it isn't entirely clear whether that should be done here; currently that's pushed up to a higher level of our application. (Note that DOM Level 1 didn't store the document's base URI.) TODO: Consider resolving Relative URIs.
(The DOM's statement that "An XML processor may choose to completely expand entities before the structure model is passed to the DOM" refers only to parsed entities, not unparsed, and hence doesn't affect this function.)
Parameters: name A string containing the Entity Name of the unparsed entity.
Returns: String containing the URI of the Unparsed Entity, or an empty string if no such entity exists.
By default, do nothing. Application writers may override this method to take specific actions for each chunk of ignorable whitespace (such as adding data to a node or buffer, or printing it to a file).
Parameters: ch The whitespace 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: org.xml.sax.ContentHandler#ignorableWhitespace
Only the effective (first) declaration for each entity will be reported.
Parameters: name The name of the entity. If it is a parameter entity, the name will begin with '%'. value The replacement text of the entity.
Throws: SAXException The application may raise an exception.
See Also: SAX2DTM org.xml.sax.DTDHandler#unparsedEntityDecl
Parameters: attributeHandle Must be a valid handle to an attribute node.
Returns: true
if the attribute was specified;
false
if it was defaulted.
Parameters: nodeHandle The node Handle.
Returns: Return true if the given node is whitespace.
Parameters: manager the DTMManager
Returns: true iff we're building this model incrementally (eg we're partnered with a IncrementalSAXSource) and thus require that the transformation and the parse run simultaneously. Guidance to the DTMManager.
By default, do nothing. Application writers may override this method in a subclass if they wish to keep track of the notations declared in a document.
Parameters: name The notation name. publicId The notation public identifier, or null if not available. systemId The notation system identifier.
Throws: SAXException Any SAX exception, possibly wrapping another exception. SAXException
See Also: org.xml.sax.DTDHandler#notationDecl
By default, do nothing. Application writers may override this method in a subclass to take specific actions for each processing instruction, such as setting status variables or invoking other methods.
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: org.xml.sax.ContentHandler#processingInstruction
Always return null, so that the parser will use the system identifier provided in the XML document. This method implements the SAX default behaviour: application writers can override it in a subclass to do special translations such as catalog lookups or URI redirection.
Parameters: publicId The public identifer, or null if none is available. systemId The system identifier provided in the XML document.
Returns: The new input source, or null to require the default behaviour.
Throws: SAXException Any SAX exception, possibly wrapping another exception. SAXException
See Also: org.xml.sax.EntityResolver#resolveEntity
By default, do nothing. Application writers may override this method in a subclass if they wish to store the locator for use with other document events.
Parameters: locator A locator for all SAX document events.
See Also: org.xml.sax.ContentHandler#setDocumentLocator org.xml.sax.Locator
Parameters: id The ID string. elem The associated element handle.
Parameters: incrementalSAXSource The parser that we want to recieve events from on demand.
Parameters: property a String
value value an Object
value
By default, do nothing. Application writers may override this method in a subclass to take specific actions for each processing instruction, such as setting status variables or invoking other methods.
Parameters: name The name of the skipped entity.
Throws: SAXException Any SAX exception, possibly wrapping another exception.
See Also: org.xml.sax.ContentHandler#processingInstruction
The contents of the CDATA section will be reported through
the regular org.xml.sax.ContentHandler#characters
characters
event.
Throws: SAXException The application may raise an exception.
See Also: SAX2DTM
Throws: SAXException Any SAX exception, possibly wrapping another exception.
See Also: org.xml.sax.ContentHandler#startDocument
Any declarations are assumed to be in the internal subset
unless otherwise indicated by a startEntity
event.
Note that the start/endDTD events will appear within the start/endDocument events from ContentHandler and before the first startElement event.
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.
By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).
Parameters: uri The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed. localName The local name (without prefix), or the empty string if Namespace processing is not being performed. qName The qualified name (with prefix), or the empty string if qualified names are not available. attributes The specified or defaulted attributes.
Throws: SAXException Any SAX exception, possibly wrapping another exception.
See Also: org.xml.sax.ContentHandler#startElement
NOTE: entity references in attribute values -- and the start and end of the document entity -- are never reported.
The start and end of the external DTD subset are reported using the pseudo-name "[dtd]". All other events must be properly nested within start/end entity events.
Note that skipped entities will be reported through the
org.xml.sax.ContentHandler#skippedEntity skippedEntity
event, which is part of the ContentHandler interface.
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: SAX2DTM org.xml.sax.ext.DeclHandler#internalEntityDecl org.xml.sax.ext.DeclHandler#externalEntityDecl
By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each Namespace prefix scope (such as storing the prefix mapping).
Parameters: prefix The Namespace prefix being declared. uri The Namespace URI mapped to the prefix.
Throws: SAXException Any SAX exception, possibly wrapping another exception.
See Also: org.xml.sax.ContentHandler#startPrefixMapping
By default, do nothing. Application writers may override this method in a subclass to keep track of the unparsed entities declared in a document.
Parameters: name The entity name. publicId The entity public identifier, or null if not available. systemId The entity system identifier. notationName The name of the associated notation.
Throws: SAXException Any SAX exception, possibly wrapping another exception. SAXException
See Also: org.xml.sax.DTDHandler#unparsedEntityDecl
The default implementation does nothing. Application writers may override this method in a subclass to take specific actions for each warning, such as inserting the message in a log file or printing it to the console.
Parameters: e The warning information encoded as an exception.
Throws: SAXException Any SAX exception, possibly wrapping another exception.
See Also: org.xml.sax.ErrorHandler#warning org.xml.sax.SAXParseException