Class SAXImpl

  • All Implemented Interfaces:
    DOM, DOMBuilder, ExtendedSAX, DOMEnhancedForDTM, DTM, org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.ext.DeclHandler, org.xml.sax.ext.LexicalHandler

    public final class SAXImpl
    extends SAX2DTM2
    implements DOMEnhancedForDTM, DOMBuilder
    SAXImpl is the core model for SAX input source. SAXImpl objects are usually created from an XSLTCDTMManager.

    DOMSource inputs are handled using DOM2SAX + SAXImpl. SAXImpl has a few specific fields (e.g. _node2Ids, _document) to keep DOM-related information. They are used when the processing behavior between DOM and SAX has to be different. Examples of these include id function and unparsed entity.

    SAXImpl extends SAX2DTM2 instead of SAX2DTM for better performance.

    Author:
    Jacek Ambroziak, Santiago Pericas-Geertsen, Morten Jorgensen, Douglas Sellers
    • Constructor Detail

      • SAXImpl

        public SAXImpl​(XSLTCDTMManager mgr,
                       javax.xml.transform.Source source,
                       int dtmIdentity,
                       DTMWSFilter whiteSpaceFilter,
                       XMLStringFactory xstringfactory,
                       boolean doIndexing,
                       boolean buildIdIndex)
        Construct a SAXImpl object using the default block size.
      • SAXImpl

        public SAXImpl​(XSLTCDTMManager mgr,
                       javax.xml.transform.Source source,
                       int dtmIdentity,
                       DTMWSFilter whiteSpaceFilter,
                       XMLStringFactory xstringfactory,
                       boolean doIndexing,
                       int blocksize,
                       boolean buildIdIndex,
                       boolean newNameTable)
        Construct a SAXImpl object using the given block size.
    • Method Detail

      • setDocumentURI

        public void setDocumentURI​(java.lang.String uri)
        Define the origin of the document from which the tree was built
        Specified by:
        setDocumentURI in interface DOMEnhancedForDTM
      • getDocumentURI

        public java.lang.String getDocumentURI()
        Returns the origin of the document from which the tree was built
        Specified by:
        getDocumentURI in interface DOMEnhancedForDTM
      • getDocumentURI

        public java.lang.String getDocumentURI​(int node)
        Specified by:
        getDocumentURI in interface DOM
      • setupMapping

        public void setupMapping​(java.lang.String[] names,
                                 java.lang.String[] urisArray,
                                 int[] typesArray,
                                 java.lang.String[] namespaces)
        Specified by:
        setupMapping in interface DOM
      • lookupNamespace

        public java.lang.String lookupNamespace​(int node,
                                                java.lang.String prefix)
                                         throws TransletException
        Lookup a namespace URI from a prefix starting at node. This method is used in the execution of xsl:element when the prefix is not known at compile time.
        Specified by:
        lookupNamespace in interface DOM
        Throws:
        TransletException
      • isElement

        public boolean isElement​(int node)
        Returns 'true' if a specific node is an element (of any type)
        Specified by:
        isElement in interface DOM
      • isAttribute

        public boolean isAttribute​(int node)
        Returns 'true' if a specific node is an attribute (of any type)
        Specified by:
        isAttribute in interface DOM
      • getSize

        public int getSize()
        Returns the number of nodes in the tree (used for indexing)
        Specified by:
        getSize in interface DOM
      • setFilter

        public void setFilter​(StripFilter filter)
        Part of the DOM interface - no function here.
        Specified by:
        setFilter in interface DOM
      • lessThan

        public boolean lessThan​(int node1,
                                int node2)
        Returns true if node1 comes before node2 in document order
        Specified by:
        lessThan in interface DOM
      • makeNode

        public org.w3c.dom.Node makeNode​(int index)
        Create an org.w3c.dom.Node from a node in the tree
        Specified by:
        makeNode in interface DOM
      • makeNode

        public org.w3c.dom.Node makeNode​(DTMAxisIterator iter)
        Create an org.w3c.dom.Node from a node in an iterator The iterator most be started before this method is called
        Specified by:
        makeNode in interface DOM
      • makeNodeList

        public org.w3c.dom.NodeList makeNodeList​(int index)
        Create an org.w3c.dom.NodeList from a node in the tree
        Specified by:
        makeNodeList in interface DOM
      • makeNodeList

        public org.w3c.dom.NodeList makeNodeList​(DTMAxisIterator iter)
        Create an org.w3c.dom.NodeList from a node iterator The iterator most be started before this method is called
        Specified by:
        makeNodeList in interface DOM
      • getIterator

        public DTMAxisIterator getIterator()
        Returns singleton iterator containg the document root Works for them main document (mark == 0). It cannot be made to point to any other node through setStartNode().
        Specified by:
        getIterator in interface DOM
      • getNSType

        public int getNSType​(int node)
        Get mapping from DOM namespace types to external namespace types
        Specified by:
        getNSType in interface DOM
      • getNamespaceType

        public int getNamespaceType​(int node)
        Returns the namespace type of a specific node
        Specified by:
        getNamespaceType in interface DOM
        Overrides:
        getNamespaceType in class DTMDefaultBase
        Parameters:
        node - the id of the node.
        Returns:
        the ID of the namespace.
      • getGeneralizedType

        public int getGeneralizedType​(java.lang.String name)
        Returns the internal type associated with an expanded QName
      • getGeneralizedType

        public int getGeneralizedType​(java.lang.String name,
                                      boolean searchOnly)
        Returns the internal type associated with an expanded QName
      • getMapping

        public short[] getMapping​(java.lang.String[] names,
                                  java.lang.String[] uris,
                                  int[] types)
        Get mapping from DOM element/attribute types to external types
        Specified by:
        getMapping in interface DOMEnhancedForDTM
      • getReverseMapping

        public int[] getReverseMapping​(java.lang.String[] names,
                                       java.lang.String[] uris,
                                       int[] types)
        Get mapping from external element/attribute types to DOM types
        Specified by:
        getReverseMapping in interface DOMEnhancedForDTM
      • getNamespaceMapping

        public short[] getNamespaceMapping​(java.lang.String[] namespaces)
        Get mapping from DOM namespace types to external namespace types
        Specified by:
        getNamespaceMapping in interface DOMEnhancedForDTM
      • getReverseNamespaceMapping

        public short[] getReverseNamespaceMapping​(java.lang.String[] namespaces)
        Get mapping from external namespace types to DOM namespace types
        Specified by:
        getReverseNamespaceMapping in interface DOMEnhancedForDTM
      • migrateTo

        public void migrateTo​(DTMManager manager)
        Migrate a DTM built with an old DTMManager to a new DTMManager. After the migration, the new DTMManager will treat the DTM as one that is built by itself. This is used to support DTM sharing between multiple transformations.
        Specified by:
        migrateTo in interface DTM
        Overrides:
        migrateTo in class SAX2DTM
        Parameters:
        manager - the DTMManager
      • getElementById

        public int getElementById​(java.lang.String idString)
        Return the node identity for a given id String
        Specified by:
        getElementById in interface DOMEnhancedForDTM
        Specified by:
        getElementById in interface DTM
        Overrides:
        getElementById in class SAX2DTM
        Parameters:
        idString - The id String
        Returns:
        The identity of the node whose id is the given String.
      • hasDOMSource

        public boolean hasDOMSource()
        Return true if the input source is DOMSource.
        Specified by:
        hasDOMSource in interface DOMEnhancedForDTM
      • characters

        public void characters​(char[] ch,
                               int start,
                               int length)
                        throws org.xml.sax.SAXException
        SAX2: Receive notification of character data.
        Specified by:
        characters in interface org.xml.sax.ContentHandler
        Overrides:
        characters in class SAX2DTM
        Parameters:
        ch - The characters.
        start - The start position in the character array.
        length - The number of characters to use from the character array.
        Throws:
        org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
        See Also:
        ContentHandler.characters(char[], int, int)
      • startDocument

        public void startDocument()
                           throws org.xml.sax.SAXException
        SAX2: Receive notification of the beginning of a document.
        Specified by:
        startDocument in interface org.xml.sax.ContentHandler
        Overrides:
        startDocument in class SAX2DTM2
        Throws:
        org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
        See Also:
        ContentHandler.startDocument()
      • endDocument

        public void endDocument()
                         throws org.xml.sax.SAXException
        SAX2: Receive notification of the end of a document.
        Specified by:
        endDocument in interface org.xml.sax.ContentHandler
        Overrides:
        endDocument in class SAX2DTM2
        Throws:
        org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
        See Also:
        ContentHandler.endDocument()
      • startElement

        public void startElement​(java.lang.String uri,
                                 java.lang.String localName,
                                 java.lang.String qname,
                                 org.xml.sax.Attributes attributes,
                                 org.w3c.dom.Node node)
                          throws org.xml.sax.SAXException
        Specialized interface used by DOM2SAX. This one has an extra Node parameter to build the Node -> id map.
        Throws:
        org.xml.sax.SAXException
      • startElement

        public void startElement​(java.lang.String uri,
                                 java.lang.String localName,
                                 java.lang.String qname,
                                 org.xml.sax.Attributes attributes)
                          throws org.xml.sax.SAXException
        SAX2: Receive notification of the beginning of an element.
        Specified by:
        startElement in interface org.xml.sax.ContentHandler
        Overrides:
        startElement in class SAX2DTM2
        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:
        org.xml.sax.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)
      • endElement

        public void endElement​(java.lang.String namespaceURI,
                               java.lang.String localName,
                               java.lang.String qname)
                        throws org.xml.sax.SAXException
        SAX2: Receive notification of the end of an element.
        Specified by:
        endElement in interface org.xml.sax.ContentHandler
        Overrides:
        endElement in class SAX2DTM2
        Parameters:
        namespaceURI - 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:
        org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
        See Also:
        ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
      • processingInstruction

        public void processingInstruction​(java.lang.String target,
                                          java.lang.String data)
                                   throws org.xml.sax.SAXException
        SAX2: Receive notification of a processing instruction.
        Specified by:
        processingInstruction in interface org.xml.sax.ContentHandler
        Overrides:
        processingInstruction in class SAX2DTM2
        Parameters:
        target - The processing instruction target.
        data - The processing instruction data, or null if none is supplied.
        Throws:
        org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
        See Also:
        ContentHandler.processingInstruction(java.lang.String, java.lang.String)
      • ignorableWhitespace

        public void ignorableWhitespace​(char[] ch,
                                        int start,
                                        int length)
                                 throws org.xml.sax.SAXException
        SAX2: Receive notification of ignorable whitespace in element content. Similar to characters(char[], int, int).
        Specified by:
        ignorableWhitespace in interface org.xml.sax.ContentHandler
        Overrides:
        ignorableWhitespace in class SAX2DTM
        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:
        org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
        See Also:
        ContentHandler.ignorableWhitespace(char[], int, int)
      • startPrefixMapping

        public void startPrefixMapping​(java.lang.String prefix,
                                       java.lang.String uri)
                                throws org.xml.sax.SAXException
        SAX2: Begin the scope of a prefix-URI Namespace mapping.
        Specified by:
        startPrefixMapping in interface org.xml.sax.ContentHandler
        Overrides:
        startPrefixMapping in class SAX2DTM
        Parameters:
        prefix - The Namespace prefix being declared.
        uri - The Namespace URI mapped to the prefix.
        Throws:
        org.xml.sax.SAXException - Any SAX exception, possibly wrapping another exception.
        See Also:
        ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)
      • comment

        public void comment​(char[] ch,
                            int start,
                            int length)
                     throws org.xml.sax.SAXException
        SAX2: Report an XML comment anywhere in the document.
        Specified by:
        comment in interface org.xml.sax.ext.LexicalHandler
        Overrides:
        comment in class SAX2DTM2
        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:
        org.xml.sax.SAXException - The application may raise an exception.
      • setEscaping

        public boolean setEscaping​(boolean value)
      • print

        public void print​(int node,
                          int level)
        Prints the whole tree to standard output
      • getNodeName

        public java.lang.String getNodeName​(int node)
        Returns the name of a node (attribute or element).
        Specified by:
        getNodeName in interface DOM
        Specified by:
        getNodeName in interface DTM
        Overrides:
        getNodeName in class SAX2DTM2
        Parameters:
        node - 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?
      • getNamespaceName

        public java.lang.String getNamespaceName​(int node)
        Returns the namespace URI to which a node belongs
        Specified by:
        getNamespaceName in interface DOM
      • getAttributeNode

        public int getAttributeNode​(int type,
                                    int element)
        Returns the attribute node of a given type (if any) for an element
        Specified by:
        getAttributeNode in interface DOM
      • getAttributeValue

        public java.lang.String getAttributeValue​(int type,
                                                  int element)
        Returns the value of a given attribute type of a given element
      • getAttributeValue

        public java.lang.String getAttributeValue​(java.lang.String name,
                                                  int element)
        This method is for testing/debugging only
      • getChildren

        public DTMAxisIterator getChildren​(int node)
        Returns an iterator with all the children of a given node
        Specified by:
        getChildren in interface DOM
      • getTypedChildren

        public DTMAxisIterator getTypedChildren​(int type)
        Returns an iterator with all children of a specific type for a given node (element)
        Specified by:
        getTypedChildren in interface DOM
      • getAxisIterator

        public DTMAxisIterator getAxisIterator​(int axis)
        This is a shortcut to the iterators that implement the supported XPath axes (only namespace::) is not supported. Returns a bare-bones iterator that must be initialized with a start node (using iterator.setStartNode()).
        Specified by:
        getAxisIterator in interface DOM
        Specified by:
        getAxisIterator in interface DTM
        Overrides:
        getAxisIterator in class DTMDefaultBaseIterators
        Parameters:
        axis - One of Axes.ANCESTORORSELF, etc.
        Returns:
        A DTMAxisIterator, or null if the given axis isn't supported.
      • getTypedAxisIterator

        public DTMAxisIterator getTypedAxisIterator​(int axis,
                                                    int type)
        Similar to getAxisIterator, but this one returns an iterator containing nodes of a typed axis (ex.: child::foo)
        Specified by:
        getTypedAxisIterator in interface DOM
        Specified by:
        getTypedAxisIterator in interface DTM
        Overrides:
        getTypedAxisIterator in class DTMDefaultBaseIterators
        Parameters:
        axis - One of Axes.ANCESTORORSELF, etc.
        type - An extended type ID.
        Returns:
        A DTMAxisIterator, or null if the given axis isn't supported.
      • getNamespaceAxisIterator

        public DTMAxisIterator getNamespaceAxisIterator​(int axis,
                                                        int ns)
        Do not think that this returns an iterator for the namespace axis. It returns an iterator with nodes that belong in a certain namespace, such as with The 'axis' specifies the axis for the base iterator from which the nodes are taken, while 'ns' specifies the namespace URI type.
        Specified by:
        getNamespaceAxisIterator in interface DOM
      • getTypedDescendantIterator

        public DTMAxisIterator getTypedDescendantIterator​(int type)
        Returns an iterator with all descendants of a node that are of a given type.
      • getNthDescendant

        public DTMAxisIterator getNthDescendant​(int type,
                                                int n,
                                                boolean includeself)
        Returns the nth descendant of a node
        Specified by:
        getNthDescendant in interface DOM
      • copy

        public void copy​(int node,
                         SerializationHandler handler)
                  throws TransletException
        Performs a deep copy (ref. XSLs copy-of()) TODO: Copy namespace declarations. Can't be done until we add namespace nodes and keep track of NS prefixes TODO: Copy comment nodes
        Specified by:
        copy in interface DOM
        Throws:
        TransletException
      • getLanguage

        public java.lang.String getLanguage​(int node)
        Returns a node' defined language for a node (if any)
        Specified by:
        getLanguage in interface DOM
      • getBuilder

        public DOMBuilder getBuilder()
        Returns an instance of the DOMBuilder inner class This class will consume the input document through a SAX2 interface and populate the tree.
      • getOutputDomBuilder

        public SerializationHandler getOutputDomBuilder()
        Return a SerializationHandler for output handling. This method is used by Result Tree Fragments.
        Specified by:
        getOutputDomBuilder in interface DOM
      • getResultTreeFrag

        public DOM getResultTreeFrag​(int initSize,
                                     int rtfType)
        Return a instance of a DOM class to be used as an RTF
        Specified by:
        getResultTreeFrag in interface DOM
      • getResultTreeFrag

        public DOM getResultTreeFrag​(int initSize,
                                     int rtfType,
                                     boolean addToManager)
        Return a instance of a DOM class to be used as an RTF
        Specified by:
        getResultTreeFrag in interface DOM
        Parameters:
        initSize - The initial size of the DOM.
        rtfType - The type of the RTF
        addToManager - true if the RTF should be registered with the DTMManager.
        Returns:
        The DOM object which represents the RTF.
      • getUnparsedEntityURI

        public java.lang.String getUnparsedEntityURI​(java.lang.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]). It returns the empty string if there is no such entity.
        Specified by:
        getUnparsedEntityURI in interface DOM
        Specified by:
        getUnparsedEntityURI in interface DTM
        Overrides:
        getUnparsedEntityURI in class SAX2DTM
        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.