cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject svn commit: rev 35699 - in cocoon/branches/butterfly: src/java src/java/org/apache/butterfly/components/pipeline/impl src/java/org/apache/butterfly/reading src/java/org/apache/butterfly/serialization src/java/org/apache/butterfly/servlet src/java/org/apache/butterfly/sitemap src/java/org/apache/butterfly/util src/webapp src/webapp/resources src/webapp/resources/images src/webapp/resources/styles testdata
Date Wed, 04 Aug 2004 21:36:16 GMT
Author: ugo
Date: Wed Aug  4 14:36:15 2004
New Revision: 35699

Added:
   cocoon/branches/butterfly/src/java/org/apache/butterfly/reading/ResourceReader.java
   cocoon/branches/butterfly/src/java/org/apache/butterfly/util/ByteRange.java
   cocoon/branches/butterfly/src/webapp/resources/
   cocoon/branches/butterfly/src/webapp/resources/images/
   cocoon/branches/butterfly/src/webapp/resources/images/cocoon.gif   (contents, props changed)
   cocoon/branches/butterfly/src/webapp/resources/images/powered.gif   (contents, props changed)
   cocoon/branches/butterfly/src/webapp/resources/styles/
   cocoon/branches/butterfly/src/webapp/resources/styles/main.css
   cocoon/branches/butterfly/src/webapp/welcome.xml
      - copied unchanged from rev 35685, cocoon/branches/butterfly/testdata/welcome.xml
   cocoon/branches/butterfly/src/webapp/welcome.xslt
      - copied unchanged from rev 35685, cocoon/branches/butterfly/testdata/welcome.xslt
Removed:
   cocoon/branches/butterfly/testdata/welcome.xml
   cocoon/branches/butterfly/testdata/welcome.xslt
Modified:
   cocoon/branches/butterfly/src/java/applicationContext.xml
   cocoon/branches/butterfly/src/java/org/apache/butterfly/components/pipeline/impl/NonCachingProcessingPipeline.java
   cocoon/branches/butterfly/src/java/org/apache/butterfly/reading/Reader.java
   cocoon/branches/butterfly/src/java/org/apache/butterfly/serialization/XMLSerializer.java
   cocoon/branches/butterfly/src/java/org/apache/butterfly/servlet/ButterflyServlet.java
   cocoon/branches/butterfly/src/java/org/apache/butterfly/servlet/Pipeline.groovy
   cocoon/branches/butterfly/src/java/org/apache/butterfly/sitemap/SitemapOutputComponent.java
   cocoon/branches/butterfly/src/webapp/sitemap.groovy
Log:
Reading

Modified: cocoon/branches/butterfly/src/java/applicationContext.xml
==============================================================================
--- cocoon/branches/butterfly/src/java/applicationContext.xml	(original)
+++ cocoon/branches/butterfly/src/java/applicationContext.xml	Wed Aug  4 14:36:15 2004
@@ -73,5 +73,12 @@
       <value>UTF-8</value>
     </property>
   </bean>
+  
+  <bean id="resourceReader" class="org.apache.butterfly.reading.ResourceReader" singleton="false">
+    <property name="sourceResolver">
+      <ref bean="sourceResolver"/>
+    </property>  
+    <property name="bufferSize"><value>8192</value></property>
+  </bean>
     
 </beans>

Modified: cocoon/branches/butterfly/src/java/org/apache/butterfly/components/pipeline/impl/NonCachingProcessingPipeline.java
==============================================================================
--- cocoon/branches/butterfly/src/java/org/apache/butterfly/components/pipeline/impl/NonCachingProcessingPipeline.java
(original)
+++ cocoon/branches/butterfly/src/java/org/apache/butterfly/components/pipeline/impl/NonCachingProcessingPipeline.java
Wed Aug  4 14:36:15 2004
@@ -170,10 +170,11 @@
         } else {
             this.preparePipeline(environment);
         }
+        */
         if ( this.reader != null ) {
-            this.preparePipeline(environment);            
+            // TODO: implement this.preparePipeline(environment);   
+            reader.setObjectModel(environment.getObjectModel());
         }
