sylvain     01/07/24 05:10:04

  Modified:    src/org/apache/cocoon/xml/dom DOMStreamer.java
  Added:       src/org/apache/cocoon/xml EmbeddedXMLPipe.java
  Log:
  Strip start/endDocument if the streamed node isn't a Document
  
  Revision  Changes    Path
  1.1                  xml-cocoon2/src/org/apache/cocoon/xml/EmbeddedXMLPipe.java
  
  Index: EmbeddedXMLPipe.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.cocoon.xml;
  
  import org.xml.sax.ContentHandler;
  import org.xml.sax.SAXException;
  
  /**
   * This class implements a ContentHandler for embedding a full SAX
   * event stream into an existing stream of SAX events. An instance of
   * this class will pass unmodified all the SAX events to the linked
   * ContentHandler, but will ignore the startDocument and endDocument
   * events.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Ovidiu Predescu</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/07/24 12:10:04 $
   */
  public class EmbeddedXMLPipe extends AbstractXMLPipe
  {
      /**
       * Creates an EmbeddedXMLPipe that writes into the given ContentHandler.
       */
      public EmbeddedXMLPipe(ContentHandler handler) {
          setContentHandler(handler);
      }
       
      /**
       * Ignore the <code>startDocument</code> event: this method does nothing.
       *
       * @exception SAXException if an error occurs
       */
      public void startDocument()
      throws SAXException
      {
      }
      
      /**
       * Ignore the <code>endDocument</code> event: this method does nothing.
       *
       * @exception SAXException if an error occurs
       */
      public void endDocument()
      throws SAXException
      {
      }
  }
  
  
  
  1.4       +13 -2     xml-cocoon2/src/org/apache/cocoon/xml/dom/DOMStreamer.java
  
  Index: DOMStreamer.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/xml/dom/DOMStreamer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DOMStreamer.java  2001/07/05 13:33:01     1.3
  +++ DOMStreamer.java  2001/07/24 12:10:04     1.4
  @@ -16,6 +16,7 @@
   import javax.xml.transform.sax.SAXResult;
   
   import org.apache.cocoon.xml.AbstractXMLProducer;
  +import org.apache.cocoon.xml.EmbeddedXMLPipe;
   import org.apache.cocoon.xml.XMLConsumer;
   import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
  @@ -29,7 +30,7 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.3 $ $Date: 2001/07/05 13:33:01 $
  + * @version CVS $Revision: 1.4 $ $Date: 2001/07/24 12:10:04 $
    */
   public class DOMStreamer extends AbstractXMLProducer {
   
  @@ -83,7 +84,17 @@
               }
           }
           DOMSource source = new DOMSource(node);
  -        SAXResult result = new SAXResult(super.contentHandler);
  +        
  +        ContentHandler handler;
  +        if (node.getNodeType() == Node.DOCUMENT_NODE) {
  +            // Pass all SAX events
  +            handler = super.contentHandler;
  +        } else {
  +            // Strip start/endDocument
  +            handler = new EmbeddedXMLPipe(super.contentHandler);
  +        }
  +        
  +        SAXResult result = new SAXResult(handler);
           result.setLexicalHandler(super.lexicalHandler);
   
           try {
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to