dtmdocumentimpl.java

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

JAVA
1,662
字号
   * the IncrementalSAXSource if we're bound to one and should receive   * the SAX stream via it for incremental build purposes...   */  public LexicalHandler getLexicalHandler()  {    if (m_incrSAXSource instanceof IncrementalSAXSource_Filter)      return (LexicalHandler) m_incrSAXSource;    else      return this;  }  /**   * Return this DTM's EntityResolver.   *   * @return null if this model doesn't respond to SAX entity ref events.   */  public org.xml.sax.EntityResolver getEntityResolver()  {    return null;  }  /**   * Return this DTM's DTDHandler.   *   * @return null if this model doesn't respond to SAX dtd events.   */  public org.xml.sax.DTDHandler getDTDHandler()  {    return null;  }  /**   * Return this DTM's ErrorHandler.   *   * @return null if this model doesn't respond to SAX error events.   */  public org.xml.sax.ErrorHandler getErrorHandler()  {    return null;  }  /**   * Return this DTM's DeclHandler.   *   * @return null if this model doesn't respond to SAX Decl events.   */  public org.xml.sax.ext.DeclHandler getDeclHandler()  {    return null;  }  /** @return 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.   * */  public boolean needsTwoThreads()  {    return null!=m_incrSAXSource;  }  //================================================================  // ========= SAX2 ContentHandler methods =========  // Accept SAX events, use them to build/extend the DTM tree.  // Replaces the deprecated DocumentHandler interface.  public void characters(char[] ch, int start, int length)       throws org.xml.sax.SAXException  {    // Actually creating the text node is handled by    // processAccumulatedText(); here we just accumulate the    // characters into the buffer.    m_char.append(ch,start,length);  }  // Flush string accumulation into a text node  private void processAccumulatedText()  {    int len=m_char.length();    if(len!=m_char_current_start)      {        // The FastStringBuffer has been previously agreed upon        appendTextChild(m_char_current_start,len-m_char_current_start);        m_char_current_start=len;      }  }  public void endDocument()       throws org.xml.sax.SAXException  {    // May need to tell the low-level builder code to pop up a level.    // There _should't_ be any significant pending text at this point.    appendEndDocument();  }  public void endElement(java.lang.String namespaceURI, java.lang.String localName,      java.lang.String qName)       throws org.xml.sax.SAXException  {    processAccumulatedText();    // No args but we do need to tell the low-level builder code to    // pop up a level.    appendEndElement();  }  public void endPrefixMapping(java.lang.String prefix)       throws org.xml.sax.SAXException  {    // No-op  }  public void ignorableWhitespace(char[] ch, int start, int length)       throws org.xml.sax.SAXException  {    // %TBD% I believe ignorable text isn't part of the DTM model...?  }  public void processingInstruction(java.lang.String target, java.lang.String data)       throws org.xml.sax.SAXException  {    processAccumulatedText();    // %TBD% Which pools do target and data go into?  }  public void setDocumentLocator(Locator locator)  {    // No-op for DTM  }  public void skippedEntity(java.lang.String name)       throws org.xml.sax.SAXException  {    processAccumulatedText();    //%TBD%  }  public void startDocument()       throws org.xml.sax.SAXException  {    appendStartDocument();  }  public void startElement(java.lang.String namespaceURI, java.lang.String localName,      java.lang.String qName, Attributes atts)       throws org.xml.sax.SAXException  {    processAccumulatedText();    // %TBD% Split prefix off qname    String prefix=null;    int colon=qName.indexOf(':');    if(colon>0)      prefix=qName.substring(0,colon);    // %TBD% Where do we pool expandedName, or is it just the union, or...    /**/System.out.println("Prefix="+prefix+" index="+m_prefixNames.stringToIndex(prefix));    appendStartElement(m_nsNames.stringToIndex(namespaceURI),                     m_localNames.stringToIndex(localName),                     m_prefixNames.stringToIndex(prefix)); /////// %TBD%    // %TBD% I'm assuming that DTM will require resequencing of    // NS decls before other attrs, hence two passes are taken.    // %TBD% Is there an easier way to test for NSDecl?    int nAtts=(atts==null) ? 0 : atts.getLength();    // %TBD% Countdown is more efficient if nobody cares about sequence.    for(int i=nAtts-1;i>=0;--i)      {        qName=atts.getQName(i);        if(qName.startsWith("xmlns:") || "xmlns".equals(qName))          {            prefix=null;            colon=qName.indexOf(':');            if(colon>0)              {                prefix=qName.substring(0,colon);              }            else              {                // %REVEIW% Null or ""?                prefix=null; // Default prefix              }            appendNSDeclaration(                                    m_prefixNames.stringToIndex(prefix),                                    m_nsNames.stringToIndex(atts.getValue(i)),                                    atts.getType(i).equalsIgnoreCase("ID"));          }      }    for(int i=nAtts-1;i>=0;--i)      {        qName=atts.getQName(i);        if(!(qName.startsWith("xmlns:") || "xmlns".equals(qName)))          {            // %TBD% I hate having to extract the prefix into a new            // string when we may never use it. Consider pooling whole            // qNames, which are already strings?            prefix=null;            colon=qName.indexOf(':');            if(colon>0)              {                prefix=qName.substring(0,colon);                localName=qName.substring(colon+1);              }            else              {                prefix=""; // Default prefix                localName=qName;              }            m_char.append(atts.getValue(i)); // Single-string value            int contentEnd=m_char.length();            if(!("xmlns".equals(prefix) || "xmlns".equals(qName)))              appendAttribute(m_nsNames.stringToIndex(atts.getURI(i)),                                  m_localNames.stringToIndex(localName),                                  m_prefixNames.stringToIndex(prefix),                                  atts.getType(i).equalsIgnoreCase("ID"),                                  m_char_current_start, contentEnd-m_char_current_start);            m_char_current_start=contentEnd;          }      }  }  public void startPrefixMapping(java.lang.String prefix, java.lang.String uri)       throws org.xml.sax.SAXException  {    // No-op in DTM, handled during element/attr processing?  }  //  // LexicalHandler support. Not all SAX2 parsers support these events  // but we may want to pass them through when they exist...  //  public void comment(char[] ch, int start, int length)       throws org.xml.sax.SAXException  {    processAccumulatedText();    m_char.append(ch,start,length); // Single-string value    appendComment(m_char_current_start,length);    m_char_current_start+=length;  }  public void endCDATA()       throws org.xml.sax.SAXException  {    // No-op in DTM  }  public void endDTD()       throws org.xml.sax.SAXException  {    // No-op in DTM  }  public void endEntity(java.lang.String name)       throws org.xml.sax.SAXException  {    // No-op in DTM  }  public void startCDATA()       throws org.xml.sax.SAXException  {    // No-op in DTM  }  public void startDTD(java.lang.String name, java.lang.String publicId,      java.lang.String systemId)       throws org.xml.sax.SAXException  {    // No-op in DTM  }  public void startEntity(java.lang.String name)       throws org.xml.sax.SAXException  {    // No-op in DTM  }  //================================================================  // ========= Document Handler Functions =========  // %REVIEW% jjk -- DocumentHandler is  SAX Level 1, and deprecated....  // and this wasn't a fully compliant or declared implementation of that API  // in any case. Phase out in favor of SAX2 ContentHandler/LexicalHandler        /**         * Reset a dtm document to its initial (empty) state.         *         * The DTMManager will invoke this method when the dtm is created.         *         * @param documentNumber the handle for the DTM document.         */        final void initDocument(int documentNumber)        {                // save masked DTM document handle                m_docHandle = documentNumber<<DOCHANDLE_SHIFT;                // Initialize the doc -- no parent, no next-sib                nodes.writeSlot(0,DOCUMENT_NODE,-1,-1,0);                // wait for the first startElement to create the doc root node                done = false;        }// 	/**// 	 * Receive hint of the end of a document.// 	 *// 	 * <p>The content handler will invoke this method only once, and it will// 	 * be the last method invoked during the parse.  The handler shall not// 	 * not invoke this method until it has either abandoned parsing// 	 * (because of an unrecoverable error) or reached the end of// 	 * input.</p>// 	 */// 	public void documentEnd()// 	{// 		done = true;// 		// %TBD% may need to notice the last slot number and slot count to avoid// 		// residual data from provious use of this DTM// 	}// 	/**// 	 * Receive notification of the beginning of a document.// 	 *// 	 * <p>The SAX parser will invoke this method only once, before any// 	 * other methods in this interface.</p>// 	 */// 	public void reset()// 	{// 		// %TBD% reset slot 0 to indicate ChunkedIntArray reuse or wait for// 		//       the next initDocument().// 		m_docElement = NULL;	 // reset nodeHandle to the root of the actual dtm doc content// 		initDocument(0);// 	}// 	/**// 	 * Factory method; creates an Element 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.

⌨️ 快捷键说明

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