You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2011/03/02 22:38:59 UTC

svn commit: r1076399 - in /tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5: internal/services/ internal/services/assets/ services/assets/

Author: hlship
Date: Wed Mar  2 21:38:58 2011
New Revision: 1076399

URL: http://svn.apache.org/viewvc?rev=1076399&view=rev
Log:
TAP5-73: Change the API of StreamableResourceSource to use a single StreamableResourceProcessing value, rather than a set of StreamableResourceFeature values

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResourceProcessing.java
Removed:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResourceFeature.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCompressingInterceptor.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceSourceImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/CompressionStatus.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResourceSource.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java?rev=1076399&r1=1076398&r2=1076399&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ResourceStreamerImpl.java Wed Mar  2 21:38:58 2011
@@ -29,7 +29,7 @@ import org.apache.tapestry5.services.Res
 import org.apache.tapestry5.services.ResponseCompressionAnalyzer;
 import org.apache.tapestry5.services.assets.CompressionStatus;
 import org.apache.tapestry5.services.assets.StreamableResource;
-import org.apache.tapestry5.services.assets.StreamableResourceFeature;
+import org.apache.tapestry5.services.assets.StreamableResourceProcessing;
 import org.apache.tapestry5.services.assets.StreamableResourceSource;
 
 public class ResourceStreamerImpl implements ResourceStreamer
@@ -75,10 +75,10 @@ public class ResourceStreamerImpl implem
 
         long ifModifiedSince = 0;
 
-        Set<StreamableResourceFeature> features = analyzer.isGZipSupported() ? StreamableResourceFeature.ALL
-                : StreamableResourceFeature.NO_COMPRESSION;
+        StreamableResourceProcessing processing = analyzer.isGZipSupported() ? StreamableResourceProcessing.COMPRESSION_ENABLED
+                : StreamableResourceProcessing.COMPRESSION_DISABLED;
 
-        StreamableResource streamable = streamableResourceSource.getStreamableResource(resource, features);
+        StreamableResource streamable = streamableResourceSource.getStreamableResource(resource, processing);
 
         long lastModified = streamable.getLastModified();
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java?rev=1076399&r1=1076398&r2=1076399&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCachingInterceptor.java Wed Mar  2 21:38:58 2011
@@ -16,14 +16,12 @@ package org.apache.tapestry5.internal.se
 
 import java.io.IOException;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.tapestry5.ioc.Resource;
-import org.apache.tapestry5.ioc.annotations.PostInjection;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.services.InvalidationListener;
 import org.apache.tapestry5.services.assets.StreamableResource;
-import org.apache.tapestry5.services.assets.StreamableResourceFeature;
+import org.apache.tapestry5.services.assets.StreamableResourceProcessing;
 import org.apache.tapestry5.services.assets.StreamableResourceSource;
 
 /**
@@ -43,17 +41,17 @@ public class SRSCachingInterceptor imple
         this.delegate = delegate;
     }
 
-    public StreamableResource getStreamableResource(Resource baseResource, Set<StreamableResourceFeature> features)
+    public StreamableResource getStreamableResource(Resource baseResource, StreamableResourceProcessing processing)
             throws IOException
     {
-        if (!features.contains(StreamableResourceFeature.CACHING))
-            return delegate.getStreamableResource(baseResource, features);
+        if (processing != StreamableResourceProcessing.FOR_AGGREGATION)
+            return delegate.getStreamableResource(baseResource, processing);
 
         StreamableResource result = cache.get(baseResource);
 
         if (result == null)
         {
-            result = delegate.getStreamableResource(baseResource, features);
+            result = delegate.getStreamableResource(baseResource, processing);
 
             if (isCacheable(result))
             {

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCompressingInterceptor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCompressingInterceptor.java?rev=1076399&r1=1076398&r2=1076399&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCompressingInterceptor.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/SRSCompressingInterceptor.java Wed Mar  2 21:38:58 2011
@@ -17,13 +17,12 @@ package org.apache.tapestry5.internal.se
 import java.io.BufferedOutputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.util.Set;
 import java.util.zip.GZIPOutputStream;
 
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.services.assets.CompressionStatus;
 import org.apache.tapestry5.services.assets.StreamableResource;
-import org.apache.tapestry5.services.assets.StreamableResourceFeature;
+import org.apache.tapestry5.services.assets.StreamableResourceProcessing;
 import org.apache.tapestry5.services.assets.StreamableResourceSource;
 
 public class SRSCompressingInterceptor implements StreamableResourceSource
@@ -38,19 +37,21 @@ public class SRSCompressingInterceptor i
         this.delegate = delegate;
     }
 
-    public StreamableResource getStreamableResource(Resource baseResource, Set<StreamableResourceFeature> features)
+    public StreamableResource getStreamableResource(Resource baseResource, StreamableResourceProcessing processing)
             throws IOException
     {
-        StreamableResource streamable = delegate.getStreamableResource(baseResource, features);
+        StreamableResource streamable = delegate.getStreamableResource(baseResource, processing);
 
-        if (streamable.getCompression() == CompressionStatus.COMPRESSABLE
-                && features.contains(StreamableResourceFeature.GZIP_COMPRESSION)) { return compress(streamable); }
+        if (processing == StreamableResourceProcessing.COMPRESSION_ENABLED) { return compress(streamable); }
 
         return streamable;
     }
 
     private StreamableResource compress(StreamableResource uncompressed) throws IOException
     {
+        if (uncompressed.getCompression() != CompressionStatus.COMPRESSABLE)
+            return uncompressed;
+
         int size = uncompressed.getSize();
 
         // Because of GZIP overhead, streams below a certain point actually get larger when compressed so

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java?rev=1076399&r1=1076398&r2=1076399&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java Wed Mar  2 21:38:58 2011
@@ -40,7 +40,7 @@ import org.apache.tapestry5.services.Res
 import org.apache.tapestry5.services.ResponseCompressionAnalyzer;
 import org.apache.tapestry5.services.assets.AssetRequestHandler;
 import org.apache.tapestry5.services.assets.StreamableResource;
-import org.apache.tapestry5.services.assets.StreamableResourceFeature;
+import org.apache.tapestry5.services.assets.StreamableResourceProcessing;
 import org.apache.tapestry5.services.assets.StreamableResourceSource;
 import org.apache.tapestry5.services.javascript.JavaScriptStack;
 import org.apache.tapestry5.services.javascript.JavaScriptStackSource;
@@ -106,7 +106,7 @@ public class StackAssetRequestHandler im
         if (compress)
             response.setHeader(InternalConstants.CONTENT_ENCODING_HEADER, InternalConstants.GZIP_CONTENT_ENCODING);
 
-        // CSS support is problematic, because of relative URLs inside the CSS files. For the
+        // CSS aggregation is problematic, because of relative URLs inside the CSS files. For the
         // moment, only JavaScript is supported.
 
         OutputStream output = response.getOutputStream("text/javascript");
@@ -211,7 +211,7 @@ public class StackAssetRequestHandler im
         Resource resource = library.getResource();
 
         StreamableResource streamable = streamableResourceSource.getStreamableResource(resource,
-                StreamableResourceFeature.NONE);
+                StreamableResourceProcessing.FOR_AGGREGATION);
 
         streamable.streamTo(outputStream);
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceSourceImpl.java?rev=1076399&r1=1076398&r2=1076399&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceSourceImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StreamableResourceSourceImpl.java Wed Mar  2 21:38:58 2011
@@ -20,7 +20,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Map;
-import java.util.Set;
 
 import org.apache.tapestry5.internal.TapestryInternalUtils;
 import org.apache.tapestry5.ioc.Resource;
@@ -29,7 +28,7 @@ import org.apache.tapestry5.services.ass
 import org.apache.tapestry5.services.assets.ContentTypeAnalyzer;
 import org.apache.tapestry5.services.assets.ResourceTransformer;
 import org.apache.tapestry5.services.assets.StreamableResource;
-import org.apache.tapestry5.services.assets.StreamableResourceFeature;
+import org.apache.tapestry5.services.assets.StreamableResourceProcessing;
 import org.apache.tapestry5.services.assets.StreamableResourceSource;
 
 public class StreamableResourceSourceImpl implements StreamableResourceSource
@@ -52,7 +51,7 @@ public class StreamableResourceSourceImp
         this.resourceChangeTracker = resourceChangeTracker;
     }
 
-    public StreamableResource getStreamableResource(Resource baseResource, Set<StreamableResourceFeature> features)
+    public StreamableResource getStreamableResource(Resource baseResource, StreamableResourceProcessing processing)
             throws IOException
     {
         assert baseResource != null;

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/CompressionStatus.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/CompressionStatus.java?rev=1076399&r1=1076398&r2=1076399&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/CompressionStatus.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/CompressionStatus.java Wed Mar  2 21:38:58 2011
@@ -35,7 +35,7 @@ public enum CompressionStatus
     COMPRESSED,
 
     /**
-     * The content is not compressable. This is usually the case for image content types, where the structure
+     * The content is not compressable. This is usually the case for image content types, where the native format
      * of the content already includes compression.
      */
     NOT_COMPRESSABLE;

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResourceProcessing.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResourceProcessing.java?rev=1076399&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResourceProcessing.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResourceProcessing.java Wed Mar  2 21:38:58 2011
@@ -0,0 +1,49 @@
+// Copyright 2011 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.tapestry5.services.assets;
+
+import org.apache.tapestry5.ioc.Resource;
+import org.apache.tapestry5.services.javascript.JavaScriptStack;
+
+/**
+ * Defines additional features desired when accessing the content of a {@link Resource} as
+ * a {@link StreamableResource}.
+ * 
+ * @since 5.3.0
+ * @see StreamableResourceSource#getStreamableResource(Resource, StreamableResourceProcessing)
+ */
+public enum StreamableResourceProcessing
+{
+    /**
+     * The default behavior when the client supports compression, and an individual (non-aggregated) resources
+     * is being accessed. The resource may be minimized and both the compressed and uncompressed versions may be cached.
+     */
+    COMPRESSION_ENABLED,
+
+    /**
+     * As with {@link #COMPRESSION_ENABLED}, but the final compression stage (and compression cache) is skipped. This is
+     * appropriate
+     * for individual resources where the client does not support compression.
+     */
+    COMPRESSION_DISABLED,
+
+    /**
+     * Turns off all caching and minification of the resource, which is appropriate when the individual resource will be
+     * aggregated with other resources to form a virtual composite.
+     * 
+     * @see JavaScriptStack
+     */
+    FOR_AGGREGATION
+}

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResourceSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResourceSource.java?rev=1076399&r1=1076398&r2=1076399&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResourceSource.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/StreamableResourceSource.java Wed Mar  2 21:38:58 2011
@@ -15,7 +15,6 @@
 package org.apache.tapestry5.services.assets;
 
 import java.io.IOException;
