tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mluse...@apache.org
Subject svn commit: r1189123 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/ main/java/org/apache/tapestry5/internal/services/assets/ main/java/org/apache/tapestry5/services/assets/ test/java/org/apache/tapestry5/internal/serv...
Date Wed, 26 Oct 2011 10:50:59 GMT
Author: mlusetti
Date: Wed Oct 26 10:50:59 2011
New Revision: 1189123

URL: http://svn.apache.org/viewvc?rev=1189123&view=rev
Log:
TAP5-1483 Make configuration knob to use of BaseURLSource to build fully qualified Assets
URL, defaults to false

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/AssetPathConstructorImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetAliasManagerImplTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ContextAssetFactoryTest.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java?rev=1189123&r1=1189122&r2=1189123&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/SymbolConstants.java
Wed Oct 26 10:50:59 2011
@@ -353,4 +353,11 @@ public class SymbolConstants
      * @since 5.3
      */
     public static final String APPLICATION_FOLDER = "tapestry.application-folder";
+
+    /**
+     * Boolean value to indicate if every {@link  org.apache.tapestry5.Asset2} should be
fully qualified or not.
+     * Default to <code>false</code> meaning no Asset URL will be fully qualified.
+     * @since 5.3
+     */
+    public static final String ASSET_URL_FULL_QUALIFIED = "tapestry.asset-url-fully-qualified";
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/AssetPathConstructorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/AssetPathConstructorImpl.java?rev=1189123&r1=1189122&r2=1189123&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/AssetPathConstructorImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/AssetPathConstructorImpl.java
Wed Oct 26 10:50:59 2011
@@ -17,6 +17,7 @@ package org.apache.tapestry5.internal.se
 import org.apache.tapestry5.SymbolConstants;
 import org.apache.tapestry5.internal.services.RequestConstants;
 import org.apache.tapestry5.ioc.annotations.Symbol;
+import org.apache.tapestry5.services.BaseURLSource;
 import org.apache.tapestry5.services.Request;
 import org.apache.tapestry5.services.assets.AssetPathConstructor;
 
@@ -26,15 +27,26 @@ public class AssetPathConstructorImpl im
 
     private final String prefix;
 
+    private final BaseURLSource baseURLSource;
+
+    private final boolean fullyQualified;
+
     public AssetPathConstructorImpl(Request request,
+                                    BaseURLSource baseURLSource,
 
                                     @Symbol(SymbolConstants.APPLICATION_VERSION)
                                     String applicationVersion,
 
                                     @Symbol(SymbolConstants.APPLICATION_FOLDER)
-                                    String applicationFolder)
+                                    String applicationFolder,
+
+                                    @Symbol(SymbolConstants.ASSET_URL_FULL_QUALIFIED)
+                                    boolean fullyQualified)
     {
         this.request = request;
+        this.baseURLSource = baseURLSource;
+
+        this.fullyQualified = fullyQualified;
 
         String folder = applicationFolder.equals("") ? "" : "/" + applicationFolder;
 
@@ -43,7 +55,12 @@ public class AssetPathConstructorImpl im
 
     public String constructAssetPath(String virtualFolder, String path)
     {
-        StringBuilder builder = new StringBuilder(request.getContextPath());
+        StringBuilder builder = new StringBuilder();
+
+        if (fullyQualified)
+            builder.append(baseURLSource.getBaseURL(request.isSecure()));
+
+        builder.append(request.getContextPath());
         builder.append(prefix);
         builder.append(virtualFolder);
         builder.append('/');

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java?rev=1189123&r1=1189122&r2=1189123&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/assets/AssetsModule.java
Wed Oct 26 10:50:59 2011
@@ -45,6 +45,7 @@ public class AssetsModule
         configuration.add(SymbolConstants.MINIFICATION_ENABLED, SymbolConstants.PRODUCTION_MODE_VALUE);
         configuration.add(SymbolConstants.GZIP_COMPRESSION_ENABLED, "true");
         configuration.add(SymbolConstants.COMBINE_SCRIPTS, SymbolConstants.PRODUCTION_MODE_VALUE);
+        configuration.add(SymbolConstants.ASSET_URL_FULL_QUALIFIED, "false");
     }
 
     // The use of decorators is to allow third-parties to get their own extensions

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetAliasManagerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetAliasManagerImplTest.java?rev=1189123&r1=1189122&r2=1189123&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetAliasManagerImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ClasspathAssetAliasManagerImplTest.java
Wed Oct 26 10:50:59 2011
@@ -18,6 +18,7 @@ import org.apache.tapestry5.internal.ser
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.util.UnknownValueException;
+import org.apache.tapestry5.services.BaseURLSource;
 import org.apache.tapestry5.services.ClasspathAssetAliasManager;
 import org.apache.tapestry5.services.Request;
 import org.testng.annotations.DataProvider;
@@ -79,12 +80,14 @@ public class ClasspathAssetAliasManagerI
     {
         Request request = mockRequest();
 
+        BaseURLSource baseURLSource = newMock(BaseURLSource.class);
+
         train_getContextPath(request, "/ctx");
 
         replay();
 
         ClasspathAssetAliasManager manager = new ClasspathAssetAliasManagerImpl(new AssetPathConstructorImpl(request,
-                APP_VERSION, ""), configuration());
+                baseURLSource, APP_VERSION, "", false), configuration());
 
         String expectedPath = "/ctx" + RequestConstants.ASSET_PATH_PREFIX + APP_VERSION +
