cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: cocoon-2.1/src/java/org/apache/cocoon/transformation SourceWritingTransformer.java
Date Wed, 12 Mar 2003 15:35:11 GMT
cziegeler    2003/03/12 07:35:11

  Modified:    src/java/org/apache/cocoon/transformation/helpers
                        DefaultIncludeCacheManager.java
                        PreemptiveLoader.java
               src/java/org/apache/cocoon/transformation
                        SourceWritingTransformer.java
  Log:
  Reverting
  
  Revision  Changes    Path
  1.4       +3 -3      cocoon-2.1/src/java/org/apache/cocoon/transformation/helpers/DefaultIncludeCacheManager.java
  
  Index: DefaultIncludeCacheManager.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/helpers/DefaultIncludeCacheManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DefaultIncludeCacheManager.java	12 Mar 2003 15:05:17 -0000	1.3
  +++ DefaultIncludeCacheManager.java	12 Mar 2003 15:35:10 -0000	1.4
  @@ -377,7 +377,7 @@
                   serializer = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
                   XMLTeePipe tee = new XMLTeePipe(handler, serializer);
                   
  -                SourceUtil.toSAX(source, tee, manager);
  +                SourceUtil.toSAX(source, tee);
                   
                   SourceValidity[] validities = new SourceValidity[1];
                   validities[0] = session.getExpiresValidity();
  @@ -385,7 +385,7 @@
                                                                (byte[])serializer.getSAXFragment());
                   session.getCacheStorageProxy().put(uri, response);
               } else {
  -                SourceUtil.toSAX(source, handler, manager);
  +                SourceUtil.toSAX(source, handler);
               }
               
           } catch (ProcessingException pe) {
  @@ -464,7 +464,7 @@
       
       public void run() {
           try {
  -            SourceUtil.toSAX(this.source, this.serializer, this.manager);
  +            SourceUtil.toSAX(this.source, this.serializer);
               this.content = (byte[])this.serializer.getSAXFragment();
           } catch (Exception local) {
               this.exception = local;
  
  
  
  1.3       +1 -1      cocoon-2.1/src/java/org/apache/cocoon/transformation/helpers/PreemptiveLoader.java
  
  Index: PreemptiveLoader.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/helpers/PreemptiveLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PreemptiveLoader.java	12 Mar 2003 15:05:17 -0000	1.2
  +++ PreemptiveLoader.java	12 Mar 2003 15:35:11 -0000	1.3
  @@ -155,7 +155,7 @@
                       source = resolver.resolveURI(uri);
                       serializer = (XMLSerializer)manager.lookup(XMLSerializer.ROLE);
                   
  -                    SourceUtil.toSAX(source, serializer, manager);
  +                    SourceUtil.toSAX(source, serializer);
                   
                       SourceValidity[] validities = new SourceValidity[1];
                       validities[0] = new ExpiresValidity(((Long)object[2]).longValue() *
1000); // milliseconds!
  
  
  
  1.3       +57 -118   cocoon-2.1/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java
  
  Index: SourceWritingTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/transformation/SourceWritingTransformer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SourceWritingTransformer.java	12 Mar 2003 15:05:17 -0000	1.2
  +++ SourceWritingTransformer.java	12 Mar 2003 15:35:11 -0000	1.3
  @@ -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,16 +76,11 @@
   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.
  + * This transformer allows you to output to a ModifiableSource.
    *
    * <p>Definition:</p>
    * <pre>
  @@ -348,30 +346,11 @@
                                 ", name=" + name + ", raw=" + raw + ", attr=" + attr);
           }
           // Element: insert
  -        if (name.equals(INSERT_ELEMENT)
  -            && this.state == STATE_OUTSIDE) {
  -            this.state = STATE_INSERT;
  -            this.parent_state = STATE_INSERT;
  -            if (attr.getValue(CREATE_ATTRIBUTE) != null
  -                && attr.getValue(CREATE_ATTRIBUTE).equals("false")) {
  -                this.stack.push("false");
  -            } else {
  -                this.stack.push("true");
  -            }
  -            if (attr.getValue(OVERWRITE_ATTRIBUTE) != null
  -                && attr.getValue(OVERWRITE_ATTRIBUTE).equals("false")) {
  -                this.stack.push("false");
  -            } else {
  -                this.stack.push("true");
  -            }
  -            this.stack.push(attr.getValue(SERIALIZER_ATTRIBUTE));
  -            this.stack.push("INSERT");
  +        if (this.state == STATE_OUTSIDE 
  +            && (name.equals(INSERT_ELEMENT) || name.equals(WRITE_ELEMENT))) {
   
  -        // Element: write
  -        } else if (name.equals(WRITE_ELEMENT)
  -            && this.state == STATE_OUTSIDE) {
  -            this.state = STATE_WRITE;
  -            this.parent_state = STATE_WRITE;
  +            this.state = (name.equals(INSERT_ELEMENT) ? STATE_INSERT : STATE_WRITE);
  +            this.parent_state = this.state;
               if (attr.getValue(CREATE_ATTRIBUTE) != null
                   && attr.getValue(CREATE_ATTRIBUTE).equals("false")) {
                   this.stack.push("false");
  @@ -385,7 +364,7 @@
                   this.stack.push("true"); // default value
               }
               this.stack.push(attr.getValue(SERIALIZER_ATTRIBUTE));
  -            this.stack.push("WRITE");
  +            this.stack.push("END");
   
           // Element: file
           } else if (name.equals(SOURCE_ELEMENT)
  @@ -445,21 +424,23 @@
                                 ", name=" + name +
                                 ", raw=" + raw);
           }
  -        if (name.equals(INSERT_ELEMENT) == true && this.state == STATE_INSERT)
{
  +        if ((name.equals(INSERT_ELEMENT) && this.state == STATE_INSERT)
  +            || (name.equals(WRITE_ELEMENT) && this.state == STATE_WRITE)) {
   
               // get the information from the stack
  -            String tag;
  -            String     fileName        = null;
               DocumentFragment fragment  = null;
  -            String     path            = null;
  -            String     replacePath     = null;
  -            String     reinsert        = null;
  +            String tag;
  +            String sourceName    = null;
  +            String path        = (this.state == STATE_INSERT ? null : "/");
  +                                 // source:write's path can be empty
  +            String replacePath = null;
  +            String reinsert    = null;
               do {
                   tag = (String)this.stack.pop();
                   if (tag.equals("PATH") == true) {
                       path = (String)this.stack.pop();
                   } else if (tag.equals("FILE") == true) {
  -                    fileName = (String)this.stack.pop();
  +                    sourceName = (String)this.stack.pop();
                   } else if (tag.equals("FRAGMENT") == true) {
                       fragment = (DocumentFragment)this.stack.pop();
                   } else if (tag.equals("REPLACE") == true) {
  @@ -467,47 +448,13 @@
                   } else if (tag.equals("REINSERT") == true) {
                       reinsert = (String)this.stack.pop();
                   }
  -            } while (tag.equals("INSERT") == false);
  -            final String localSerializer = (String)this.stack.pop();
  -            final boolean overwrite = this.stack.pop().equals("true");
  -            final boolean create = this.stack.pop().equals("true");
  +            } while ( !tag.equals("END") );
   
  -            this.insertFragment(fileName,
  -                                    path,
  -                                    fragment,
  -                                    replacePath,
  -                                    create,
  -                                    overwrite,
  -                                    reinsert,
  -                                    localSerializer,
  -                                    name);
  -
  -            this.state = STATE_OUTSIDE;
  -
  -        } else if (name.equals(WRITE_ELEMENT) == true && this.state == STATE_WRITE)
{
  -
  -            // get the information from the stack
  -            String tag;
  -            String     fileName        = null;
  -            DocumentFragment fragment  = null;
  -            String     path            = "/"; // source:write's path can be empty
  -            String     replacePath     = null;
  -            String     reinsert        = null;
  -            do {
  -                tag = (String)this.stack.pop();
  -                if (tag.equals("PATH") == true) {
  -                    path = (String)this.stack.pop();
  -                } else if (tag.equals("FILE") == true) {
  -                    fileName = (String)this.stack.pop();
  -                } else if (tag.equals("FRAGMENT") == true) {
  -                    fragment = (DocumentFragment)this.stack.pop();
  -                }
  -            } while (tag.equals("WRITE") == false);
               final String localSerializer = (String)this.stack.pop();
               final boolean overwrite = this.stack.pop().equals("true");
               final boolean create = this.stack.pop().equals("true");
   
  -            this.insertFragment(fileName,
  +            this.insertFragment(sourceName,
                                       path,
                                       fragment,
                                       replacePath,
  @@ -634,7 +581,7 @@
               target = source.getURI();
               if ( exists == true && this.state == STATE_INSERT ) {
                                   message = "content inserted at: " + path;
  -                resource = SourceUtil.toDOM( source, this.manager );
  +                resource = SourceUtil.toDOM( source );
                   // import the fragment
                   Node importNode = resource.importNode(fragment, true);
                   // get the node
  @@ -718,53 +665,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) {
  
  
  

Mime
View raw message