-        */
         
         // See if we need to set an "Expires:" header
         /*

Modified: cocoon/branches/butterfly/src/java/org/apache/butterfly/reading/Reader.java
==============================================================================
--- cocoon/branches/butterfly/src/java/org/apache/butterfly/reading/Reader.java	(original)
+++ cocoon/branches/butterfly/src/java/org/apache/butterfly/reading/Reader.java	Wed Aug  4
14:36:15 2004
@@ -26,8 +26,6 @@
  */
 public interface Reader extends SitemapOutputComponent {
 
-    String ROLE = Reader.class.getName();
-
     /**
      * Generate the response.
      */

Added: cocoon/branches/butterfly/src/java/org/apache/butterfly/reading/ResourceReader.java
==============================================================================
--- (empty file)
+++ cocoon/branches/butterfly/src/java/org/apache/butterfly/reading/ResourceReader.java	Wed
Aug  4 14:36:15 2004
@@ -0,0 +1,249 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.butterfly.reading;
+
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Map;
+
+import org.apache.butterfly.components.pipeline.PipelineProcessingException;
+import org.apache.butterfly.environment.ObjectModelHelper;
+import org.apache.butterfly.environment.Request;
+import org.apache.butterfly.environment.Response;
+import org.apache.butterfly.environment.http.HttpResponse;
+import org.apache.butterfly.source.Source;
+import org.apache.butterfly.source.SourceResolver;
+import org.apache.butterfly.util.ByteRange;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+/**
+ * Description of ResourceReader.
+ * 
+ * @version CVS $Id$
+ */
+public class ResourceReader implements Reader {
+    protected static final Log logger = LogFactory.getLog(ResourceReader.class);
+    private SourceResolver sourceResolver;
+    protected long expires = -1;
+    protected int bufferSize = 8192;
+    protected boolean byteRanges = true;
+    private Source inputSource;
+    private OutputStream out;
+    protected Response response;
+    protected Request request;
+    private Map objectModel;
+
+    /**
+     * 
+     */
+    public ResourceReader() {
+        super();
+        // TODO Auto-generated constructor stub
+    }
+    
+    public void setInputSource(String source) {
+        this.inputSource = sourceResolver.resolveURI(source);
+    }
+    
+    /**
+     * @param sourceResolver The sourceResolver to set.
+     */
+    public void setSourceResolver(SourceResolver sourceResolver) {
+        this.sourceResolver = sourceResolver;
+    }
+
+    /**
+     * @param bufferSize The bufferSize to set.
+     */
+    public void setBufferSize(int bufferSize) {
+        this.bufferSize = bufferSize;
+    }
+    
+    /**
+     * @param byteRanges The byteRanges to set.
+     */
+    public void setByteRanges(boolean byteRanges) {
+        this.byteRanges = byteRanges;
+    }
+    
+    /**
+     * @param expires The expires to set.
+     */
+    public void setExpires(long expires) {
+        this.expires = expires;
+    }
+    
+    /**
+     * @param request The request to set.
+     */
+    public void setRequest(Request request) {
+        this.request = request;
+    }
+    /**
+     * @param response The response to set.
+     */
+    public void setResponse(Response response) {
+        this.response = response;
+    }
+    
+    /**
+     * @param objectModel The objectModel to set.
+     */
+    public void setObjectModel(Map objectModel) {
+        this.objectModel = objectModel;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.butterfly.reading.Reader#generate()
+     */
+    public void generate() {
+        this.request = ObjectModelHelper.getRequest(objectModel);
+        this.response = ObjectModelHelper.getResponse(objectModel);
+
+        InputStream inputStream = inputSource.getInputStream();
+        try {
+            processStream(inputStream);
+        } catch (IOException e) {
+            throw new PipelineProcessingException(e);
+        } finally {
+            if (inputStream != null) {
+                try {
+                    inputStream.close();
+                } catch (IOException e) {
+                    throw new PipelineProcessingException(e);
+                }
+            }
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.butterfly.reading.Reader#getLastModified()
+     */
+    public long getLastModified() {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.butterfly.sitemap.SitemapOutputComponent#setOutputStream(java.io.OutputStream)
+     */
+    public void setOutputStream(OutputStream out) {
+        if (out instanceof BufferedOutputStream 
+                || out instanceof org.apache.butterfly.util.BufferedOutputStream) {
+               this.out = out;
+           } else {
+               this.out = new BufferedOutputStream(out, 1536);
+           }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.butterfly.sitemap.SitemapOutputComponent#getMimeType()
+     */
+    public String getMimeType() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.butterfly.sitemap.SitemapOutputComponent#shouldSetContentLength()
+     */
+    public boolean shouldSetContentLength() {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    protected void processStream(InputStream inputStream) throws IOException {
+        byte[] buffer = new byte[bufferSize];
+        int length = -1;
+
+        // tell the client whether we support byte range requests or not
+        if(byteRanges) {
+            response.setHeader("Accept-Ranges", "bytes");
+        } else {
+            response.setHeader("Accept-Ranges", "none");
+        }
+
+        String ranges = request.getHeader("Ranges");
+
+        ByteRange byteRange;
+        if (ranges != null && byteRanges) {
+            try {
+                ranges = ranges.substring(ranges.indexOf('=') + 1);
+                byteRange = new ByteRange(ranges);
+            } catch (NumberFormatException e) {
+                byteRange = null;
+
+                // TC: Hm.. why don't we have setStatus in the Response interface ?
+                if (response instanceof HttpResponse) {
+                    // Respond with status 416 (Request range not satisfiable)
+                    ((HttpResponse)response).setStatus(416);
+                    if (logger.isDebugEnabled()) {
+                        logger.debug("malformed byte range header [" + String.valueOf(ranges)
+ "]");
+                    }
+                }
+            }
+        } else {
+            byteRange = null;
+        }
+
+        long contentLength = inputSource.getContentLength();
+
+        if (byteRange != null) {
+            String entityLength;
+            String entityRange;
+            if (contentLength != -1) {
+                entityLength = "" + contentLength;
+                entityRange = byteRange.intersection(new ByteRange(0, contentLength)).toString();
+            } else {
+                entityLength = "*";
+                entityRange = byteRange.toString();
+            }
+
+            response.setHeader("Content-Range", entityRange + "/" + entityLength);
+
+            if (response instanceof HttpResponse) {
+                // Response with status 206 (Partial content)
+                ((HttpResponse)response).setStatus(206);
+            }
+
+            int pos = 0;
+            int posEnd;
+            while ((length = inputStream.read(buffer)) > -1) {
+                posEnd = pos + length - 1;
+                ByteRange intersection = byteRange.intersection(new ByteRange(pos, posEnd));
+                if (intersection != null) {
+                    out.write(buffer, (int) intersection.getStart() - pos, (int) intersection.length());
+                }
+                pos += length;
+            }
+        } else {
+            if (contentLength != -1) {
+                response.setHeader("Content-Length", Long.toString(contentLength));
+            }
+
+            while ((length = inputStream.read(buffer)) > -1) {
+                out.write(buffer, 0, length);
+            }
+        }
+
+        out.flush();
+    }
+
+}

Modified: cocoon/branches/butterfly/src/java/org/apache/butterfly/serialization/XMLSerializer.java
==============================================================================
--- cocoon/branches/butterfly/src/java/org/apache/butterfly/serialization/XMLSerializer.java
(original)
+++ cocoon/branches/butterfly/src/java/org/apache/butterfly/serialization/XMLSerializer.java
Wed Aug  4 14:36:15 2004
@@ -18,6 +18,7 @@
 package org.apache.butterfly.serialization;
 
 import java.io.OutputStream;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.xml.transform.OutputKeys;
@@ -36,6 +37,7 @@
 public class XMLSerializer extends AbstractXMLPipe implements Serializer {
 
     protected OutputStream output;
+    private Map objectModel;
     protected TraxTransformerFactory transformerFactory;
 
     /**
@@ -122,5 +124,12 @@
      */
     public boolean shouldSetContentLength() {
         return false;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.butterfly.sitemap.SitemapOutputComponent#setObjectModel(java.util.Map)
+     */
+    public void setObjectModel(Map objectModel) {
+        this.objectModel = objectModel;
     }
 }

Modified: cocoon/branches/butterfly/src/java/org/apache/butterfly/servlet/ButterflyServlet.java
==============================================================================
--- cocoon/branches/butterfly/src/java/org/apache/butterfly/servlet/ButterflyServlet.java
(original)
+++ cocoon/branches/butterfly/src/java/org/apache/butterfly/servlet/ButterflyServlet.java
Wed Aug  4 14:36:15 2004
@@ -114,14 +114,17 @@
         try {
             Class pipelineClass = loader.parseClass(getClass().getResourceAsStream("Pipeline.groovy"));
             // Parse the main sitemap
-            System.err.println(this.servletContext.getResource("sitemap.groovy").getFile());
             FileInputStream fis = new FileInputStream(this.servletContext.getResource("sitemap.groovy").getFile());
             Class sitemapClass = loader.parseClass(fis);
             GroovyObject sitemap = (GroovyObject) sitemapClass.newInstance();
             sitemap.setProperty("beanFactory", this.applicationContext);
             Object[] args = { uri };
-            sitemap.invokeMethod("setup", args);
-            sitemap.invokeMethod("process", new Object[] { env });
+            Boolean retval = (Boolean) sitemap.invokeMethod("setup", args);
+            if (retval.booleanValue()) {
+                sitemap.invokeMethod("process", new Object[] { env });
+            } else {
+                logger.info("Sitemap has no match for URI [" + uri + "].");
+            }
         } catch (CompilationFailedException e) {
             logger.error("Cannot compile Groovy sitemap.", e);
             throw new ServletException(e);

Modified: cocoon/branches/butterfly/src/java/org/apache/butterfly/servlet/Pipeline.groovy
==============================================================================
--- cocoon/branches/butterfly/src/java/org/apache/butterfly/servlet/Pipeline.groovy	(original)
+++ cocoon/branches/butterfly/src/java/org/apache/butterfly/servlet/Pipeline.groovy	Wed Aug
 4 14:36:15 2004
@@ -42,6 +42,12 @@
         this.pipeline.serializer = serializer
     }
     
+    protected void read(src, type) {
+        reader = beanFactory.getBean("resourceReader");
+        reader.inputSource = src;
+        this.pipeline.reader = reader;
+    }
+    
     public void process(environment, consumer) {
         this.pipeline.process(environment, consumer)
     }

Modified: cocoon/branches/butterfly/src/java/org/apache/butterfly/sitemap/SitemapOutputComponent.java
==============================================================================
--- cocoon/branches/butterfly/src/java/org/apache/butterfly/sitemap/SitemapOutputComponent.java
(original)
+++ cocoon/branches/butterfly/src/java/org/apache/butterfly/sitemap/SitemapOutputComponent.java
Wed Aug  4 14:36:15 2004
@@ -16,6 +16,7 @@
 package org.apache.butterfly.sitemap;
 
 import java.io.OutputStream;
+import java.util.Map;
 
 /**
  * This interface marks a component as a sitemap component that produces
@@ -40,4 +41,6 @@
      * Test if the component wants to set the content length
      */
     boolean shouldSetContentLength();
+    
+    void setObjectModel(Map objectModel);
 }

Added: cocoon/branches/butterfly/src/java/org/apache/butterfly/util/ByteRange.java
==============================================================================
--- (empty file)
+++ cocoon/branches/butterfly/src/java/org/apache/butterfly/util/ByteRange.java	Wed Aug  4
14:36:15 2004
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.butterfly.util;
+
+/**
+ * @author <a href="mailto:stuart.roebuck@adolos.co.uk">Stuart Roebuck</a>
+ * @version CVS $Id: ByteRange.java,v 1.2 2004/03/05 13:03:00 bdelacretaz Exp $
+ */
+final public class ByteRange {
+
+    
+    private final long start;
+    private final long end;
+
+    
+    public ByteRange(long start, long end) {
+        this.start = start;
+        this.end = end;
+    }
+
+    
+    public ByteRange(String string) throws NumberFormatException {
+        string = string.trim();
+        int dashPos = string.indexOf('-');
+        int length = string.length();
+        if (string.indexOf(',') != -1) {
+            throw new NumberFormatException("Simple ByteRange String contains a comma.");
+        }
+        if (dashPos > 0) {
+            this.start = Integer.parseInt(string.substring(0, dashPos));
+        } else {
+            this.start = Long.MIN_VALUE;
+        }
+        if (dashPos < length - 1) {
+            this.end = Integer.parseInt(string.substring(dashPos + 1, length));
+        } else {
+            this.end = Long.MAX_VALUE;
+        }
+        if (this.start > this.end) {
+            throw new NumberFormatException("Start value is greater than end value.");
+        }
+    }
+
+    
+    public long getStart() {
+        return this.start;
+    }
+
+    
+    public long getEnd() {
+        return this.end;
+    }
+
+    
+    public long length() {
+        return this.end - this.start + 1;
+    }
+
+    
+    public ByteRange intersection(ByteRange range) {
+        if (range.end < this.start || this.end < range.start) {
+            return null;
+        } else {
+            long start = (this.start > range.start) ? this.start : range.start;
+            long end = (this.end < range.end) ? this.end : range.end;
+            return new ByteRange(start, end);
+        }
+    }
+
+
+    public String toString() {
+        return this.start + "-" + this.end;
+    }
+
+    
+}

Added: cocoon/branches/butterfly/src/webapp/resources/images/cocoon.gif
==============================================================================
Binary file. No diff available.

Added: cocoon/branches/butterfly/src/webapp/resources/images/powered.gif
==============================================================================
Binary file. No diff available.

Added: cocoon/branches/butterfly/src/webapp/resources/styles/main.css
==============================================================================
--- (empty file)
+++ cocoon/branches/butterfly/src/webapp/resources/styles/main.css	Wed Aug  4 14:36:15 2004
@@ -0,0 +1,81 @@
+/*
+* 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.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+body { background-color: white; color: black; font-family: verdana, helvetica, arial, sans-serif;
font-size: 80%; }
+
+h1 { color: #336699; text-align: center; font-size: 3em; padding-bottom: 10px; margin: 0px;
}
+h2 { color: #336699; }
+h3 { color: #336699; }
+h4 { color: #336699; }
+
+a:link { color: #336699; }
+a:visited { color: #800080; }
+a:hover { color: #800080; background-color: #ffff80; }
+a:active { color: #006666; }
+
+img { border: 0; }
+.figure { text-align: center; }
+
+span.year { color: #336699; }
+
+p.copyright { text-align: center; padding-top: 10px; border-width: 1px 0px 0px 0px; border-style:
solid; border-color: #336699; }
+p.author { color: #336699; padding-bottom: 10px; }
+p.block { text-align: center; }
+
+hr { height: 0px; color: #336699; }
+
+span.description { color: #336699; font-weight: bold; }
+span.switch { cursor: pointer; margin-left: 5px; text-decoration: underline; }
+
+/* Samples */
+
+.samplesGroup {
+    /* a tasteful shade of blue */
+    background-color: #BFCCDF;
+    color: black;
+    border-width: 0px 0px 2px 0px;
+    border-style: solid;
+    border-color: #336699;
+    font-size:120%;
+    padding-left: 0.2em;
+    padding-top: 0.2em;
+    padding-bottom: 0.2em;
+    margin-top: 1em;
+    margin-bottom: 0;
+ 
+    /* mozilla and some others support the fancy CSS3 borders */
+    -moz-border-radius-bottomleft: 1em;
+    border-radius-bottomleft: 1em;
+}
+
+.samplesNote {
+    color: #333333;
+    margin: 0.5em;
+    padding: 0.2em;
+    background-color: #ffffcc;
+    font-style: italic;
+}
+
+.samplesText {
+    margin-top: 0.2em;
+}
+
+div.resources {
+    text-align: right;
+}
+
+div.resources a {
+    margin: 5px;
+}

Modified: cocoon/branches/butterfly/src/webapp/sitemap.groovy
==============================================================================
--- cocoon/branches/butterfly/src/webapp/sitemap.groovy	(original)
+++ cocoon/branches/butterfly/src/webapp/sitemap.groovy	Wed Aug  4 14:36:15 2004
@@ -15,14 +15,19 @@
  */
 class Sitemap extends Pipeline {
   
-    void setup(String requestPath) {
-        if (requestPath =~ ".*\.html") {
-            generate "testdata/welcome.xml"
-            transform "trax", "testdata/welcome.xslt" 
+    boolean setup(String requestPath) {
+        if (requestPath =~ "index\.html") {
+            // TODO: paths should be relative to the webapp context!
+            generate "build/webapp/welcome.xml"
+            transform "trax", "build/webapp/welcome.xslt" 
             serialize "xml"
+        } else if (requestPath =~ "images/.*\.gif") {
+            read "build/webapp/resources/images/powered.gif", "image/gif"
+        } else if (requestPath =~ "styles/.*\.css") {
+            read "build/webapp/resources/styles/main.css", "text/css"
+        } else {
+            return false;
         }
-        else {
-            println("No matches for URI [" + requestPath + "]");
-        }
+        return true;
     }
 }

Mime
View raw message