"/" + expectedClientURL;
         assertEquals(manager.toClientURL(resourcePath), expectedPath);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ContextAssetFactoryTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ContextAssetFactoryTest.java?rev=1189123&r1=1189122&r2=1189123&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ContextAssetFactoryTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ContextAssetFactoryTest.java
Wed Oct 26 10:50:59 2011
@@ -19,6 +19,7 @@ import org.apache.tapestry5.internal.ser
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
 import org.apache.tapestry5.ioc.Resource;
 import org.apache.tapestry5.services.AssetFactory;
+import org.apache.tapestry5.services.BaseURLSource;
 import org.apache.tapestry5.services.Context;
 import org.apache.tapestry5.services.Request;
 import org.testng.annotations.Test;
@@ -31,7 +32,7 @@ public class ContextAssetFactoryTest ext
     public void root_resource()
     {
         Context context = mockContext();
-        Request request = mockRequest();
+        // Request request = mockRequest();
 
         replay();
 
@@ -48,14 +49,63 @@ public class ContextAssetFactoryTest ext
         Context context = mockContext();
         Request request = mockRequest();
 
+        BaseURLSource baseURLSource = newMock(BaseURLSource.class);
+
+        Resource r = new ContextResource(context, "foo/Bar.txt");
+
+        train_getContextPath(request, "/context");
+
+        replay();
+
+        AssetFactory factory = new ContextAssetFactory(
+                                    new AssetPathConstructorImpl(request,
+                                                                baseURLSource,
+                                                                "4.5.6",
+                                                                "",
+                                                                false
+                                                            ),
+                                    context,
+                                    new IdentityAssetPathConverter()
+                                );
+
+        Asset asset = factory.createAsset(r);
+
+        assertSame(asset.getResource(), r);
+        assertEquals(asset.toClientURL(), "/context/assets/4.5.6/ctx/foo/Bar.txt");
+
+        // In real life, toString() is the same as toClientURL(), but we're testing
+        // that the optimize method is getting called, basically.
+
+        assertEquals(asset.toString(), "/context/assets/4.5.6/ctx/foo/Bar.txt");
+
+        verify();
+    }
+
+    @Test
+    public void asset_client_URL_fully_qualified()
+    {
+        Context context = mockContext();
+        Request request = mockRequest();
+
+        BaseURLSource baseURLSource = newMock(BaseURLSource.class);
+
         Resource r = new ContextResource(context, "foo/Bar.txt");
 
         train_getContextPath(request, "/context");
+        train_getBaseSource(baseURLSource, request);
 
         replay();
 
-        AssetFactory factory = new ContextAssetFactory(new AssetPathConstructorImpl(request,
"4.5.6", ""), context,
-                new IdentityAssetPathConverter());
+        AssetFactory factory = new ContextAssetFactory(
+                                    new AssetPathConstructorImpl(request,
+                                                                baseURLSource,
+                                                                "4.5.6",
+                                                                "",
+                                                                true
+                                                            ),
+                                    context,
+                                    new IdentityAssetPathConverter()
+                                );
 
         Asset asset = factory.createAsset(r);
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java?rev=1189123&r1=1189122&r2=1189123&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/test/InternalBaseTestCase.java
Wed Oct 26 10:50:59 2011
@@ -171,6 +171,12 @@ public class InternalBaseTestCase extend
         expect(request.getContextPath()).andReturn(contextPath).atLeastOnce();
     }
 
+    protected final void train_getBaseSource(BaseURLSource baseURLSource, Request request)
+    {
+        expect(request.isSecure()).andReturn(false);
+        expect(baseURLSource.getBaseURL(false)).andReturn("");
+    }
+
     protected final void train_resolvePageClassNameToPageName(ComponentClassResolver resolver,
String pageClassName,
                                                               String pageName)
     {



Mime
View raw message