cziegeler    2003/02/27 07:22:48

  Modified:    src/java/org/apache/cocoon/components/source SourceUtil.java
               src/java/org/apache/cocoon/transformation
                        SourceWritingTransformer.java
  Removed:     src/java/org/apache/cocoon/components/source
                        WriteableSAXSource.java
  Log:
  Trying to reduce deprecation dependencies
  
  Revision  Changes    Path
  1.23      +34 -42    
xml-cocoon2/src/java/org/apache/cocoon/components/source/SourceUtil.java
  
  Index: SourceUtil.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/source/SourceUtil.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- SourceUtil.java   26 Feb 2003 15:02:33 -0000      1.22
  +++ SourceUtil.java   27 Feb 2003 15:22:48 -0000      1.23
  @@ -64,7 +64,6 @@
   import org.apache.cocoon.xml.IncludeXMLConsumer;
   import org.apache.cocoon.xml.XMLUtils;
   import org.apache.cocoon.xml.dom.DOMBuilder;
  -import org.apache.cocoon.xml.dom.DOMStreamer;
   import org.apache.excalibur.source.ModifiableSource;
   import org.apache.excalibur.source.Source;
   import org.apache.excalibur.source.SourceException;
  @@ -404,46 +403,39 @@
   
                   frag.normalize();
   
  -                if (ws instanceof WriteableSAXSource) {
  -                    ContentHandler contentHandler = ((WriteableSAXSource) 
ws).getContentHandler();
  -                    DOMStreamer streamer = new DOMStreamer(contentHandler);
  -
  -                    streamer.stream(frag);
  -                } else {
  -                    // Lookup the Serializer
  -                    // FIXME (CZ) : Due to the CM hierarchy we don't get the
  -                    // correct serializer selector...
  -//                    ComponentSelector selector = null;
  -//                    Serializer serializer = null;
  -//                    OutputStream oStream = null;
  -//                    try {
  -//                        selector = 
(ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
  -//                        serializer = (Serializer)selector.select(serializerName);
  -//                        oStream = ws.getOutputStream();
  -//                        serializer.setOutputStream(oStream);
  -//                        DOMStreamer streamer = new DOMStreamer(serializer);
  -//                        streamer.stream(frag);
  -//                    } finally {
  -//                        if (oStream != null) {
  -//                            oStream.flush();
  -//                            try {
  -//                                oStream.close();
  -//                            } finally {
  -//                                if ( selector != null ) {
  -//                                    selector.release( serializer );
  -//                                    manager.release( selector );
  -//                                }
  -//                            }
  -//                        }
  -//                    }
  -                    final String content = XMLUtils.serializeNode(frag,
  -                                               
XMLUtils.defaultSerializeToXMLFormat(false));
  -                    OutputStream oStream = ws.getOutputStream();
  -
  -                    oStream.write(content.getBytes());
  -                    oStream.flush();
  -                    oStream.close();
  -                }
  +                // Lookup the Serializer
  +                // FIXME (CZ) : Due to the CM hierarchy we don't get the
  +                // correct serializer selector...
  +//                 ComponentSelector selector = null;
  +//                 Serializer serializer = null;
  +//                 OutputStream oStream = null;
  +//                 try {
  +//                     selector = (ComponentSelector)manager.lookup(Serializer.ROLE 
+ "Selector");
  +//                     serializer = (Serializer)selector.select(serializerName);
  +//                     oStream = ws.getOutputStream();
  +//                     serializer.setOutputStream(oStream);
  +//                     DOMStreamer streamer = new DOMStreamer(serializer);
  +//                     streamer.stream(frag);
  +//                } finally {
  +//                     if (oStream != null) {
  +//                         oStream.flush();
  +//                         try {
  +//                             oStream.close();
  +//                         } finally {
  +//                             if ( selector != null ) {
  +//                                 selector.release( serializer );
  +//                                 manager.release( selector );
  +//                             }
  +//                         }
  +//                     }
  +//                }
  +                final String content = XMLUtils.serializeNode(frag,
  +                                           
XMLUtils.defaultSerializeToXMLFormat(false));
  +                OutputStream oStream = ws.getOutputStream();
  +
  +                oStream.write(content.getBytes());
  +                oStream.flush();
  +                oStream.close();
               } else {
                   // and now serializing...
                   // Lookup the Serializer
  
  
  
  1.18      +39 -49    
xml-cocoon2/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java
  
  Index: SourceWritingTransformer.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SourceWritingTransformer.java     6 Feb 2003 12:19:46 -0000       1.17
  +++ SourceWritingTransformer.java     27 Feb 2003 15:22:48 -0000      1.18
  @@ -50,6 +50,10 @@
   */
   package org.apache.cocoon.transformation;
   
  +import java.io.IOException;
  +import java.io.OutputStream;
  +import java.util.Map;
  +
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentSelector;
  @@ -58,7 +62,6 @@
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.source.SourceUtil;
  -import org.apache.cocoon.components.source.WriteableSAXSource;
   import org.apache.cocoon.environment.SourceResolver;
   import org.apache.cocoon.serialization.Serializer;
   import org.apache.cocoon.xml.XMLUtils;
  @@ -73,13 +76,8 @@
   import org.w3c.dom.DocumentFragment;
   import org.w3c.dom.Node;
   import org.xml.sax.Attributes;
  -import org.xml.sax.ContentHandler;
   import org.xml.sax.SAXException;
   
  -import java.io.IOException;
  -import java.io.OutputStream;
  -import java.util.Map;
  -
   /**
   /**
    * This transformer allows you to output to a WriteableSource.
  @@ -718,53 +716,45 @@
               // write source
               if ( resource != null) {
                   resource.normalize();
  -                if (source instanceof WriteableSAXSource) {
  -                    ContentHandler contentHandler = 
((WriteableSAXSource)ws).getContentHandler();
  -                    DOMStreamer streamer = new DOMStreamer(contentHandler);
  -                    streamer.stream(resource);
  -                    localSerializer = "null";
  -                    failed = false;
  -                } else {
  -                    // use serializer
  -                    if (localSerializer == null) localSerializer = 
this.configuredSerializerName;
  -                    if (localSerializer != null) {
  -                        // Lookup the Serializer
  -                        ComponentSelector selector = null;
  -                        Serializer serializer = null;
  -                        OutputStream oStream = null;
  -                        try {
  -                            selector = 
(ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
  -                            serializer = 
(Serializer)selector.select(localSerializer);
  -                            oStream = ws.getOutputStream();
  -                            serializer.setOutputStream(oStream);
  -                            DOMStreamer streamer = new DOMStreamer(serializer);
  -                            streamer.stream(resource);
  -                        } finally {
  -                            if (oStream != null) {
  -                                oStream.flush();
  -                                try {
  -                                    oStream.close();
  -                                    failed = false;
  -                                } catch (Throwable t) {
  -                                    if (this.getLogger().isDebugEnabled() == true) {
  -                                        this.getLogger().debug("FAIL 
(oStream.close) exception"+t, t);
  -                                    }
  -                                    throw new ProcessingException("Could not 
process your document.", t);
  -                                } finally {
  -                                    if ( selector != null ) {
  -                                            selector.release( serializer );
  -                                            this.manager.release( selector );
  -                                    }
  +                // use serializer
  +                if (localSerializer == null) localSerializer = 
this.configuredSerializerName;
  +                if (localSerializer != null) {
  +                    // Lookup the Serializer
  +                    ComponentSelector selector = null;
  +                    Serializer serializer = null;
  +                    OutputStream oStream = null;
  +                    try {
  +                        selector = 
(ComponentSelector)manager.lookup(Serializer.ROLE + "Selector");
  +                        serializer = (Serializer)selector.select(localSerializer);
  +                        oStream = ws.getOutputStream();
  +                        serializer.setOutputStream(oStream);
  +                        DOMStreamer streamer = new DOMStreamer(serializer);
  +                        streamer.stream(resource);
  +                    } finally {
  +                        if (oStream != null) {
  +                            oStream.flush();
  +                            try {
  +                                oStream.close();
  +                                failed = false;
  +                            } catch (Throwable t) {
  +                                if (this.getLogger().isDebugEnabled() == true) {
  +                                    this.getLogger().debug("FAIL (oStream.close) 
exception"+t, t);
  +                                }
  +                                throw new ProcessingException("Could not process 
your document.", t);
  +                            } finally {
  +                                if ( selector != null ) {
  +                                        selector.release( serializer );
  +                                        this.manager.release( selector );
                                   }
                               }
                           }
  -                    } else {
  -                        if (this.getLogger().isDebugEnabled() == true) {
  -                            this.getLogger().debug("ERROR no serializer");
  -                        }
  -                        //throw new ProcessingException("No serializer specified 
for writing to source " + systemID);
  -                        message = "That source requires a serializer, please add 
the appropirate tag to your code.";
                       }
  +                } else {
  +                    if (this.getLogger().isDebugEnabled() == true) {
  +                        this.getLogger().debug("ERROR no serializer");
  +                    }
  +                    //throw new ProcessingException("No serializer specified for 
writing to source " + systemID);
  +                    message = "That source requires a serializer, please add the 
appropirate tag to your code.";
                   }
               }
           } catch (DOMException de) {
  
  
  

Reply via email to