You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2001/07/09 15:20:02 UTC

cvs commit: xml-cocoon2/src/org/apache/cocoon/components/source SitemapSource.java

cziegeler    01/07/09 06:20:02

  Modified:    src/org/apache/cocoon Cocoon.java Processor.java
               src/org/apache/cocoon/components/pipeline
                        AbstractEventPipeline.java
                        CachingEventPipeline.java EventPipeline.java
                        NonCachingEventPipeline.java StreamPipeline.java
               src/org/apache/cocoon/components/source SitemapSource.java
  Added:       src/org/apache/cocoon ProcessorWrapper.java
  Log:
  Next step to the working cocoon:// url.
  Added a processor for the root sitemap to the component manager.
  
  Revision  Changes    Path
  1.16      +5 -1      xml-cocoon2/src/org/apache/cocoon/Cocoon.java
  
  Index: Cocoon.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/Cocoon.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Cocoon.java	2001/07/07 11:43:11	1.15
  +++ Cocoon.java	2001/07/09 13:19:47	1.16
  @@ -57,7 +57,7 @@
    *
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a> (Apache Software Foundation, Exoffice Technologies)
    * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
  - * @version CVS $Revision: 1.15 $ $Date: 2001/07/07 11:43:11 $
  + * @version CVS $Revision: 1.16 $ $Date: 2001/07/09 13:19:47 $
    */
   public class Cocoon extends AbstractLoggable implements ThreadSafe, Component, Initializable, Disposable, Modifiable, Processor, Contextualizable {
       /** The application context */
  @@ -303,6 +303,10 @@
   
           getLogger().debug("Setting up components...");
           this.componentManager.configure(conf);
  +
  +        // adding the processor itself to the available components
  +        // we need a wrapper to avoid infinite dispose loops
  +        this.componentManager.addComponentInstance(Processor.ROLE, new ProcessorWrapper(this));
   
           return conf;
       }
  
  
  
  1.2       +15 -1     xml-cocoon2/src/org/apache/cocoon/Processor.java
  
  Index: Processor.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/Processor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Processor.java	2001/05/09 20:49:27	1.1
  +++ Processor.java	2001/07/09 13:19:48	1.2
  @@ -7,18 +7,32 @@
    *****************************************************************************/
   package org.apache.cocoon;
   
  +import org.apache.cocoon.components.pipeline.EventPipeline;
  +import org.apache.cocoon.components.pipeline.StreamPipeline;
   import org.apache.cocoon.environment.Environment;
   
   /**
    *
    * @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation, Exoffice Technologies)
  - * @version CVS $Revision: 1.1 $ $Date: 2001/05/09 20:49:27 $
  + * @version CVS $Revision: 1.2 $ $Date: 2001/07/09 13:19:48 $
    */
   public interface Processor {
  +
  +    String ROLE = "org.apache.cocoon.Processor";
  +
       /**
        * Process the given <code>Environment</code> producing the output
        */
       boolean process(Environment environment)
  +    throws Exception;
  +
  +    /**
  +     * Process the given <code>Environment</code> to assemble
  +     * a <code>StreamPipeline</code> and an <code>EventPipeline</code>.
  +     */
  +    boolean process(Environment environment,
  +                    StreamPipeline pipeline,
  +                    EventPipeline eventPipeline)
       throws Exception;
   }
  
  
  
  1.1                  xml-cocoon2/src/org/apache/cocoon/ProcessorWrapper.java
  
  Index: ProcessorWrapper.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;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.Component;
  import org.apache.avalon.framework.thread.ThreadSafe;
  import org.apache.cocoon.components.pipeline.EventPipeline;
  import org.apache.cocoon.components.pipeline.StreamPipeline;
  import org.apache.cocoon.environment.Environment;
  
  /**
   * This class is a wrapper around the real processor (the <code>Cocoon</code> class).
   * It is necessary to avoid infinite dispose loops
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/07/09 13:19:49 $
   */
  public final class ProcessorWrapper
  implements Processor, Component, Disposable, ThreadSafe {
  
      private Processor processor;
  
      public void dispose() {
          this.processor = null;
      }
  
      public ProcessorWrapper(Processor processor) {
          this.processor = processor;
      }
  
      /**
       * Process the given <code>Environment</code> producing the output
       */
      public boolean process(Environment environment)
      throws Exception {
          return this.processor.process(environment);
      }
  
      /**
       * Process the given <code>Environment</code> to assemble
       * a <code>StreamPipeline</code> and an <code>EventPipeline</code>.
       */
      public boolean process(Environment environment,
                             StreamPipeline pipeline,
                             EventPipeline eventPipeline)
      throws Exception {
          return this.processor.process(environment, pipeline, eventPipeline);
      }
  }
  
  
  
  1.12      +1 -2      xml-cocoon2/src/org/apache/cocoon/components/pipeline/AbstractEventPipeline.java
  
  Index: AbstractEventPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/pipeline/AbstractEventPipeline.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AbstractEventPipeline.java	2001/07/07 11:43:23	1.11
  +++ AbstractEventPipeline.java	2001/07/09 13:19:51	1.12
  @@ -18,7 +18,6 @@
   import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.Processor;
   import org.apache.cocoon.components.saxconnector.SAXConnector;
   import org.apache.cocoon.components.saxconnector.NullSAXConnector;
   import org.apache.cocoon.environment.Environment;
  @@ -33,7 +32,7 @@
   /**
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
    * @author <a href="mailto:cziegeler@Carsten Ziegeler">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.11 $ $Date: 2001/07/07 11:43:23 $
  + * @version CVS $Revision: 1.12 $ $Date: 2001/07/09 13:19:51 $
    */
   public abstract class AbstractEventPipeline
   extends AbstractXMLProducer
  
  
  
  1.15      +1 -2      xml-cocoon2/src/org/apache/cocoon/components/pipeline/CachingEventPipeline.java
  
  Index: CachingEventPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/pipeline/CachingEventPipeline.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- CachingEventPipeline.java	2001/07/07 11:43:23	1.14
  +++ CachingEventPipeline.java	2001/07/09 13:19:52	1.15
  @@ -20,7 +20,6 @@
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.excalibur.pool.Recyclable;
   import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.Processor;
   import org.apache.cocoon.caching.CacheValidity;
   import org.apache.cocoon.caching.Cacheable;
   import org.apache.cocoon.caching.CachedEventObject;
  @@ -51,7 +50,7 @@
    * does not cache! (If it would cache, the response would be cached twice!)
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.14 $ $Date: 2001/07/07 11:43:23 $
  + * @version CVS $Revision: 1.15 $ $Date: 2001/07/09 13:19:52 $
    */
   public class CachingEventPipeline
   extends AbstractEventPipeline
  
  
  
  1.6       +8 -4      xml-cocoon2/src/org/apache/cocoon/components/pipeline/EventPipeline.java
  
  Index: EventPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/pipeline/EventPipeline.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EventPipeline.java	2001/07/07 11:43:24	1.5
  +++ EventPipeline.java	2001/07/09 13:19:53	1.6
  @@ -10,7 +10,6 @@
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.parameters.Parameters;
  -import org.apache.cocoon.Processor;
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.generation.Generator;
   import org.apache.cocoon.sitemap.Sitemap;
  @@ -18,15 +17,20 @@
   
   /**
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.5 $ $Date: 2001/07/07 11:43:24 $
  + * @version CVS $Revision: 1.6 $ $Date: 2001/07/09 13:19:53 $
    */
  -public interface EventPipeline extends Component, Composable, Recyclable, Processor {
  +public interface EventPipeline extends Component, Composable, Recyclable {
   
       String ROLE = "org.apache.cocoon.components.pipeline.EventPipeline";
   
  +    /**
  +     * Process the given <code>Environment</code> producing the output
  +     */
  +    boolean process(Environment environment)
  +    throws Exception;
  +
       void setGenerator (String role, String source, Parameters param, Exception e) throws Exception;
       void setGenerator (String role, String source, Parameters param) throws Exception;
       Generator getGenerator ();
       void addTransformer (String role, String source, Parameters param) throws Exception;
  -    boolean process(Environment environment) throws Exception;
   }
  
  
  
  1.6       +1 -2      xml-cocoon2/src/org/apache/cocoon/components/pipeline/NonCachingEventPipeline.java
  
  Index: NonCachingEventPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/pipeline/NonCachingEventPipeline.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- NonCachingEventPipeline.java	2001/07/07 11:43:24	1.5
  +++ NonCachingEventPipeline.java	2001/07/09 13:19:54	1.6
  @@ -17,7 +17,6 @@
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.excalibur.pool.Recyclable;
   import org.apache.cocoon.ProcessingException;
  -import org.apache.cocoon.Processor;
   import org.apache.cocoon.environment.Environment;
   import org.apache.cocoon.generation.Generator;
   import org.apache.cocoon.sitemap.ErrorNotifier;
  @@ -29,7 +28,7 @@
   
   /**
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.5 $ $Date: 2001/07/07 11:43:24 $
  + * @version CVS $Revision: 1.6 $ $Date: 2001/07/09 13:19:54 $
    */
   public class NonCachingEventPipeline extends AbstractEventPipeline implements Recyclable {
   
  
  
  
  1.5       +32 -3     xml-cocoon2/src/org/apache/cocoon/components/pipeline/StreamPipeline.java
  
  Index: StreamPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/pipeline/StreamPipeline.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- StreamPipeline.java	2001/07/07 11:43:24	1.4
  +++ StreamPipeline.java	2001/07/09 13:19:55	1.5
  @@ -10,8 +10,8 @@
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.Composable;
   import org.apache.avalon.framework.parameters.Parameters;
  -import org.apache.cocoon.Processor;
   import org.apache.avalon.excalibur.pool.Recyclable;
  +import org.apache.cocoon.environment.Environment;
   
   /** A <CODE>StreamPipeline</CODE> either
    * <UL>
  @@ -20,16 +20,45 @@
    *  <CODE>Serializer</CODE> and let them produce the character stream
    * </UL>
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
  - * @version CVS $Revision: 1.4 $ $Date: 2001/07/07 11:43:24 $
  + * @version CVS $Revision: 1.5 $ $Date: 2001/07/09 13:19:55 $
    */
  -public interface StreamPipeline extends Component, Composable, Recyclable, Processor {
  +public interface StreamPipeline extends Component, Composable, Recyclable {
   
       String ROLE = "org.apache.cocoon.components.pipeline.StreamPipeline";
   
  +    /**
  +     * Process the given <code>Environment</code> producing the output
  +     */
  +    boolean process(Environment environment)
  +    throws Exception;
  +
  +    /**
  +     * Set the <code>EventPipeline</code>
  +     */
       void setEventPipeline (EventPipeline eventPipeline) throws Exception;
  +
  +    /**
  +     * Get the <code>EventPipeline</code>
  +     */
       EventPipeline getEventPipeline ();
  +
  +    /**
  +     * Set the reader for this pipeline
  +     */
       void setReader (String role, String source, Parameters param) throws Exception;
  +
  +    /**
  +     * Set the reader for this pipeline
  +     */
       void setReader (String role, String source, Parameters param, String mimeType) throws Exception;
  +
  +    /**
  +     * Set the serializer for this pipeline
  +     */
       void setSerializer (String role, String source, Parameters param) throws Exception;
  +
  +    /**
  +     * Set the serializer for this pipeline
  +     */
       void setSerializer (String role, String source, Parameters param, String mimeType) throws Exception;
   }
  
  
  
  1.7       +27 -8     xml-cocoon2/src/org/apache/cocoon/components/source/SitemapSource.java
  
  Index: SitemapSource.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/source/SitemapSource.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SitemapSource.java	2001/07/07 11:43:26	1.6
  +++ SitemapSource.java	2001/07/09 13:20:00	1.7
  @@ -22,6 +22,7 @@
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.cocoon.Constants;
  +import org.apache.cocoon.Processor;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.pipeline.EventPipeline;
   import org.apache.cocoon.components.pipeline.StreamPipeline;
  @@ -42,7 +43,7 @@
    * Description of a source which is defined by a pipeline.
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Revision: 1.6 $ $Date: 2001/07/07 11:43:26 $
  + * @version CVS $Revision: 1.7 $ $Date: 2001/07/09 13:20:00 $
    */
   
   public final class SitemapSource
  @@ -63,8 +64,8 @@
       /** The current ComponentManager */
       private ComponentManager manager;
   
  -    /** The sitemap */
  -    private Sitemap sitemap;
  +    /** The processor */
  +    private Processor processor;
   
       /** The environment */
       private Environment environment;
  @@ -78,6 +79,9 @@
                            String           uri)
       throws IOException, ProcessingException {
   
  +        this.manager = manager;
  +        this.environment = env;
  +
           // remove the protocol
           int protocolEnd = uri.indexOf(':');
           if (protocolEnd != -1) {
  @@ -89,8 +93,16 @@
               uri = uri.substring(2);
               // FIXME (CZ) The root sitemap is not available
               // so resolve it to the current sitemap
  +            Processor processor = null;
  +            try {
  +                processor = (Processor)this.manager.lookup(Processor.ROLE);
  +            } catch (ComponentException e) {
  +                throw new ProcessingException("Cannot get Processor instance", e);
  +            }
  +            this.processor = processor;
           } else if (uri.startsWith("/") == true) {
               uri = uri.substring(1);
  +            this.processor = sitemap;
           }
   
           Request request= (Request)env.getObjectModel().get(Constants.REQUEST_OBJECT);
  @@ -101,9 +113,6 @@
           this.uri = uri;
           this.contentLength = -1;
           this.lastModificationDate = 0;
  -        this.manager = manager;
  -        this.sitemap = sitemap;
  -        this.environment = env;
       }
   
       /**
  @@ -144,7 +153,12 @@
   
               try {
                   this.environment.pushURI(this.uri);
  -                this.sitemap.process(this.environment, pipeline, eventPipeline);
  +                this.processor.process(this.environment, pipeline, eventPipeline);
  +            } finally {
  +                this.environment.popURI();
  +            }
  +            try {
  +                this.environment.pushURI(this.uri);
                   ((XMLProducer)eventPipeline).setConsumer(serializer);
                   eventPipeline.process(this.environment);
               } finally {
  @@ -222,8 +236,13 @@
               pipeline.setEventPipeline(eventPipeline);
   
               try {
  +                this.environment.pushURI(this.uri);
  +                this.processor.process(this.environment, pipeline, eventPipeline);
  +            } finally {
  +                this.environment.popURI();
  +            }
  +            try {
                   this.environment.pushURI(this.uri);
  -                this.sitemap.process(this.environment, pipeline, eventPipeline);
                   ((XMLProducer)eventPipeline).setConsumer(consumer);
                   eventPipeline.process(this.environment);
               } finally {
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org