⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saximpl.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    	super.migrateTo(manager);    	if (manager instanceof XSLTCDTMManager) {    	    _dtmManager = (XSLTCDTMManager)manager;    	}    }            /**     * Return the node identity for a given id String     *      * @param idString The id String     * @return The identity of the node whose id is the given String.     */    public int getElementById(String idString)    {        Node node = _document.getElementById(idString);        if (node != null) {            Integer id = (Integer)_node2Ids.get(node);            return (id != null) ? id.intValue() : DTM.NULL;        }        else {            return DTM.NULL;        }    }        /**     * Return true if the input source is DOMSource.     */    public boolean hasDOMSource()    {        return _hasDOMSource;	    }    /*---------------------------------------------------------------------------*/    /* DOMBuilder methods begin                                                  */    /*---------------------------------------------------------------------------*/        /**     * Call this when an xml:space attribute is encountered to     * define the whitespace strip/preserve settings.     */    private void xmlSpaceDefine(String val, final int node)    {        final boolean setting = val.equals(PRESERVE_STRING);        if (setting != _preserve) {            _xmlSpaceStack[_idx++] = node;            _preserve = setting;        }    }    /**     * Call this from endElement() to revert strip/preserve setting     * to whatever it was before the corresponding startElement().     */    private void xmlSpaceRevert(final int node)    {        if (node == _xmlSpaceStack[_idx - 1]) {            _idx--;            _preserve = !_preserve;        }    }    /**     * Find out whether or not to strip whitespace nodes.     *     *     * @return whether or not to strip whitespace nodes.     */    protected boolean getShouldStripWhitespace()    {        return _preserve ? false : super.getShouldStripWhitespace();    }    /**     * Creates a text-node and checks if it is a whitespace node.     */    private void handleTextEscaping() {        if (_disableEscaping && _textNodeToProcess != DTM.NULL            && _type(_textNodeToProcess) == DTM.TEXT_NODE) {            if (_dontEscape == null) {                _dontEscape = new BitArray(_size);            }                      // Resize the _dontEscape BitArray if necessary.            if (_textNodeToProcess >= _dontEscape.size()) {                _dontEscape.resize(_dontEscape.size() * 2);            }                      _dontEscape.setBit(_textNodeToProcess);            _disableEscaping = false;        }        _textNodeToProcess = DTM.NULL;    }    /****************************************************************/    /*               SAX Interface Starts Here                      */    /****************************************************************/    /**     * SAX2: Receive notification of character data.     */    public void characters(char[] ch, int start, int length) throws SAXException    {        super.characters(ch, start, length);                _disableEscaping = !_escaping;          _textNodeToProcess = getNumberOfNodes();    }    /**     * SAX2: Receive notification of the beginning of a document.     */    public void startDocument() throws SAXException    {        super.startDocument();        _nsIndex.put(new Integer(0), new Integer(_uriCount++));        definePrefixAndUri(XML_PREFIX, XML_URI);    }    /**     * SAX2: Receive notification of the end of a document.     */    public void endDocument() throws SAXException    {        super.endDocument();                handleTextEscaping();        _namesSize = m_expandedNameTable.getSize();    }    /**     * Specialized interface used by DOM2SAX. This one has an extra Node     * parameter to build the Node -> id map.     */    public void startElement(String uri, String localName,                             String qname, Attributes attributes,                             Node node)        throws SAXException    {    	this.startElement(uri, localName, qname, attributes);    	    	if (m_buildIdIndex) {    	    _node2Ids.put(node, new Integer(m_parents.peek()));    	}    }        /**     * SAX2: Receive notification of the beginning of an element.     */    public void startElement(String uri, String localName,                 String qname, Attributes attributes)        throws SAXException    {        super.startElement(uri, localName, qname, attributes);                handleTextEscaping();        if (m_wsfilter != null) {            // Look for any xml:space attributes            // Depending on the implementation of attributes, this            // might be faster than looping through all attributes. ILENE            final int index = attributes.getIndex(XMLSPACE_STRING);            if (index >= 0) {                xmlSpaceDefine(attributes.getValue(index), m_parents.peek());            }        }    }    /**     * SAX2: Receive notification of the end of an element.     */    public void endElement(String namespaceURI, String localName, String qname)        throws SAXException    {        super.endElement(namespaceURI, localName, qname);                handleTextEscaping();        // Revert to strip/preserve-space setting from before this element        if (m_wsfilter != null) {            xmlSpaceRevert(m_previous);        }    }    /**     * SAX2: Receive notification of a processing instruction.     */    public void processingInstruction(String target, String data)        throws SAXException    {        super.processingInstruction(target, data);        handleTextEscaping();    }    /**     * SAX2: Receive notification of ignorable whitespace in element     * content. Similar to characters(char[], int, int).     */    public void ignorableWhitespace(char[] ch, int start, int length)        throws SAXException    {        super.ignorableWhitespace(ch, start, length);        _textNodeToProcess = getNumberOfNodes();    }    /**     * SAX2: Begin the scope of a prefix-URI Namespace mapping.     */    public void startPrefixMapping(String prefix, String uri)        throws SAXException    {        super.startPrefixMapping(prefix, uri);        handleTextEscaping();        definePrefixAndUri(prefix, uri);    }    private void definePrefixAndUri(String prefix, String uri)         throws SAXException     {        // Check if the URI already exists before pushing on stack        Integer eType = new Integer(getIdForNamespace(uri));        if ((Integer)_nsIndex.get(eType) == null) {            _nsIndex.put(eType, new Integer(_uriCount++));        }    }     /**     * SAX2: Report an XML comment anywhere in the document.     */    public void comment(char[] ch, int start, int length)        throws SAXException    {        super.comment(ch, start, length);        handleTextEscaping();    }    public boolean setEscaping(boolean value) {        final boolean temp = _escaping;        _escaping = value;         return temp;    }      /*---------------------------------------------------------------------------*/   /* DOMBuilder methods end                                                    */   /*---------------------------------------------------------------------------*/    /**     * Prints the whole tree to standard output     */    public void print(int node, int level)    {        switch(getNodeType(node))        {	    case DTM.ROOT_NODE:	    case DTM.DOCUMENT_NODE:	        print(getFirstChild(node), level);	        break;	    case DTM.TEXT_NODE:	    case DTM.COMMENT_NODE:	    case DTM.PROCESSING_INSTRUCTION_NODE:	        System.out.print(getStringValueX(node));	        break;	    default:	        final String name = getNodeName(node);	        System.out.print("<" + name);	        for (int a = getFirstAttribute(node); a != DTM.NULL; a = getNextAttribute(a))                {		    System.out.print("\n" + getNodeName(a) + "=\"" + getStringValueX(a) + "\"");	        }	        System.out.print('>');	        for (int child = getFirstChild(node); child != DTM.NULL;		    child = getNextSibling(child)) {		    print(child, level + 1);	        }	        System.out.println("</" + name + '>');	        break;	}    }    /**     * Returns the name of a node (attribute or element).     */    public String getNodeName(final int node)    {	// Get the node type and make sure that it is within limits	int nodeh = node;	final short type = getNodeType(nodeh);	switch(type)        {	    case DTM.ROOT_NODE:	    case DTM.DOCUMENT_NODE:	    case DTM.TEXT_NODE:	    case DTM.COMMENT_NODE:	        return EMPTYSTRING;	    case DTM.NAMESPACE_NODE:		return this.getLocalName(nodeh);	    default:	        return super.getNodeName(nodeh);	}    }        /**     * Returns the namespace URI to which a node belongs     */    public String getNamespaceName(final int node)    {    	if (node == DTM.NULL) {    	    return "";    	}    	        String s;        return (s = getNamespaceURI(node)) == null ? EMPTYSTRING : s;    }     /**     * Returns the attribute node of a given type (if any) for an element     */    public int getAttributeNode(final int type, final int element)    {        for (int attr = getFirstAttribute(element);           attr != DTM.NULL;           attr = getNextAttribute(attr))        {            if (getExpandedTypeID(attr) == type) return attr;        }        return DTM.NULL;    }    /**     * Returns the value of a given attribute type of a given element     */    public String getAttributeValue(final int type, final int element)    {        final int attr = getAttributeNode(type, element);        return (attr != DTM.NULL) ? getStringValueX(attr) : EMPTYSTRING;    }    /**     * This method is for testing/debugging only     */    public String getAttributeValue(final String name, final int element)    {        return getAttributeValue(getGeneralizedType(name), element);    }    /**     * Returns an iterator with all the children of a given node     */    public DTMAxisIterator getChildren(final int node)    {        return (new ChildrenIterator()).setStartNode(node);    }    /**     * Returns an iterator with all children of a specific type     * for a given node (element)     */    public DTMAxisIterator getTypedChildren(final int type)    {        return(new TypedChildrenIterator(type));    }    /**     * 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()).     */    public DTMAxisIterator getAxisIterator(final int axis)    {        switch (axis)        {            case Axis.SELF:                return new SingletonIterator();            case Axis.CHILD:                return new ChildrenIterator();            case Axis.PARENT:                return new ParentIterator();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -