froehlich    02/05/24 01:38:13

  Modified:    src/java/org/apache/cocoon/reading ResourceReader.java
  Log:
  applied patch from [EMAIL PROTECTED]
  patch to get the mime type from the Excalibur source.
  
  Revision  Changes    Path
  1.8       +41 -21    
xml-cocoon2/src/java/org/apache/cocoon/reading/ResourceReader.java
  
  Index: ResourceReader.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/reading/ResourceReader.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ResourceReader.java       20 Mar 2002 20:12:42 -0000      1.7
  +++ ResourceReader.java       24 May 2002 08:38:13 -0000      1.8
  @@ -51,14 +51,19 @@
   package org.apache.cocoon.reading;
   
   import org.apache.avalon.framework.parameters.Parameters;
  +
  +import org.apache.excalibur.source.Source;
  +import org.apache.excalibur.source.SourceException;
  +import org.apache.excalibur.source.SourceValidity;
  +import org.apache.excalibur.source.impl.validity.TimeStampValidity;
  +
   import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.caching.CacheValidity;
   import org.apache.cocoon.caching.Cacheable;
  -import org.apache.cocoon.caching.TimeStampCacheValidity;
  +import org.apache.cocoon.caching.SourceCacheValidity;
   import org.apache.cocoon.environment.Context;
   import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.cocoon.environment.Response;
  -import org.apache.cocoon.environment.Source;
   import org.apache.cocoon.environment.SourceResolver;
   import org.apache.cocoon.util.HashUtil;
   import org.xml.sax.SAXException;
  @@ -86,7 +91,7 @@
    *   </dl>
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Giacomo Pati</a>
  - * @version CVS $Id: ResourceReader.java,v 1.7 2002/03/20 20:12:42 vgritsenko Exp $
  + * @version CVS $Id: ResourceReader.java,v 1.8 2002/05/24 08:38:13 froehlich Exp $
    */
   public class ResourceReader
     extends AbstractReader
  @@ -104,15 +109,20 @@
       public void setup(SourceResolver resolver, Map objectModel, String src, 
Parameters par)
       throws ProcessingException, SAXException, IOException {
           super.setup(resolver, objectModel, src, par);
  -        this.inputSource = this.resolver.resolve(super.source);
  +        try {
  +            this.inputSource = resolver.resolveURI(src);
  +        } catch (SourceException se) {
  +            getLogger().error("Error during resolving of '" + src + "'.", se);
  +            throw new ProcessingException("Error during resolving of '" + src + 
"'.", se);
  +        }
       }
   
       public void recycle() {
  -        super.recycle();
           if (this.inputSource != null) {
  -            this.inputSource.recycle();
  +            super.resolver.release( this.inputSource );
               this.inputSource = null;
           }
  +        super.recycle();
       }
   
       /**
  @@ -122,7 +132,7 @@
        * @return The generated key hashes the src
        */
       public long generateKey() {
  -        if (this.inputSource.getLastModified() != 0) {
  +        if (this.inputSource.getValidity() != null) {
               return HashUtil.hash(this.inputSource.getSystemId());
           }
           return 0;
  @@ -135,8 +145,8 @@
        *         component is currently not cacheable.
        */
       public CacheValidity generateValidity() {
  -        if (this.inputSource.getLastModified() != 0) {
  -            return new TimeStampCacheValidity(this.inputSource.getLastModified());
  +        if (this.inputSource.getValidity() != null) {
  +            return new SourceCacheValidity(this.inputSource.getValidity());
           }
           return null;
       }
  @@ -146,7 +156,11 @@
        *         possible to detect
        */
       public long getLastModified() {
  -        return this.inputSource.getLastModified();
  +        final SourceValidity validity = this.inputSource.getValidity();
  +        if (validity instanceof TimeStampValidity) {
  +            return ((TimeStampValidity)validity).getTimeStamp();
  +        }
  +        return 0;
       }
   
       /**
  @@ -163,26 +177,28 @@
                   response.setDateHeader("Expires", System.currentTimeMillis() + 
expires);
               }
   
  -            long contentLength = this.inputSource.getContentLength();
  -            if (contentLength != -1) {
  -                // FIXME (VG): Environment has setContentLength, and
  -                // Response interface has not. Strange.
  -                response.setHeader("Content-Length", Long.toString(contentLength));
  -            }
  -            response.setHeader("Accept-Ranges", "bytes");
  -
               byte[] buffer = new byte[8192];
               int length = -1;
  +            long contentLength = 0;
   
               InputStream inputStream = this.inputSource.getInputStream();
               while ((length = inputStream.read(buffer)) > -1) {
                   out.write(buffer, 0, length);
  +                contentLength += length;
               }
  +
  +            // FIXME (VG): Environment has setContentLength, and
  +            // Response interface has not. Strange.
  +            response.setHeader("Content-Length", Long.toString(contentLength));
  +            response.setHeader("Accept-Ranges", "bytes");
  +
               inputStream.close();
               inputStream = null;
               out.flush();
           } catch (IOException ioe) {
  -            getLogger().debug("Received an IOException, assuming client severed 
connection on purpose");
  +            getLogger().error("Received an IOException, assuming client severed 
connection on purpose", ioe);
  +        } catch (SourceException se) {
  +            getLogger().error("Received an SourceException, assuming client severed 
connection on purpose", se);
           }
       }
   
  @@ -193,9 +209,13 @@
           Context ctx = ObjectModelHelper.getContext(this.objectModel);
   
           if (ctx != null) {
  -           return ctx.getMimeType(this.source);
  +            if (ctx.getMimeType(this.source)!=null) {
  +                return ctx.getMimeType(this.source);
  +            } else {
  +                return this.inputSource.getMimeType();
  +            }
           } else {
  -           return null;
  +           return this.inputSource.getMimeType();
           }
       }
   
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to