mmidy       00/11/15 16:12:10

  Modified:    java/src/org/apache/xalan/stree StreeDOMBuilder.java
                        TextImpl.java
  Log:
  Append current text to text of previously created text node from the last 
Characters
  
  Revision  Changes    Path
  1.6       +118 -9    
xml-xalan/java/src/org/apache/xalan/stree/StreeDOMBuilder.java
  
  Index: StreeDOMBuilder.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/stree/StreeDOMBuilder.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- StreeDOMBuilder.java      2000/11/13 16:27:08     1.5
  +++ StreeDOMBuilder.java      2000/11/16 00:12:10     1.6
  @@ -62,6 +62,7 @@
   import org.w3c.dom.DocumentFragment;
   import org.w3c.dom.Node;
   import org.w3c.dom.Element;
  +import org.xml.sax.Attributes;
   
   import javax.xml.transform.TransformerException;
   
  @@ -76,6 +77,10 @@
   
     /** Source document node          */
     protected DocumentImpl m_docImpl;
  +  
  +  /** State of the source tree indicating whether the last event
  +   * was a characters event.   */
  +  private boolean m_previousIsText = false;
   
     /**
      * StreeDOMBuilder instance constructor... it will add the DOM nodes
  @@ -131,6 +136,38 @@
     {
       m_docImpl.setIDAttribute(id, elem);
     }
  +  
  +  /**
  +   * Receive notification of the beginning of an element.
  +   *
  +   *
  +   * @param ns namespace URL of the element
  +   * @param localName local part of qualified name of the element 
  +   * @param name The element type name.
  +   * @param atts The attributes attached to the element, if any.
  +   * @see org.apache.xalan.utils.DOMBuilder.startElement()
  +   */
  +  public void startElement(
  +          String ns, String localName, String name, Attributes atts)
  +            throws org.xml.sax.SAXException
  +  {
  +    super.startElement(ns, localName, name, atts);
  +    setPreviousIsText(false);
  +  }
  +  
  +  /**
  +   * Receive notification of the end of an element.
  +   *
  +   * @param ns namespace URL of the element
  +   * @param localName local part of qualified name of the element
  +   * @param name The element type name
  +   */
  +  public void endElement(String ns, String localName, String name)
  +          throws org.xml.sax.SAXException
  +  {
  +    super.endElement(ns, localName, name);
  +    setPreviousIsText(false);
  +  }
   
     /**
      * Receive notification of character data.
  @@ -143,12 +180,17 @@
      * @throws TransformerException
      */
     public void characters(char ch[], int start, int length) throws 
org.xml.sax.SAXException
  -  {
  -
  -    if (m_inCData)
  -      append(new CDATASectionImpl(m_docImpl, ch, start, length));
  +  {           
  +    if (getPreviousIsText())      
  +      appendAccumulatedText(getCurrentNode(), ch, start, length);      
       else
  -      append(new TextImpl(m_docImpl, ch, start, length));
  +    {
  +      if (m_inCData)
  +        append(new CDATASectionImpl(m_docImpl, ch, start, length));
  +      else
  +        append(new TextImpl(m_docImpl, ch, start, length));
  +      setPreviousIsText(true);
  +    }        
     }
   
     /**
  @@ -164,7 +206,13 @@
     public void ignorableWhitespace(char ch[], int start, int length)
             throws org.xml.sax.SAXException
     {
  -    append(new TextImpl(m_docImpl, ch, start, length));
  +    if (getPreviousIsText())      
  +      appendAccumulatedText(getCurrentNode(), ch, start, length);      
  +    else
  +    {  
  +      append(new TextImpl(m_docImpl, ch, start, length));
  +      setPreviousIsText(true);
  +    }
     }
   
     /**
  @@ -187,6 +235,7 @@
       append(m_doc.createProcessingInstruction("xslt-next-is-raw",
                                                "formatter-to-dom"));
       append(new TextImpl(m_docImpl, ch, start, length));
  +    
     }
   
     /**
  @@ -202,8 +251,10 @@
     public void comment(char ch[], int start, int length) throws 
org.xml.sax.SAXException
     {
       append(new CommentImpl(m_docImpl, ch, start, length));
  +    setPreviousIsText(false);
     }
  -
  +  
  +  //Don't think we need this for STree!!
     /**
      * Receive notification of cdata. 
      *
  @@ -213,9 +264,67 @@
      * @param length The number of characters to read from the array.
      *
      * @throws TransformerException
  +   */
  +/*  public void cdata(char ch[], int start, int length) throws 
org.xml.sax.SAXException
  +  {
  +    append(new CDATASectionImpl(m_docImpl, ch, start, length));    
  +  }*/
  +  
  +   /**
  +   * Receive notification of ignorable whitespace in element content.
  +   *
  +   * @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.
  +   * @see #characters
  +   */
  +  public void processingInstruction(String target, String data)
  +          throws org.xml.sax.SAXException
  +  {
  +    super.processingInstruction(target, data);
  +    setPreviousIsText(false);
  +  }
  +  
  +  /**
  +   * Set the state of the source tree to indicate whether the last event
  +   * was a characters event. 
  +   *
  +   *
  +   * @param isText True if last event was a characters event
  +   *
  +   */
  +  void setPreviousIsText(boolean isText)
  +  {   
  +    m_previousIsText = isText;
  +  }
  +  
  +  /**
  +   * Get the state of the source tree indicating whether the last event
  +   * was a characters event. 
  +   *
  +   *
  +   * @return True if last event was a characters event
  +   *
  +   */
  +  boolean getPreviousIsText()
  +  {   
  +    return m_previousIsText;
  +  } 
  +  
  +  /**
  +   * Append the text from this characters event to the previous text.
  +   *
  +   *
  +   * @param textNode Text node created by previous characters event.
  +   * @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 void cdata(char ch[], int start, int length) throws 
org.xml.sax.SAXException
  +  void appendAccumulatedText(Node currentNode, char ch[], int start, int 
length)
     {
  -    append(new CDATASectionImpl(m_docImpl, ch, start, length));
  +    TextImpl textNode = (TextImpl)((Parent)currentNode).m_last;
  +    textNode.appendText(ch, start, length);
     }
  +  
   }
  
  
  
  1.7       +23 -0     xml-xalan/java/src/org/apache/xalan/stree/TextImpl.java
  
  Index: TextImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/stree/TextImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TextImpl.java     2000/11/13 16:27:08     1.6
  +++ TextImpl.java     2000/11/16 00:12:10     1.7
  @@ -240,4 +240,27 @@
       // else
       //  return super.supports(feature, version);
     }
  +  
  +  /**
  +   * Append this text to the text of this node.
  +   *
  +   *
  +   * @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. 
  +   *
  +   */
  +  void appendText(char ch[], int start, int length)
  +  {   
  +    if (null == m_data)
  +    {
  +      FastStringBuffer fsb = m_doc.m_chars;   
  +      fsb.append(ch, start, length);      
  +    }
  +    else
  +      m_data.concat(ch.toString());
  +    
  +    m_length += length;
  +  }
  +  
   }
  
  
  

Reply via email to