-import java.util.Set;
 
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.ioc.annotations.Primary;
@@ -23,9 +22,8 @@ import org.apache.tapestry5.ioc.annotati
 
 /**
  * Converts {@link Resource}s into {@link StreamableResource}s, and may be responsible for
- * {@linkplain ResourceTransformer transforming} resources based on file extension. Only
- * the {@link Primary} service has a configuration; the alternate {@link ExtendedProcessing} service
- * adds caching, compression, and minimization.
+ * {@linkplain ResourceTransformer transforming} resources based on file extension. In addition,
+ * service decorators added to the service may provide additional processing (compression, minimization, and caching).
  * 
  * @since 5.3.0
  */
@@ -38,12 +36,12 @@ public interface StreamableResourceSourc
      * 
      * @param baseResource
      *            the resource to convert
-     * @param features
-     *            a set of features desired for the resource, normally {@link StreamableResourceFeature#ALL}
+     * @param processing
+     *            defines additional processing after the resource has been read and possibly transformed
      * @return the contents of the Resource, possibly transformed, in a streamable format.
      * @throws IOException
      *             if the resource does not exist or a URL for the content is not available
      */
-    StreamableResource getStreamableResource(Resource baseResource, Set<StreamableResourceFeature> features)
+    StreamableResource getStreamableResource(Resource baseResource, StreamableResourceProcessing processing)
             throws IOException;
 }