dtmdocumentimpl.java

来自「JAVA 所有包」· Java 代码 · 共 1,662 行 · 第 1/5 页

JAVA
1,662
字号
// 	 *// 	 * <p>The XML content handler will invoke endElement() method after all// 	 * of the element's content are processed in order to give DTM the indication// 	 * to prepare and patch up parent and sibling node pointers.</p>// 	 *// 	 * <p>The following interface for createElement will use an index value corresponds// 	 * to the symbol entry in the DTMDStringPool based symbol tables.</p>// 	 *// 	 * @param nsIndex The namespace of the node// 	 * @param nameIndex The element name.// 	 * @see #endElement// 	 * @see org.xml.sax.Attributes// 	 * @return nodeHandle int of the element created// 	 */// 	public int createElement(int nsIndex, int nameIndex, Attributes atts)// 	{// 		// do document root node creation here on the first element, create nodes for// 		// this element and its attributes, store the element, namespace, and attritute// 		// name indexes to the nodes array, keep track of the current node and parent// 		// element used// 		// W0  High:  Namespace  Low:  Node Type// 		int w0 = (nsIndex << 16) | ELEMENT_NODE;// 		// W1: Parent// 		int w1 = currentParent;// 		// W2: Next  (initialized as 0)// 		int w2 = 0;// 		// W3: Tagname// 		int w3 = nameIndex;// 		//int ourslot = nodes.appendSlot(w0, w1, w2, w3);// 		int ourslot = appendNode(w0, w1, w2, w3);// 		currentParent = ourslot;// 		previousSibling = 0;// 		setAttributes(atts);// 		// set the root element pointer when creating the first element node// 		if (m_docElement == NULL)// 			m_docElement = ourslot;// 		return (m_docHandle | ourslot);// 	}// 	// Factory method to create an Element node not associated with a given name space// 	// using String value parameters passed in from a content handler or application// 	/**// 	 * Factory method; creates an Element node not associated with a given name space in this document.// 	 *// 	 * The node created will be chained according to its natural order of request// 	 * received.  %TBD% It can be rechained later via the optional DTM writable interface.// 	 *// 	 * <p>The XML content handler or application will invoke endElement() method after all// 	 * of the element's content are processed in order to give DTM the indication// 	 * to prepare and patch up parent and sibling node pointers.</p>// 	 *// 	 * <p>The following parameters for createElement contains raw string values for name// 	 * symbols used in an Element node.</p>// 	 *// 	 * @param name String the element name, including the prefix if any.// 	 * @param atts The attributes attached to the element, if any.// 	 * @see #endElement// 	 * @see org.xml.sax.Attributes// 	 */// 	public int createElement(String name, Attributes atts)// 	{// 		// This method wraps around the index valued interface of the createElement interface.// 		// The raw string values are stored into the current DTM name symbol tables.  The method// 		// method will then use the index values returned to invoke the other createElement()// 		// onverted to index values modified to match a// 		// method.// 		int nsIndex = NULL;// 		int nameIndex = m_localNames.stringToIndex(name);// 		// note - there should be no prefix separator in the name because it is not associated// 		// with a name space// 		return createElement(nsIndex, nameIndex, atts);// 	}// 	// Factory method to create an Element node associated with a given name space// 	// using String value parameters passed in from a content handler or application// 	/**// 	 * Factory method; creates an Element node associated with a given name space in this document.// 	 *// 	 * The node created will be chained according to its natural order of request// 	 * received.  %TBD% It can be rechained later via the optional DTM writable interface.// 	 *// 	 * <p>The XML content handler or application will invoke endElement() method after all// 	 * of the element's content are processed in order to give DTM the indication// 	 * to prepare and patch up parent and sibling node pointers.</p>// 	 *// 	 * <p>The following parameters for createElementNS contains raw string values for name// 	 * symbols used in an Element node.</p>// 	 *// 	 * @param ns String the namespace of the node// 	 * @param name String the element name, including the prefix if any.// 	 * @param atts The attributes attached to the element, if any.// 	 * @see #endElement// 	 * @see org.xml.sax.Attributes// 	 */// 	public int createElementNS(String ns, String name, Attributes atts)// 	{// 		// This method wraps around the index valued interface of the createElement interface.// 		// The raw string values are stored into the current DTM name symbol tables.  The method// 		// method will then use the index values returned to invoke the other createElement()// 		// onverted to index values modified to match a// 		// method.// 		int nsIndex = m_nsNames.stringToIndex(ns);// 		int nameIndex = m_localNames.stringToIndex(name);// 		// The prefixIndex is not needed by the indexed interface of the createElement method// 		int prefixSep = name.indexOf(":");// 		int prefixIndex = m_prefixNames.stringToIndex(name.substring(0, prefixSep));// 		return createElement(nsIndex, nameIndex, atts);// 	}// 	/**// 	 * Receive an indication for the end of an element.// 	 *// 	 * <p>The XML content handler will invoke this method at the end of every// 	 * element in the XML document to give hint its time to pop up the current// 	 * element and parent and patch up parent and sibling pointers if necessary// 	 *// 	 * <p>%tbd% The following interface may need to be modified to match a// 	 * coordinated access to the DTMDStringPool based symbol tables.</p>// 		 *// 	 * @param ns the namespace of the element// 	 * @param name The element name// 	 */// 	public void endElement(String ns, String name)// 	{// 		// pop up the stacks// 		//// 		if (previousSiblingWasParent)// 			nodes.writeEntry(previousSibling, 2, NULL);// 		// Pop parentage// 		previousSibling = currentParent;// 		nodes.readSlot(currentParent, gotslot);// 		currentParent = gotslot[1] & 0xFFFF;// 		// The element just being finished will be// 		// the previous sibling for the next operation// 		previousSiblingWasParent = true;// 		// Pop a level of namespace table// 		// namespaceTable.removeLastElem();// 	}// 	/**// 	 * Creates attributes for the current node.// 	 *// 	 * @param atts Attributes to be created.// 	 */// 	void setAttributes(Attributes atts) {// 		int atLength = (null == atts) ? 0 : atts.getLength();// 		for (int i=0; i < atLength; i++) {// 			String qname = atts.getQName(i);// 			createAttribute(atts.getQName(i), atts.getValue(i));// 		}// 	}// 	/**// 	 * Appends an attribute to the document.// 	 * @param qname Qualified Name of the attribute// 	 * @param value Value of the attribute// 	 * @return Handle of node// 	 */// 	public int createAttribute(String qname, String value) {// 		int colonpos = qname.indexOf(":");// 		String attName = qname.substring(colonpos+1);// 		int w0 = 0;// 		if (colonpos > 0) {// 			String prefix = qname.substring(0, colonpos);// 			if (prefix.equals("xml")) {// 				//w0 = ATTRIBUTE_NODE |// 				//	(com.sun.org.apache.xalan.internal.templates.Constants.S_XMLNAMESPACEURI << 16);// 			} else {// 				//w0 = ATTRIBUTE_NODE |// 			}// 		} else {// 			w0 = ATTRIBUTE_NODE;// 		}// 		// W1:  Parent// 		int w1 = currentParent;// 		// W2:  Next (not yet resolved)// 		int w2 = 0;// 		// W3:  Tag name// 		int w3 = m_localNames.stringToIndex(attName);// 		// Add node// 		int ourslot = appendNode(w0, w1, w2, w3);// 		previousSibling = ourslot;	// Should attributes be previous siblings// 		// W0: Node Type// 		w0 = TEXT_NODE;// 		// W1: Parent// 		w1 = ourslot;// 		// W2: Start Position within buffer// 		w2 = m_char.length();// 		m_char.append(value);// 		// W3: Length// 		w3 = m_char.length() - w2;// 		appendNode(w0, w1, w2, w3);// 		charStringStart=m_char.length();// 		charStringLength = 0;// 		//previousSibling = ourslot;// 		// Attrs are Parents// 		previousSiblingWasParent = true;// 		return (m_docHandle | ourslot);// 	}// 	/**// 	 * Factory method; creates a Text node in this document.// 	 *// 	 * The node created will be chained according to its natural order of request// 	 * received.  %TBD% It can be rechained later via the optional DTM writable interface.// 	 *// 	 * @param text String The characters text string from the XML document.// 	 * @return int DTM node-number of the text node created// 	 */// 	public int createTextNode(String text)// 	throws DTMException// 	{// 		// wraps around the index value based createTextNode method// 		return createTextNode(text.toCharArray(), 0, text.length());// 	}// 	/**// 	 * Factory method; creates a Text node in this document.// 	 *// 	 * The node created will be chained according to its natural order of request// 	 * received.  %TBD% It can be rechained later via the optional DTM writable interface.// 	 *// 	 * %REVIEW% for text normalization issues, unless we are willing to// 	 * insist that all adjacent text must be merged before this method// 	 * is called.// 	 *// 	 * @param ch The characters from the XML document.// 	 * @param start The start position in the array.// 	 * @param length The number of characters to read from the array.// 	 */// 	public int createTextNode(char ch[], int start, int length)// 	throws DTMException// 	{// 		m_char.append(ch, start, length);		// store the chunk to the text/comment string table// 		// create a Text Node// 		// %TBD% may be possible to combine with appendNode()to replace the next chunk of code// 		int w0 = TEXT_NODE;// 		// W1: Parent// 		int w1 = currentParent;// 		// W2: Start position within m_char// 		int w2 = charStringStart;// 		// W3: Length of the full string// 		int w3 = length;// 		int ourslot = appendNode(w0, w1, w2, w3);// 		previousSibling = ourslot;// 		charStringStart=m_char.length();// 		charStringLength = 0;// 		return (m_docHandle | ourslot);// 	}// 	/**// 	 * Factory method; creates a Comment node in this document.// 	 *// 	 * The node created will be chained according to its natural order of request// 	 * received.  %TBD% It can be rechained later via the optional DTM writable interface.// 	 *// 	 * @param text String The characters text string from the XML document.// 	 * @return int DTM node-number of the text node created// 	 */// 	public int createComment(String text)// 	throws DTMException// 	{// 		// wraps around the index value based createTextNode method// 		return createComment(text.toCharArray(), 0, text.length());// 	}// 	/**// 	 * Factory method; creates a Comment node in this document.// 	 *// 	 * The node created will be chained according to its natural order of request// 	 * received.  %TBD% It can be rechained later via the optional DTM writable interface.// 	 *// 	 * @param ch An array holding the characters in the comment.// 	 * @param start The starting position in the array.// 	 * @param length The number of characters to use from the array.// 	 * @see DTMException// 	 */// 	public int createComment(char ch[], int start, int length)// 	throws DTMException// 	{// 		m_char.append(ch, start, length);		// store the comment string to the text/comment string table// 		// create a Comment Node// 		// %TBD% may be possible to combine with appendNode()to replace the next chunk of code// 		int w0 = COMMENT_NODE;// 		// W1: Parent// 		int w1 = currentParent;// 		// W2: Start position within m_char// 		int w2 = charStringStart;// 		// W3: Length of the full string// 		int w3 = length;// 		int ourslot = appendNode(w0, w1, w2, w3);// 		previousSibling = ourslot;// 		charStringStart=m_char.length();// 		charStringLength = 0;// 		return (m_docHandle | ourslot);// 	}// 	// Counters to keep track of the current text string being accumulated with respect// 	// to the text/comment string table: charStringStart should point to the starting// 	// offset of the string in the table and charStringLength the acccumulated length when// 	// appendAccumulatedText starts, and reset to the end of the table and 0 at the end// 	// of appendAccumulatedText for the next set of characters receives// 	int charStringStart=0,charStringLength=0;        // ========= Document Navigation Functions =========        /** Given a node handle, test if it has child nodes.         * <p> %REVIEW% This is obviously useful at the DOM layer, where it         * would permit testing this without having to create a proxy         * node. It's less useful in the DTM API, where         * (dtm.getFirstChild(nodeHandle)!=DTM.NULL) is just as fast and         * almost as self-evident. But it's a convenience, and eases porting         * of DOM code to DTM.  </p>         *         * @param nodeHandle int Handle of the node.         * @return int true if the given node has child nodes.         */        public boolean hasChildNodes(int nodeHandle) {                return(getFirstChild(nodeHandle) != NULL);        }

⌨️ 快捷键说明

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