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/components/source SourceUtil.java
Date Wed, 03 Sep 2003 15:00:57 GMT
cziegeler    2003/09/03 08:00:57

  Modified:    src/java/org/apache/cocoon/generation AbstractGenerator.java
                        DirectoryGenerator.java FileGenerator.java
                        JXTemplateGenerator.java ServletGenerator.java
                        StreamGenerator.java XPathDirectoryGenerator.java
                        StatusGenerator.java RequestGenerator.java
                        LinkStatusGenerator.java ComposerGenerator.java
               src/java/org/apache/cocoon/components/source SourceUtil.java
  Added:       src/java/org/apache/cocoon/generation
                        ServiceableGenerator.java
  Log:
  Moving to ServiceableGenerator
  
  Revision  Changes    Path
  1.2       +8 -3      cocoon-2.1/src/java/org/apache/cocoon/generation/AbstractGenerator.java
  
  Index: AbstractGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/AbstractGenerator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractGenerator.java	9 Mar 2003 00:09:31 -0000	1.1
  +++ AbstractGenerator.java	3 Sep 2003 15:00:56 -0000	1.2
  @@ -60,12 +60,17 @@
   import java.util.Map;
   
   /**
  - *
  + * An abstract class that can be used to implement an own generator.
  + * If you need other components, use the {@link ServiceableGenerator}
  + * instead.
  + * 
    * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation)
    * @version CVS $Id$
    */
  -public abstract class AbstractGenerator extends AbstractXMLProducer implements Generator
{
  +public abstract class AbstractGenerator 
  +    extends AbstractXMLProducer 
  +    implements Generator {
   
       /** The current <code>SourceResolver</code>. */
       protected SourceResolver resolver=null;
  
  
  
  1.8       +4 -2      cocoon-2.1/src/java/org/apache/cocoon/generation/DirectoryGenerator.java
  
  Index: DirectoryGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/DirectoryGenerator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DirectoryGenerator.java	2 Jul 2003 23:52:10 -0000	1.7
  +++ DirectoryGenerator.java	3 Sep 2003 15:00:56 -0000	1.8
  @@ -125,7 +125,9 @@
    *         (SMB GmbH) for Virbus AG
    * @version CVS $Id$
    */
  -public class DirectoryGenerator extends ComposerGenerator implements CacheableProcessingComponent
{
  +public class DirectoryGenerator 
  +    extends ServiceableGenerator 
  +    implements CacheableProcessingComponent {
   
       /** Constant for the file protocol. */
       private static final String FILE = "file:";
  
  
  
  1.4       +2 -3      cocoon-2.1/src/java/org/apache/cocoon/generation/FileGenerator.java
  
  Index: FileGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/FileGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileGenerator.java	16 May 2003 07:04:54 -0000	1.3
  +++ FileGenerator.java	3 Sep 2003 15:00:56 -0000	1.4
  @@ -65,7 +65,6 @@
   
   /**
    *
  - *
    * The <code>FileGenerator</code> is a class that reads XML from a source
    * and generates SAX Events.
    * The FileGenerator implements the <code>CacheableProcessingComponent</code>
interface.
  @@ -75,7 +74,7 @@
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @version CVS $Id$
    */
  -public class FileGenerator extends ComposerGenerator
  +public class FileGenerator extends ServiceableGenerator
   implements CacheableProcessingComponent {
   
       /** The input source */
  
  
  
  1.8       +1 -1      cocoon-2.1/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java
  
  Index: JXTemplateGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JXTemplateGenerator.java	28 Aug 2003 14:29:43 -0000	1.7
  +++ JXTemplateGenerator.java	3 Sep 2003 15:00:56 -0000	1.8
  @@ -334,7 +334,7 @@
    * &lt;/table&gt;
    * </pre></p>
    */
  -public class JXTemplateGenerator extends ComposerGenerator {
  +public class JXTemplateGenerator extends ServiceableGenerator {
   
       private static final JXPathContextFactory 
           jxpathContextFactory = JXPathContextFactory.newInstance();
  
  
  
  1.2       +9 -9      cocoon-2.1/src/java/org/apache/cocoon/generation/ServletGenerator.java
  
  Index: ServletGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/ServletGenerator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ServletGenerator.java	9 Mar 2003 00:09:31 -0000	1.1
  +++ ServletGenerator.java	3 Sep 2003 15:00:56 -0000	1.2
  @@ -71,17 +71,17 @@
    */
   public abstract class ServletGenerator extends ComposerGenerator {
   
  -    protected Request request=null;
  -    protected Response response=null;
  -    protected Context context=null;
  +    protected Request request;
  +    protected Response response;
  +    protected Context context;
   
       public void setup(SourceResolver resolver, Map objectModel, String src, Parameters
par)
  -        throws ProcessingException, SAXException, IOException {
  +    throws ProcessingException, SAXException, IOException {
   
  -      super.setup(resolver, objectModel, src, par);
  -      this.request = ObjectModelHelper.getRequest(objectModel);
  -      this.response = ObjectModelHelper.getResponse(objectModel);
  -      this.context = ObjectModelHelper.getContext(objectModel);
  +        super.setup(resolver, objectModel, src, par);
  +        this.request = ObjectModelHelper.getRequest(objectModel);
  +        this.response = ObjectModelHelper.getResponse(objectModel);
  +        this.context = ObjectModelHelper.getContext(objectModel);
       }
   
       /**
  
  
  
  1.4       +3 -4      cocoon-2.1/src/java/org/apache/cocoon/generation/StreamGenerator.java
  
  Index: StreamGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/StreamGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StreamGenerator.java	3 Sep 2003 13:35:20 -0000	1.3
  +++ StreamGenerator.java	3 Sep 2003 15:00:56 -0000	1.4
  @@ -50,7 +50,6 @@
   */
   package org.apache.cocoon.generation;
   
  -import org.apache.avalon.framework.component.Component;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.ResourceNotFoundException;
   import org.apache.cocoon.environment.ObjectModelHelper;
  @@ -90,7 +89,7 @@
    * @author <a href="mailto:Kinga_Dziembowski@hp.com">Kinga Dziembowski</a>
    * @version CVS $Id$
    */
  -public class StreamGenerator extends ComposerGenerator
  +public class StreamGenerator extends ServiceableGenerator
   {
       public static final String CLASS = StreamGenerator.class.getName();
   
  @@ -182,7 +181,7 @@
               getLogger().error("Could not get parser", e);
               throw new ProcessingException("Exception in StreamGenerator.generate()", e);
           } finally {
  -            this.manager.release( (Component)parser);
  +            this.manager.release( parser);
           }
       }
   
  
  
  
  1.3       +20 -5     cocoon-2.1/src/java/org/apache/cocoon/generation/XPathDirectoryGenerator.java
  
  Index: XPathDirectoryGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/XPathDirectoryGenerator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- XPathDirectoryGenerator.java	2 Jul 2003 23:58:11 -0000	1.2
  +++ XPathDirectoryGenerator.java	3 Sep 2003 15:00:56 -0000	1.3
  @@ -54,9 +54,9 @@
   import java.io.IOException;
   import java.util.Map;
   
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.components.source.SourceUtil;
   import org.apache.cocoon.environment.SourceResolver;
  @@ -161,12 +161,27 @@
           }
       }
   
  -    public void compose(ComponentManager manager) throws ComponentException {
  -        super.compose(manager);
  +    /**
  +     * Serviceable
  +     */
  +    public void service(ServiceManager manager) throws ServiceException {
  +        super.service(manager);
           this.processor = (XPathProcessor)manager.lookup(XPathProcessor.ROLE);
           this.parser = (DOMParser)manager.lookup(DOMParser.ROLE);
       }
   
  +    /**
  +     * Disposable
  +     */
  +    public void dispose() {
  +        if ( this.manager != null ) {
  +            this.manager.release( this.processor );
  +            this.manager.release( this.parser );
  +            this.processor = null;
  +            this.parser = null;
  +        }
  +        super.dispose();
  +    }
       /**
        * Extends the startNode() method of the DirectoryGenerator by starting
        * a possible XPath query on a file.
  
  
  
  1.2       +19 -9     cocoon-2.1/src/java/org/apache/cocoon/generation/StatusGenerator.java
  
  Index: StatusGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/StatusGenerator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- StatusGenerator.java	9 Mar 2003 00:09:31 -0000	1.1
  +++ StatusGenerator.java	3 Sep 2003 15:00:56 -0000	1.2
  @@ -50,8 +50,8 @@
   */
   package org.apache.cocoon.generation;
   
  -import org.apache.avalon.framework.component.ComponentException;
  -import org.apache.avalon.framework.component.ComponentManager;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.excalibur.store.Store;
   import org.apache.excalibur.store.StoreJanitor;
   import org.xml.sax.Attributes;
  @@ -95,7 +95,7 @@
    * @author <a href="mailto:g-froehlich@gmx.de">Gerhard Froehlich</a>
    * @version CVS $Id$
    */
  -public class StatusGenerator extends ComposerGenerator {
  +public class StatusGenerator extends ServiceableGenerator {
   
       /**
        * The StoreJanitor used to get cache statistics
  @@ -122,18 +122,28 @@
       protected static final String xlinkPrefix = "xlink";
   
       /**
  -     * Set the current <code>ComponentManager</code> instance used by this
  -     * <code>Composable</code>.
  +     * Set the current <code>ServiceManager</code> instance used by this
  +     * <code>Serviceable</code>.
        * Need to get statistics about cache hits
        */
  -    public void compose(ComponentManager manager) throws ComponentException {
  -        super.compose(manager);
  +    public void service(ServiceManager manager) throws ServiceException {
  +        super.service(manager);
           try {
               this.storejanitor = (StoreJanitor)manager.lookup(StoreJanitor.ROLE);
               this.store_persistent = (Store)this.manager.lookup(Store.PERSISTENT_STORE);
  -        } catch(ComponentException ce) {
  +        } catch(ServiceException ce) {
               getLogger().info("StoreJanitor is not available. Sorry, no cache statistics");
           }
  +    }
  +    
  +    public void dispose() {
  +        if ( this.manager != null ) {
  +            this.manager.release( this.store_persistent );
  +            this.manager.release( this.storejanitor );
  +            this.store_persistent = null;
  +            this.storejanitor = null;
  +        }
  +        super.dispose();
       }
   
       /** Generate the status information in XML format.
  
  
  
  1.4       +2 -2      cocoon-2.1/src/java/org/apache/cocoon/generation/RequestGenerator.java
  
  Index: RequestGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/RequestGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RequestGenerator.java	16 Jun 2003 23:46:10 -0000	1.3
  +++ RequestGenerator.java	3 Sep 2003 15:00:56 -0000	1.4
  @@ -252,7 +252,7 @@
           } catch (Exception e) {
               throw e;
           } finally {
  -            if (parser != null) manager.release((Component) parser);
  +            if (parser != null) manager.release( (Component)parser);
           }
       }
       
  
  
  
  1.4       +2 -2      cocoon-2.1/src/java/org/apache/cocoon/generation/LinkStatusGenerator.java
  
  Index: LinkStatusGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/LinkStatusGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LinkStatusGenerator.java	3 May 2003 04:41:22 -0000	1.3
  +++ LinkStatusGenerator.java	3 Sep 2003 15:00:56 -0000	1.4
  @@ -87,7 +87,7 @@
    * @author Bernhard Huber (huber@apache.org)
    * @version CVS $Id$
    */
  -public class LinkStatusGenerator extends ComposerGenerator implements Recyclable, Configurable
{
  +public class LinkStatusGenerator extends ServiceableGenerator implements Recyclable, Configurable
{
       /** The URI of the namespace of this generator. */
       protected static final String URI =
               "http://apache.org/cocoon/linkstatus/2.0";
  
  
  
  1.2       +5 -3      cocoon-2.1/src/java/org/apache/cocoon/generation/ComposerGenerator.java
  
  Index: ComposerGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/ComposerGenerator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ComposerGenerator.java	9 Mar 2003 00:09:31 -0000	1.1
  +++ ComposerGenerator.java	3 Sep 2003 15:00:56 -0000	1.2
  @@ -56,7 +56,9 @@
   import org.apache.avalon.framework.component.Composable;
   
   /**
  - *
  + * A default implementation that can be used for writing own generators.
  + * 
  + * @deprecated Use the {@link ServiceableGenerator} instead.
    * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
    *         (Apache Software Foundation)
    * @version CVS $Id$
  @@ -65,7 +67,7 @@
   implements Composable, Disposable {
   
       /** The component manager instance */
  -    protected ComponentManager manager = null;
  +    protected ComponentManager manager;
   
       /**
        * Set the current <code>ComponentManager</code> instance used by this
  
  
  
  1.1                  cocoon-2.1/src/java/org/apache/cocoon/generation/ServiceableGenerator.java
  
  Index: ServiceableGenerator.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.generation;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  
  /**
   * A default implementation that can be used for writing own generators.
   *  
   * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
   * @version CVS $Id: ServiceableGenerator.java,v 1.1 2003/09/03 15:00:56 cziegeler Exp $
   * @since 2.1.1
   */
  public abstract class ServiceableGenerator extends AbstractGenerator
  implements Serviceable, Disposable {
  
      /** The service manager instance */
      protected ServiceManager manager;
  
      /**
       * Set the current <code>ServiceManager</code> instance used by this
       * <code>Serviceable</code>.
       */
      public void service(ServiceManager manager) throws ServiceException {
          this.manager = manager;
      }
  
      /**
       * Release all resources.
       */
      public void dispose() {
          this.manager = null;
      }
  }
  
  
  
  1.7       +32 -1     cocoon-2.1/src/java/org/apache/cocoon/components/source/SourceUtil.java
  
  Index: SourceUtil.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/components/source/SourceUtil.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SourceUtil.java	16 May 2003 07:04:55 -0000	1.6
  +++ SourceUtil.java	3 Sep 2003 15:00:57 -0000	1.7
  @@ -61,6 +61,8 @@
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.component.ComponentSelector;
   import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.service.ServiceException;
  +import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.ResourceNotFoundException;
   import org.apache.cocoon.components.CocoonComponentManager;
  @@ -202,6 +204,35 @@
                   throw new ProcessingException("Exception during parsing source.", ce);
               } finally {
                   manager.release( (Component)parser );
  +            }
  +        }
  +    }
  +
  +    /**
  +     * Generates SAX events from the given source by parsing it.
  +     * <b>NOTE</b> : if the implementation can produce lexical events, care
should be taken
  +     * that <code>handler</code> can actually
  +     * directly implement the LexicalHandler interface!
  +     * @param  source    the data
  +     * @throws ProcessingException if no suitable converter is found
  +     */
  +    static public void parse( ServiceManager manager, 
  +                              Source source,
  +                              ContentHandler handler)
  +    throws SAXException, IOException, ProcessingException {
  +        if ( source instanceof XMLizable ) {
  +            ((XMLizable)source).toSAX( handler );
  +        } else {
  +            SAXParser parser = null;
  +            try {
  +                parser = (SAXParser) manager.lookup( SAXParser.ROLE);
  +                parser.parse( getInputSource( source ), handler );
  +            } catch (SourceException se) {
  +                throw SourceUtil.handle(se);
  +            } catch (ServiceException ce) {
  +                throw new ProcessingException("Exception during parsing source.", ce);
  +            } finally {
  +                manager.release( parser );
               }
           }
       }
  
  
  

Mime
View raw message