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 2008/04/20 00:48:54 UTC

svn commit: r649860 - in /tapestry/tapestry5/trunk: tapestry-core/src/main/java/org/apache/tapestry/internal/services/ tapestry-core/src/main/java/org/apache/tapestry/services/ tapestry-core/src/test/java/org/apache/tapestry/integration/ tapestry-core/...

Author: hlship
Date: Sat Apr 19 15:48:31 2008
New Revision: 649860

URL: http://svn.apache.org/viewvc?rev=649860&view=rev
Log:
TAPESTRY-2159: YSlow Recommendation: Version bundled javascript and use far-future expires header

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ResourceStreamerImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ResourceStreamerImplTest.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/util/TimeInterval.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ResourceStreamerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ResourceStreamerImpl.java?rev=649860&r1=649859&r2=649860&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ResourceStreamerImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/ResourceStreamerImpl.java Sat Apr 19 15:48:31 2008
@@ -16,6 +16,7 @@
 
 import org.apache.tapestry.ioc.Resource;
 import org.apache.tapestry.ioc.internal.util.InternalUtils;
+import org.apache.tapestry.ioc.util.TimeInterval;
 import org.apache.tapestry.services.Response;
 
 import java.io.BufferedInputStream;
@@ -34,6 +35,8 @@
 
     private final int _bufferSize = 1000;
 
