cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r676332 - in /cocoon/whiteboard/corona/trunk: corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/ corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/
Date Sun, 13 Jul 2008 14:25:26 GMT
Author: reinhard
Date: Sun Jul 13 07:25:25 2008
New Revision: 676332

URL: http://svn.apache.org/viewvc?rev=676332&view=rev
Log:
. improve naming: there are parameters passed to a pipeline (and resp. to its components)
coming from outside --> inputParameters and there are configuration parameters coming from
the sitemap --> configuration. Naming all parameters hasn't been very helpful to understand
the code.

. close URLconnections explicitly

Modified:
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractXMLProducer.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/IncludeTransformer.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XSLTTransformer.java
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java
    cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java?rev=676332&r1=676331&r2=676332&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractSerializer.java
Sun Jul 13 07:25:25 2008
@@ -24,51 +24,72 @@
 
 public abstract class AbstractSerializer extends AbstractXMLPipe implements PipelineComponent,
Finisher {
 
-    @SuppressWarnings("unused")
-    protected OutputStream outputStream;
+    private OutputStream outputStream;
 
-    protected String contentType;
+    private String contentType;
 
-    @SuppressWarnings("unused")
-    protected Map<String, ? extends Object> configuration;
+    private Map<String, ? extends Object> configuration;
 
-    @SuppressWarnings("unused")
-    protected Map<String, Object> inputParameters;
+    private Map<String, Object> inputParameters;
 
-    public void setContentType(String contentType) {
-        this.contentType = contentType;
+    /**
+     * @return A {@link Map} that contains all configuration parameters.
+     */
+    protected Map<String, ? extends Object> getConfiguration() {
+        return this.configuration;
     }
 
     /**
      * 
      * {@inheritDoc}
      * 
-     * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setConfiguration(java.util.Map)
+     * @see org.apache.cocoon.corona.pipeline.component.Finisher#getContentType()
      */
-    public void setConfiguration(Map<String, ? extends Object> parameters) {
-        if (parameters.containsKey("mime-type")) {
-            this.contentType = (String) parameters.get("mime-type");
-        }
+    public String getContentType() {
+        return this.contentType;
+    }
+
+    /**
+     * @return A {@link Map} that contains all pipeline input parameters.
+     */
+    protected Map<String, Object> getInputParameters() {
+        return this.inputParameters;
+    }
+
+    /**
+     * @return The {@link OutputStream} of the pipeline.
+     */
+    protected OutputStream getOutputStream() {
+        return this.outputStream;
     }
 
     /**
      * 
      * {@inheritDoc}
      * 
-     * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setInputParameters(java.util.Map)
+     * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setConfiguration(java.util.Map)
      */
-    public void setInputParameters(Map<String, Object> parameters) {
-        this.inputParameters = parameters;
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
+        if (configuration.containsKey("mime-type")) {
+            this.contentType = (String) configuration.get("mime-type");
+        }
+    }
+
+    /**
+     * @param The type of the content produced by this serializer.
+     */
+    public void setContentType(String contentType) {
+        this.contentType = contentType;
     }
 
     /**
      * 
      * {@inheritDoc}
      * 
-     * @see org.apache.cocoon.corona.pipeline.component.Finisher#getContentType()
+     * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setInputParameters(java.util.Map)
      */
-    public String getContentType() {
-        return this.contentType;
+    public void setInputParameters(Map<String, Object> inputParameters) {
+        this.inputParameters = inputParameters;
     }
 
     /**

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractXMLProducer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractXMLProducer.java?rev=676332&r1=676331&r2=676332&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractXMLProducer.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/AbstractXMLProducer.java
Sun Jul 13 07:25:25 2008
@@ -44,7 +44,7 @@
      * 
      * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setConfiguration(java.util.Map)
      */
-    public void setConfiguration(Map<String, ? extends Object> parameters) {
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
     }
 
     /**
@@ -52,7 +52,7 @@
      * 
      * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setInputParameters(java.util.Map)
      */
-    public void setInputParameters(Map<String, Object> parameters) {
+    public void setInputParameters(Map<String, Object> inputParameters) {
     }
 
     protected XMLConsumer getXMLConsumer() {

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java?rev=676332&r1=676331&r2=676332&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/CleaningTransformer.java
Sun Jul 13 07:25:25 2008
@@ -97,5 +97,4 @@
     public CacheKey constructCacheKey() {
         return new SimpleCacheKey();
     }
-
-}
+}
\ No newline at end of file

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java?rev=676332&r1=676331&r2=676332&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java
Sun Jul 13 07:25:25 2008
@@ -20,6 +20,7 @@
 
 import java.io.IOException;
 import java.net.URL;
+import java.net.URLConnection;
 import java.util.Map;
 
 import org.apache.cocoon.corona.pipeline.caching.CacheKey;
@@ -51,7 +52,10 @@
      */
     public CacheKey constructCacheKey() {
         try {
-            return new TimestampCacheKey(this.source, this.source.openConnection().getLastModified());
+            URLConnection connection = this.source.openConnection();
+            TimestampCacheKey timestampCacheKey = new TimestampCacheKey(this.source, connection.getLastModified());
+            URLConnectionUtils.closeQuietly(connection);
+            return timestampCacheKey;
         } catch (IOException e) {
             this.logger.error("Can't construct cache key. Error while connecting to " + this.source,
e);
         }
@@ -82,8 +86,8 @@
      * @see org.apache.cocoon.corona.pipeline.component.AbstractXMLProducer#setConfiguration(java.util.Map)
      */
     @Override
-    public void setConfiguration(Map<String, ? extends Object> parameters) {
-        this.setSource((URL) parameters.get("source"));
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
+        this.setSource((URL) configuration.get("source"));
     }
 
     public void setSource(URL source) {

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java?rev=676332&r1=676331&r2=676332&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java
Sun Jul 13 07:25:25 2008
@@ -27,6 +27,7 @@
 
 import org.apache.cocoon.corona.pipeline.caching.CacheKey;
 import org.apache.cocoon.corona.pipeline.caching.TimestampCacheKey;
+import org.apache.cocoon.corona.pipeline.util.URLConnectionUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -70,12 +71,13 @@
      */
     public void execute() {
         InputStream inputStream = null;
+        if (this.source == null) {
+            throw new IllegalArgumentException("FileReaderComponent has no source configured
to read from.");
+        }
+        URLConnection connection = null;
         try {
-            if (this.source == null) {
-                throw new IllegalArgumentException("FileReaderComponent has no source configured
to read from.");
-            }
-
-            inputStream = this.source.openStream();
+            connection = this.source.openConnection();
+            inputStream = connection.getInputStream();
 
             byte[] data = new byte[1024];
             while (true) {
@@ -93,11 +95,7 @@
             this.logger.error(message, e);
             throw new RuntimeException(message, e);
         } finally {
-            try {
-                inputStream.close();
-            } catch (IOException e) {
-                this.logger.error("Error while closing input stream on " + this.source, e);
-            }
+            URLConnectionUtils.closeQuietly(connection);
         }
     }
 
@@ -111,10 +109,14 @@
             return this.mimeType;
         }
 
+        URLConnection connection = null;
         try {
-            return this.source.openConnection().getContentType();
+            connection = this.source.openConnection();
+            return connection.getContentType();
         } catch (IOException e) {
             throw new RuntimeException(e);
+        } finally {
+            URLConnectionUtils.closeQuietly(connection);
         }
     }
 
@@ -133,14 +135,28 @@
      * 
      * @see org.apache.cocoon.corona.pipeline.component.PipelineComponent#setInputParameters(java.util.Map)
      */
-    public void setInputParameters(Map<String, Object> parameters) {
+    public void setInputParameters(Map<String, Object> inputParameters) {
     }
 
+    /**
+     * Set the mime-type directly which is useful when this component is used directly.
+     * 
+     * @param mimeType The mime-type that belongs to the content that is produced by this
component.
+     */
     public void setMimeType(String mimeType) {
         this.mimeType = mimeType;
     }
 
     /**
+     * Set the source {@link URL} directly when this component is used directly.
+     * 
+     * @param source A {@link URL} that will be used by this component.
+     */
+    public void setSource(URL source) {
+        this.source = source;
+    }
+
+    /**
      * {@inheritDoc}
      * 
      * @see org.apache.cocoon.corona.pipeline.component.Finisher#setOutputStream(java.io.OutputStream)
@@ -149,10 +165,6 @@
         this.outputStream = outputStream;
     }
 
-    public void setSource(URL source) {
-        this.source = source;
-    }
-
     /**
      * {@inheritDoc}
      * 

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/IncludeTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/IncludeTransformer.java?rev=676332&r1=676331&r2=676332&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/IncludeTransformer.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/IncludeTransformer.java
Sun Jul 13 07:25:25 2008
@@ -107,8 +107,8 @@
     }
 
     @Override
-    public void setConfiguration(Map<String, ? extends Object> parameters) {
-        this.setBaseUrl((URL) parameters.get("baseUrl"));
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
+        this.setBaseUrl((URL) configuration.get("baseUrl"));
     }
 
     public void setBaseUrl(URL baseUrl) {

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XSLTTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XSLTTransformer.java?rev=676332&r1=676331&r2=676332&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XSLTTransformer.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XSLTTransformer.java
Sun Jul 13 07:25:25 2008
@@ -49,10 +49,10 @@
     }
 
     @Override
-    public void setConfiguration(Map<String, ? extends Object> parameters) {
-        this.source = (URL) parameters.get("source");
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
+        this.source = (URL) configuration.get("source");
 
-        this.parameters = new HashMap<String, Object>(parameters);
+        this.parameters = new HashMap<String, Object>(configuration);
     }
 
     @Override

Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java?rev=676332&r1=676331&r2=676332&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServiceConsumerGenerator.java
Sun Jul 13 07:25:25 2008
@@ -30,10 +30,10 @@
 
 public class ServiceConsumerGenerator extends AbstractXMLProducer implements Starter {
 
-    private Map<String, ? extends Object> parameters;
+    private Map<String, ? extends Object> inputParameters;
 
     public void execute() {
-        HttpServletRequest request = HttpContextHelper.getRequest(this.parameters);
+        HttpServletRequest request = HttpContextHelper.getRequest(this.inputParameters);
         if (!"POST".equals(request.getMethod())) {
             throw new ProcessingException("Cannot create consumer source for request that
is not POST.");
         }
@@ -49,7 +49,7 @@
     }
 
     @Override
-    public void setInputParameters(Map<String, Object> parameters) {
-        this.parameters = parameters;
+    public void setInputParameters(Map<String, Object> inputParameters) {
+        this.inputParameters = inputParameters;
     }
 }
\ No newline at end of file

Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java?rev=676332&r1=676331&r2=676332&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceGenerator.java
Sun Jul 13 07:25:25 2008
@@ -40,7 +40,7 @@
     }
 
     @Override
-    public void setConfiguration(Map<String, ? extends Object> parameters) {
-        this.service = (URL) parameters.get("service");
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
+        this.service = (URL) configuration.get("service");
     }
 }
\ No newline at end of file

Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java?rev=676332&r1=676331&r2=676332&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceSerializer.java
Sun Jul 13 07:25:25 2008
@@ -25,6 +25,7 @@
 import org.apache.cocoon.corona.pipeline.ProcessingException;
 import org.apache.cocoon.corona.pipeline.component.AbstractSerializer;
 import org.apache.cocoon.corona.pipeline.util.SaxBuffer;
+import org.apache.cocoon.corona.pipeline.util.URLConnectionUtils;
 import org.apache.cocoon.corona.pipeline.util.XMLUtils;
 import org.apache.commons.io.IOUtils;
 import org.xml.sax.SAXException;
@@ -49,9 +50,11 @@
 
         try {
             XMLUtils.toOutputStream(this.getUrlConnection().getOutputStream(), this.saxBuffer);
-            IOUtils.copy(this.getUrlConnection().getInputStream(), this.outputStream);
+            IOUtils.copy(this.getUrlConnection().getInputStream(), this.getOutputStream());
         } catch (IOException e) {
             throw new SAXException("Can't copy result of servlet service to the output stream",
e);
+        } finally {
+            URLConnectionUtils.closeQuietly(this.getUrlConnection());
         }
     }
 
@@ -73,11 +76,11 @@
     }
 
     @Override
-    public void setConfiguration(Map<String, ? extends Object> parameters) {
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
         try {
-            this.service = new URL((String) parameters.get("service"));
+            this.service = new URL((String) configuration.get("service"));
         } catch (MalformedURLException e) {
-            throw new ProcessingException(("Can't create an URL for " + parameters.get("service")
+ "."), e);
+            throw new ProcessingException(("Can't create an URL for " + configuration.get("service")
+ "."), e);
         }
     }
 }
\ No newline at end of file

Modified: cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java?rev=676332&r1=676331&r2=676332&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java
(original)
+++ cocoon/whiteboard/corona/trunk/corona-servlet/src/main/java/org/apache/cocoon/corona/servlet/ssf/ServletServiceTransformer.java
Sun Jul 13 07:25:25 2008
@@ -51,12 +51,14 @@
 
         try {
             XMLUtils.toOutputStream(this.getUrlConnection().getOutputStream(), saxBuffer);
+            URLConnectionUtils.toSax(this.getUrlConnection(), this.getXMLConsumer());
         } catch (IOException e) {
             throw new ProcessingException("Can't stream SaxBuffer into the output stream
of the URL "
                     + this.getUrlConnection().getURL());
+        } finally {
+            URLConnectionUtils.closeQuietly(this.getUrlConnection());
         }
 
-        URLConnectionUtils.toSax(this.getUrlConnection(), this.getXMLConsumer());
     }
 
     private URLConnection getUrlConnection() {
@@ -72,11 +74,11 @@
     }
 
     @Override
-    public void setConfiguration(Map<String, ? extends Object> parameters) {
+    public void setConfiguration(Map<String, ? extends Object> configuration) {
         try {
-            this.service = new URL((String) parameters.get("service"));
+            this.service = new URL((String) configuration.get("service"));
         } catch (MalformedURLException e) {
-            throw new ProcessingException(("Can't create an URL for " + parameters.get("service")
+ "."), e);
+            throw new ProcessingException(("Can't create an URL for " + configuration.get("service")
+ "."), e);
         }
     }
 }
\ No newline at end of file



Mime
View raw message