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.2/src/java/org/apache/cocoon/reading ResourceReader.java
Date Wed, 04 Feb 2004 12:22:47 GMT
cziegeler    2004/02/04 04:22:47

  Modified:    src/java/org/apache/cocoon/reading ResourceReader.java
  Log:
     <action dev="CZ" type="update">
       ResourceReader: Is now configurable as well. All parameters can be defined during configuration
       of the reader. Fixed also a minor bug in the last-modified detection.
     </action>
  
  Revision  Changes    Path
  1.6       +37 -10    cocoon-2.2/src/java/org/apache/cocoon/reading/ResourceReader.java
  
  Index: ResourceReader.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/reading/ResourceReader.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ResourceReader.java	27 Dec 2003 15:11:57 -0000	1.5
  +++ ResourceReader.java	4 Feb 2004 12:22:47 -0000	1.6
  @@ -50,6 +50,8 @@
   */
   package org.apache.cocoon.reading;
   
  +import org.apache.avalon.framework.parameters.ParameterException;
  +import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.util.ByteRange;
  @@ -96,6 +98,7 @@
    *
    * @author <a href="mailto:Giacomo.Pati@pwr.ch">Giacomo Pati</a>
    * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
  + * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
    * @version CVS $Id$
    * 
    * @avalon.component
  @@ -103,7 +106,9 @@
    * @x-avalon.lifestyle type=pooled
    * @x-avalon.info name=resource-reader
    */
  -public class ResourceReader extends AbstractReader implements CacheableProcessingComponent
{
  +public class ResourceReader 
  +extends AbstractReader 
  +implements CacheableProcessingComponent, Parameterizable {
   
       /** The list of generated documents */
       private static final Map documents = new HashMap();
  @@ -119,6 +124,21 @@
       protected long expires;
       protected int bufferSize;
   
  +    protected long configuredExpires;
  +    protected boolean configuredQuickTest;
  +    protected int configuredBufferSize;
  +    protected boolean configuredByteRanges;
  +    
  +    /* (non-Javadoc)
  +     * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
  +     */
  +    public void parameterize(Parameters parameters) throws ParameterException {
  +        this.configuredExpires = parameters.getParameterAsLong("expires", -1);
  +        this.configuredQuickTest = parameters.getParameterAsBoolean("quick-modified-test",
false);
  +        this.configuredBufferSize = parameters.getParameterAsInteger("buffer-size", 8192);
  +        this.configuredByteRanges = parameters.getParameterAsBoolean("byte-ranges", true);
  +    }
  +
       /**
        * Setup the reader.
        * The resource is opened to get an <code>InputStream</code>,
  @@ -130,11 +150,11 @@
           request = ObjectModelHelper.getRequest(objectModel);
           response = ObjectModelHelper.getResponse(objectModel);
   
  -        expires = par.getParameterAsInteger("expires", -1);
  -        bufferSize = par.getParameterAsInteger("buffer-size",8192);
  +        expires = par.getParameterAsLong("expires", this.configuredExpires);
  +        bufferSize = par.getParameterAsInteger("buffer-size", this.configuredBufferSize);
   
  -        byteRanges = par.getParameterAsBoolean("byte-ranges",true);
  -        quickTest = par.getParameterAsBoolean("quick-modified-test", false);
  +        byteRanges = par.getParameterAsBoolean("byte-ranges", this.configuredByteRanges);
  +        quickTest = par.getParameterAsBoolean("quick-modified-test", this.configuredQuickTest);
   
           try {
               inputSource = resolver.resolveURI(src);
  @@ -184,7 +204,7 @@
               return inputSource.getLastModified();
           }
           final String systemId = (String) documents.get(request.getRequestURI());
  -        if (inputSource.getURI().equals(systemId)) {
  +        if (systemId == null || inputSource.getURI().equals(systemId)) {
               return inputSource.getLastModified();
           }
           else {
  @@ -294,9 +314,16 @@
                   throw SourceUtil.handle("Error during resolving of the input stream", se);
               }
   
  -            processStream();
  -
  -            inputStream.close();
  +            // Bugzilla Bug 25069, close inputStream in finally block
  +            // this will close inputStream even if processStream throws
  +            // an exception
  +            try {
  +                processStream();
  +            } finally {
  +                if (inputStream != null) {
  +                    inputStream.close();
  +                }
  +            }
   
               if (!quickTest) {
                   // if everything is ok, add this to the list of generated documents
  
  
  

Mime
View raw message