dtmdocumentimpl.java

来自「java jdk 1.4的源码」· Java 代码 · 共 1,655 行 · 第 1/5 页

JAVA
1,655
字号
          * Set a reference pointer to the content-text repository          *          * @param bufferRef FastStringBuffer reference to an instance of          * buffer          */         void setContentBuffer(FastStringBuffer buffer) {                 m_char = buffer;         }         /**          * Get a reference pointer to the content-text repository          *          * @return FastStringBuffer reference to an instance of buffer          */         FastStringBuffer getContentBuffer() {                 return m_char;         }  /** getContentHandler returns "our SAX builder" -- the thing that   * someone else should send SAX events to in order to extend this   * DTM model.   *   * @return 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...   * */  public org.xml.sax.ContentHandler getContentHandler()  {    if (m_incrSAXSource instanceof IncrementalSAXSource_Filter)      return (ContentHandler) m_incrSAXSource;    else      return this;  }  /**   * Return this DTM's lexical handler.   *   * %REVIEW% Should this return null if constrution already done/begun?   *   * @return 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...   */  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 docHandle int the handle for the DTM document.         */        final void initDocument(int documentNumber)        {                // save masked DTM document handle

⌨️ 快捷键说明

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