+    private static final long TEN_YEARS = new TimeInterval("10y").milliseconds();
+
     public ResourceStreamerImpl(final Response response, Map<String, String> configuration)
     {
         _response = response;
@@ -56,6 +59,7 @@
         long lastModified = connection.getLastModified();
 
         _response.setDateHeader("Last-Modified", lastModified);
+        _response.setDateHeader("Expires", lastModified + TEN_YEARS);
 
         String contentType = connection.getContentType();
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java?rev=649860&r1=649859&r2=649860&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/services/TapestryModule.java Sat Apr 19 15:48:31 2008
@@ -97,6 +97,13 @@
 
     private final EnvironmentalShadowBuilder _environmentalBuilder;
 
+
+    /**
+     * We inject all sorts of common dependencies (including builders) into the module itself (note: even though some of
+     * these service are defined by the module itself, that's ok because services are always lazy proxies).  This isn't
+     * about efficiency (it may be slightly more efficient, but not in any noticable way), it's about eliminating the
+     * need to keep injecting these dependencies into invividual service builder and contribution methods.
+     */
     public TapestryModule(PipelineBuilder pipelineBuilder,
 
                           PropertyShadowBuilder shadowBuilder,
@@ -136,7 +143,6 @@
         _strategyBuilder = strategyBuilder;
         _componentInstantiatorSource = componentInstantiatorSource;
         _propertyAccess = propertyAccess;
-
         _updateListenerHub = updateListenerHub;
         _request = request;
         _response = response;
@@ -240,6 +246,9 @@
 
     public static void contributeClasspathAssetAliasManager(MappedConfiguration<String, String> configuration,
 
+                                                            @Symbol(TapestryConstants.TAPESTRY_VERSION_SYMBOL)
+                                                            String version,
+
                                                             // @Inject not needed, because this isn't a service builder method
                                                             @Symbol("tapestry.scriptaculous.path")
                                                             String scriptaculousPath,
@@ -247,11 +256,15 @@
                                                             @Symbol("tapestry.datepicker.path")
                                                             String datepickerPath)
     {
-        configuration.add("tapestry", "org/apache/tapestry");
+        // TAPESTRY-2159:  All the classpath assets are inside a version numbered folder (i.e., 5.0.12).
+        // For scriptaculous, etc., this version is not the version of the library, but the version
+        // bundled with Tapestry.
+
+        configuration.add("tapestry/" + version, "org/apache/tapestry");
 
-        configuration.add("scriptaculous", scriptaculousPath);
+        configuration.add("scriptaculous/" + version, scriptaculousPath);
 
-        configuration.add("datepicker", datepickerPath);
+        configuration.add("datepicker/" + version, datepickerPath);
     }
 
     public static void contributeComponentClassResolver(Configuration<LibraryMapping> configuration)
@@ -1998,9 +2011,9 @@
     /**
      * Contributes filters: <dl> <dt>Ajax</dt> <dd>Determines if the request is Ajax oriented, and redirects to an
      * alternative handler if so</dd> <dt>ImmediateRender</dt> <dd>When {@linkplain
-     * org.apache.tapestry.TapestryConstants#SUPPRESS_REDIRECT_FROM_ACTION_REQUESTS_SYMBOL immediate action response
-     * rendering} is enabled, generates the markup response (instead of a page redirect response, which is the normal
-     * behavior) </dd> <dt>Secure</dt> <dd>Sends a redirect if an non-secure request accesses a secure page</dd></dl>
+     * TapestryConstants#SUPPRESS_REDIRECT_FROM_ACTION_REQUESTS_SYMBOL immediate action response rendering} is enabled,
+     * generates the markup response (instead of a page redirect response, which is the normal behavior) </dd>
+     * <dt>Secure</dt> <dd>Sends a redirect if an non-secure request accesses a secure page</dd></dl>
      */
     public void contributeComponentEventRequestHandler(OrderedConfiguration<ComponentEventRequestFilter> configuration,
                                                        final RequestSecurityManager requestSecurityManager,

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?rev=649860&r1=649859&r2=649860&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/integration/IntegrationTests.java Sat Apr 19 15:48:31 2008
@@ -647,7 +647,7 @@
 
         // The lack of a leading slash indicates that the path was optimized, see TAPESTRY-1502
 
-        assertAttribute("//img[@id='title:sort']/@src", "assets/tapestry/corelib/components/sort-asc.png");
+        assertAttribute("//img[@id='title:sort']/@src", "assets/tapestry/UNKNOWN/corelib/components/sort-asc.png");
         assertAttribute("//img[@id='title:sort']/@alt", "[Asc]");
 
         clickAndWait("link=1");
@@ -656,7 +656,7 @@
 
         clickAndWait("link=Title");
 
-        assertAttribute("//img[@id='title:sort']/@src", "assets/tapestry/corelib/components/sort-desc.png");
+        assertAttribute("//img[@id='title:sort']/@src", "assets/tapestry/UNKNOWN/corelib/components/sort-desc.png");
         assertAttribute("//img[@id='title:sort']/@alt", "[Desc]");
 
         clickAndWait("link=reset the Grid");
@@ -817,8 +817,8 @@
 
         // The lack of a leading slash indicates that the path was optimized, see TAPESTRY-1502
 
-        assertAttributeSeries("//script[%d]/@src", 1, "assets/scriptaculous/prototype.js",
-                              "assets/scriptaculous/scriptaculous.js");
+        assertAttributeSeries("//script[%d]/@src", 1, "assets/scriptaculous/UNKNOWN/prototype.js",
+                              "assets/scriptaculous/UNKNOWN/scriptaculous.js");
 
         clickAndWait("link=Clear Data");
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ResourceStreamerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ResourceStreamerImplTest.java?rev=649860&r1=649859&r2=649860&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ResourceStreamerImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/ResourceStreamerImplTest.java Sat Apr 19 15:48:31 2008
@@ -57,6 +57,7 @@
 
         train_setContentLength(hsr, anyInt());
         train_setDateHeader(hsr, eq("Last-Modified"), anyLong());
+        train_setDateHeader(hsr, eq("Expires"), anyLong());
         train_setContentType(hsr, contentType);
         train_getOutputStream(hsr, new TestServletOutputStream());
 

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/util/TimeInterval.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/util/TimeInterval.java?rev=649860&r1=649859&r2=649860&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/util/TimeInterval.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry/ioc/util/TimeInterval.java Sat Apr 19 15:48:31 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 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.
@@ -21,23 +21,15 @@
 import java.util.regex.Pattern;
 
 /**
- * Used to represent a period of time, specifically as a configuration value. This is often
- * used to specify timeouts.
+ * Used to represent a period of time, specifically as a configuration value. This is often used to specify timeouts.
  * <p/>
  * TimePeriods are parsed from strings.
  * <p/>
- * The string specifys a number of terms. The values of all the terms are summed together to form
- * the total time period. Each term consists of a number followed by a unit.
- * Units (from largest to smallest) are:
- * <dl>
- * <dt>d <dd>day
- * <dt>h <dd>hour
- * <dt>m <dd>minute
- * <dt>s <dd>second
- * <dt>ms <dd>millisecond
- * </dl>
- * <p>  Example: "2 h 30 m". By convention, terms are specified largest to smallest.  A term without a unit is assumed to be milliseconds.  Units are case insensitive ("h" or "H"
- * are treated the same).
+ * The string specifys a number of terms. The values of all the terms are summed together to form the total time period.
+ * Each term consists of a number followed by a unit. Units (from largest to smallest) are: <dl> <dt>y <dd>year <dt>d
+ * <dd>day <dt>h <dd>hour <dt>m <dd>minute <dt>s <dd>second <dt>ms <dd>millisecond </dl> <p>  Example: "2 h 30 m". By
+ * convention, terms are specified largest to smallest.  A term without a unit is assumed to be milliseconds.  Units are
+ * case insensitive ("h" or "H" are treated the same).
  */
 public class TimeInterval
 {
@@ -50,8 +42,9 @@
         UNITS.put("ms", 1l);
         UNITS.put("s", MILLISECOND);
         UNITS.put("m", 60 * MILLISECOND);
-        UNITS.put("h", 60 * 60 * MILLISECOND);
-        UNITS.put("d", 24 * 60 * 60 * MILLISECOND);
+        UNITS.put("h", 60 * UNITS.get("m"));
+        UNITS.put("d", 24 * UNITS.get("h"));
+        UNITS.put("y", 365 * UNITS.get("d"));
     }
 
     private static final Pattern PATTERN = Pattern.compile("\\s*(\\d+)\\s*([a-z]*)", Pattern.CASE_INSENSITIVE);