cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: rev 43562 - in cocoon/trunk/src/java/org/apache/cocoon/components: container flow flow/util source/impl
Date Thu, 09 Sep 2004 02:29:47 GMT
Author: vgritsenko
Date: Wed Sep  8 19:29:46 2004
New Revision: 43562

Modified:
   cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonComponentManager.java
   cocoon/trunk/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
   cocoon/trunk/src/java/org/apache/cocoon/components/flow/util/PipelineUtil.java
   cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
Log:
pipelineutil: close input stream


Modified: cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonComponentManager.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonComponentManager.java
(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonComponentManager.java
Wed Sep  8 19:29:46 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -40,17 +40,16 @@
  *
  * @author <a href="mailto:bluetkemeier@s-und-n.de">Bj&ouml;rn L&uuml;tkemeier</a>
  * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Id: CocoonComponentManager.java,v 1.3 2004/07/14 19:39:10 cziegeler Exp
$
+ * @version CVS $Id$
  */
-public final class CocoonComponentManager
-extends ExcaliburComponentManager {
- 
+public final class CocoonComponentManager extends ExcaliburComponentManager {
+
     /** The {@link SitemapConfigurationHolder}s */
     private Map sitemapConfigurationHolders = new HashMap(15);
-    
+
     /** The parent component manager for implementing parent aware components */
     private ComponentManager parentManager;
-    
+
     /** Temporary list of parent-aware components.  Will be null for most of
      * our lifecycle. */
     private ArrayList parentAwareComponents = new ArrayList();
@@ -67,13 +66,13 @@
 
     /** Create the ComponentManager with a Classloader and parent ComponentManager */
     public CocoonComponentManager(final ComponentManager manager, final ClassLoader loader)
{
-        super( manager, loader );
+        super(manager, loader);
         this.parentManager = manager;
     }
 
     /** Create the ComponentManager with a parent ComponentManager */
     public CocoonComponentManager(final ComponentManager manager) {
-        super( manager);
+        super(manager);
         this.parentManager = manager;
     }
 
@@ -82,9 +81,10 @@
      * Fully Qualified Name(FQN)--unless there are multiple Components for the same Role.
 In that
      * case, the Role's FQN is appended with "Selector", and we return a ComponentSelector.
      */
-    public Component lookup( final String role )
+    public Component lookup(final String role)
     throws ComponentException {
-        if( null == role ) {
+
+        if(null == role) {
             final String message =
                 "ComponentLocator Attempted to retrieve component with null role.";
 
@@ -96,7 +96,7 @@
 
             // FIXME: how can we prevent that this is called over and over again?
             SitemapConfigurationHolder holder;
-            
+
             holder = (SitemapConfigurationHolder)this.sitemapConfigurationHolders.get( role
);
             if ( null == holder ) {
                 // create new holder
@@ -110,6 +110,7 @@
                 throw new ComponentException(role, "Exception during setup of SitemapConfigurable.",
ce);
             }
         }
+
         return component;
     }
 
@@ -117,7 +118,8 @@
      * @see org.apache.avalon.excalibur.component.ExcaliburComponentManager#addComponent(java.lang.String,
java.lang.Class, org.apache.avalon.framework.configuration.Configuration)
      */
     public void addComponent(String role, Class clazz, Configuration conf)
-        throws ComponentException {
+    throws ComponentException {
+
         super.addComponent(role, clazz, conf);
         // Note that at this point, we're not initialized and cannot do
         // lookups, so defer parental introductions to initialize().
@@ -126,10 +128,9 @@
         }
     }
 
-    public void initialize()
-        throws Exception
-    {
+    public void initialize() throws Exception {
         super.initialize();
+
         if (parentAwareComponents == null) {
             throw new ComponentException(null, "CocoonComponentManager already initialized");
         }
@@ -154,4 +155,3 @@
         parentAwareComponents = null;  // null to save memory, and catch logic bugs.
     }
 }
-

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java	Wed Sep
 8 19:29:46 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -53,18 +53,18 @@
  *
  * @author <a href="mailto:ovidiu@cup.hp.com">Ovidiu Predescu</a>
  * @since March 15, 2002
- * @version CVS $Id: AbstractInterpreter.java,v 1.22 2004/07/07 05:56:04 sylvain Exp $
+ * @version CVS $Id$
  */
 public abstract class AbstractInterpreter extends AbstractLogEnabled
   implements Component, Serviceable, Contextualizable, Interpreter,
              SingleThreaded, Configurable, Disposable
 {
-    // The instance counters, used to produce unique IDs 
+    // The instance counters, used to produce unique IDs
     private static int instanceCounter = 0;
-    
+
     // The instance ID of this interpreter, used to identify user scopes
     private String instanceID;
-    
+
     protected org.apache.avalon.framework.context.Context avalonContext;
 
     /**
@@ -75,7 +75,7 @@
     protected org.apache.cocoon.environment.Context context;
     protected ServiceManager manager;
     protected ContinuationsManager continuationsMgr;
-    
+
     /**
      * Whether reloading of scripts should be done. Specified through
      * the "reload-scripts" attribute in <code>flow.xmap</code>.
@@ -94,11 +94,11 @@
             this.instanceID = String.valueOf(instanceCounter);
         }
     }
-    
+
     /**
      * Get the unique ID for this interpreter, which can be used to distinguish user value
scopes
      * attached to the session.
-     * 
+     *
      * @return a unique ID for this interpreter
      */
     protected String getInterpreterID() {
@@ -179,8 +179,7 @@
      * @exception Exception If an error occurs.
      */
     public void process(String uri, Object biz, OutputStream out)
-        throws Exception 
-    {
+    throws Exception {
         // FIXME (SW): should we deprecate this method in favor of PipelineUtil?
         PipelineUtil pipeUtil = new PipelineUtil();
         try {
@@ -195,8 +194,7 @@
     public void forwardTo(String uri, Object bizData,
                           WebContinuation continuation,
                           Redirector redirector)
-        throws Exception
-    {
+    throws Exception {
         if (SourceUtil.indexOfSchemeColon(uri) == -1) {
             uri = "cocoon:/" + uri;
             Map objectModel = ContextHelper.getObjectModel(this.avalonContext);

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/flow/util/PipelineUtil.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/flow/util/PipelineUtil.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/flow/util/PipelineUtil.java	Wed Sep
 8 19:29:46 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -42,12 +42,12 @@
  * Utility class to process a pipeline to various destinations.
  * This class must be setup from the flowscript before being used. This means that instances
must
  * be created with <code>cocoon.createObject(Packages.org.apache.cocoon.components.flow.util.PipelineUtil);
- * 
+ *
  * @author <a href="http://www.apache.org/~sylvain/">Sylvain Wallez</a>
- * @version CVS $Id: PipelineUtil.java,v 1.3 2004/05/04 11:54:35 cziegeler Exp $
+ * @version CVS $Id$
  */
 public class PipelineUtil implements Contextualizable, Serviceable, Disposable {
-    
+
     private Context context;
     private ServiceManager manager;
     private SourceResolver resolver;
@@ -56,23 +56,23 @@
      * @see org.apache.avalon.framework.activity.Disposable#dispose()
      */
     public void dispose() {
-        if ( this.manager != null ) {
-            this.manager.release( this.resolver );
+        if (this.manager != null) {
+            this.manager.release(this.resolver);
             this.manager = null;
             this.resolver = null;
         }
     }
-    
+
     public void contextualize(Context context) throws ContextException {
         this.context = context;
-        
+
     }
 
     public void service(ServiceManager manager) throws ServiceException {
         this.manager = manager;
         this.resolver = (SourceResolver)manager.lookup(SourceResolver.ROLE);
     }
-    
+
     /**
      * Check that this object has been correctly set up.
      *
@@ -80,36 +80,42 @@
      */
     private void checkSetup() {
         if (this.manager == null) {
-            throw new IllegalStateException("Instances of " + this.getClass().getName() +
-                " must be setup using either cocoon.createObject() or cocoon.setupObject().");
+            throw new IllegalStateException("Instances of " + getClass().getName() +
+                                            " must be setup using either cocoon.createObject()
or cocoon.setupObject().");
         }
     }
-    
+
     /**
      * Process a pipeline to a stream.
-     * 
+     *
      * @param uri the pipeline URI
      * @param viewData the view data object
      * @param output the stream where pipeline result is output. Note: this stream is not
closed.
      * @throws IOException
      */
-    public void processToStream(String uri, Object viewData, OutputStream output) throws
IOException {
+    public void processToStream(String uri, Object viewData, OutputStream output)
+    throws IOException {
         checkSetup();
-        
+
         Map objectModel = ContextHelper.getObjectModel(this.context);
 
         // Keep the previous view data, if any (is it really necessary?), and set the new
one
         Object oldViewData = FlowHelper.getContextObject(objectModel);
         FlowHelper.setContextObject(objectModel, FlowHelper.unwrap(viewData));
-        
+
         Source src = null;
-        
+        InputStream input = null;
         try {
             src = this.resolver.resolveURI("cocoon:/" + uri);
-            InputStream input = src.getInputStream();
-            
+            input = src.getInputStream();
             IOUtil.copy(input, output);
         } finally {
+            if (input != null) {
+                try {
+                    input.close();
+                } catch (IOException ignored) {}
+            }
+
             // Restore the previous view data
             FlowHelper.setContextObject(objectModel, oldViewData);
 
@@ -118,23 +124,23 @@
             }
         }
     }
-    
+
     /**
      * Process a pipeline to a SAX <code>ContentHandler</code>
-     * 
+     *
      * @param uri the pipeline URI
      * @param viewData the view data object
      * @param handler where the pipeline should be streamed to.
      */
-    public void processToSAX(String uri, Object viewData, ContentHandler handler) throws
SAXException, IOException, ProcessingException {
+    public void processToSAX(String uri, Object viewData, ContentHandler handler)
+    throws SAXException, IOException, ProcessingException {
         checkSetup();
-        
+
         Map objectModel = ContextHelper.getObjectModel(this.context);
         Object oldViewData = FlowHelper.getContextObject(objectModel);
         FlowHelper.setContextObject(objectModel, FlowHelper.unwrap(viewData));
-        
+
         Source src = null;
-        
         try {
             src = this.resolver.resolveURI("cocoon:/" + uri);
             SourceUtil.toSAX(src, handler);
@@ -145,23 +151,23 @@
             }
         }
     }
-    
+
     /**
      * Process a pipeline and gets is result as a DOM <code>Document</code>
-     * 
+     *
      * @param uri the pipeline URI
      * @param viewData the view data object
      * @return the document
      */
     public Document processToDOM(String uri, Object viewData) throws ProcessingException,
SAXException, IOException  {
         checkSetup();
-        
+
         Map objectModel = ContextHelper.getObjectModel(this.context);
         Object oldViewData = FlowHelper.getContextObject(objectModel);
         FlowHelper.setContextObject(objectModel, FlowHelper.unwrap(viewData));
-        
+
         Source src = null;
-        
+
         try {
             src = this.resolver.resolveURI("cocoon:/" + uri);
             return SourceUtil.toDOM(src);

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java	(original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/source/impl/SitemapSource.java	Wed
Sep  8 19:29:46 2004
@@ -1,12 +1,12 @@
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -65,7 +65,7 @@
 
     /** The system id used for caching */
     private String systemIdForCaching;
-    
+
     /** The current ServiceManager */
     private final ServiceManager manager;
 
@@ -92,15 +92,15 @@
 
     /** Is start processing on the environment called? */
     private boolean processed;
-    
+
     /** The used protocol */
     private final String protocol;
 
     /** SourceResolver (for the redirect source) */
     private SourceResolver sourceResolver;
-    
+
     private String mimeType;
-    
+
     /**
      * Construct a new object
      */
@@ -129,7 +129,7 @@
 
         // create environment...
         final EnvironmentWrapper wrapper = new EnvironmentWrapper(env, info, logger);
-        
+
         // The environment is a facade whose delegate can be changed in case of internal
redirects
         this.environment = new MutableEnvironmentFacade(wrapper);
 
@@ -139,9 +139,9 @@
         } else {
             this.environment.getObjectModel().remove(ObjectModelHelper.PARENT_CONTEXT);
         }
-        
+
         this.systemId = info.systemId;
-        
+
         // initialize
         this.init();
     }
@@ -191,11 +191,11 @@
         try {
             ByteArrayOutputStream os = new ByteArrayOutputStream();
             this.environment.setOutputStream(os);
-            EnvironmentHelper.enterProcessor(this.pipelineDescription.lastProcessor, 
+            EnvironmentHelper.enterProcessor(this.pipelineDescription.lastProcessor,
                                             this.manager,
                                             this.environment);
             try {
-                
+
                 this.pipelineDescription.processingPipeline.process(this.environment);
             } finally {
                 EnvironmentHelper.leaveProcessor();
@@ -221,13 +221,13 @@
     }
 
     /**
-     * 
+     *
      * @see org.apache.excalibur.source.Source#exists()
      */
     public boolean exists() {
         return true;
     }
-    
+
     /**
      *  Get the Validity object. This can either wrap the last modification
      *  date or the expires information or...
@@ -281,7 +281,7 @@
                     this.sourceValidity = this.pipelineDescription.processingPipeline.getValidityForEventPipeline();
                     final String eventPipelineKey = this.pipelineDescription.processingPipeline.getKeyForEventPipeline();
                     this.mimeType = this.environment.getContentType();
-                    
+
                     if (eventPipelineKey != null) {
                         StringBuffer buffer = new StringBuffer(this.systemId);
                         if (this.systemId.indexOf('?') == -1) {
@@ -293,7 +293,7 @@
                         buffer.append(eventPipelineKey);
                         this.systemIdForCaching = buffer.toString();
                     } else {
-                        this.systemIdForCaching = this.systemId; 
+                        this.systemIdForCaching = this.systemId;
                     }
                 } finally {
                     EnvironmentHelper.leaveProcessor();
@@ -350,7 +350,7 @@
                                                  this.environment);
                 try {
                     this.pipelineDescription.processingPipeline.process(this.environment,
-                                 EnvironmentHelper.createEnvironmentAwareConsumer(consumer));

+                                 EnvironmentHelper.createEnvironmentAwareConsumer(consumer));
                 } finally {
                     EnvironmentHelper.leaveProcessor();
                 }
@@ -374,17 +374,20 @@
             this.pipelineDescription.release();
             this.pipelineDescription = null;
         }
-        if ( this.processed ) {
+
+        if (this.processed) {
             this.processed = false;
             this.environment.finishingProcessing();
         }
-        this.sourceValidity = null;
+
         if (this.redirectSource != null) {
             this.sourceResolver.release(this.redirectSource);
+            this.redirectSource = null;
         }
-        this.environment.reset();
-        this.redirectSource = null;
+        this.sourceValidity = null;
         this.redirectValidity = null;
+
+        this.environment.reset();
         this.exception = null;
         this.needsRefresh = true;
     }

Mime
View raw message