You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by jk...@apache.org on 2007/05/03 19:24:29 UTC

svn commit: r534938 - in /tapestry/tapestry4/trunk/tapestry-framework/src: descriptor/META-INF/ java/org/apache/tapestry/asset/ java/org/apache/tapestry/services/impl/ test/org/apache/tapestry/asset/

Author: jkuhnert
Date: Thu May  3 10:24:28 2007
New Revision: 534938

URL: http://svn.apache.org/viewvc?view=rev&rev=534938
Log:
Made TemplateSource use the same kind of context relative resource finding logic that SpecificationResolver impls use. Need to re-factor this back out into one centralized service. I'm thinking assetSource or similar.

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.parse.xml
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ContextAssetFactory.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/TemplateSourceImpl.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ContextAssetFactoryTest.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.parse.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.parse.xml?view=diff&rev=534938&r1=534937&r2=534938
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.parse.xml (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.parse.xml Thu May  3 10:24:28 2007
@@ -82,6 +82,7 @@
         <set-service property="parser" service-id="TemplateParser"/>
         <set-service property="delegate" service-id="TemplateSourceDelegate"/>
         <set-object property="contextRoot" value="infrastructure:contextRoot"/>
+        <set-object property="applicationId" value="infrastructure:applicationId"/>
         <set-service property="componentSpecificationResolver" service-id="tapestry.page.ComponentSpecificationResolver"/>
         <set-object property="componentPropertySource"  value="infrastructure:componentPropertySource"/>
         <set-object property="localizer" value="infrastructure:resourceLocalizer"/>

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ContextAssetFactory.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ContextAssetFactory.java?view=diff&rev=534938&r1=534937&r2=534938
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ContextAssetFactory.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/asset/ContextAssetFactory.java Thu May  3 10:24:28 2007
@@ -58,6 +58,12 @@
         Resource assetResource = baseResource.getRelativeResource("/").getRelativeResource(path);
         Resource localized = _localizer.findLocalization(assetResource, locale);
 
+        if (localized == null) {
+
+            assetResource = baseResource.getRelativeResource(path);
+            localized = _localizer.findLocalization(assetResource, locale);
+        }
+
         if (localized == null && spec != null && spec.getLocation().getResource() != null) {
             // try relative to specification
 

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/TemplateSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/TemplateSourceImpl.java?view=diff&rev=534938&r1=534937&r2=534938
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/TemplateSourceImpl.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/TemplateSourceImpl.java Thu May  3 10:24:28 2007
@@ -56,7 +56,7 @@
 
     public static final String TEMPLATE_ENCODING_PROPERTY_NAME = "org.apache.tapestry.template-encoding";
 
-    private static final String WEB_INF = "/WEB-INF/";
+    private static final String WEB_INF = "WEB-INF/";
 
     private static final int BUFFER_SIZE = 2000;
 
@@ -103,6 +103,19 @@
     /** @since 4.1.2 */
     private AssetFactory _contextAssetFactory;
 
+    private String _applicationId;
+
+    private Resource _webInfLocation;
+
+    private Resource _webInfAppLocation;
+
+    public void initializeService()
+    {
+        _webInfLocation = _contextRoot.getRelativeResource(WEB_INF);
+
+        _webInfAppLocation = _webInfLocation.getRelativeResource(_applicationId + "/");
+    }
+
     /**
      * Clears the template cache. This is used during debugging.
      */
@@ -287,19 +300,18 @@
 
             if (_classpathAssetFactory.assetExists(component.getSpecification(), base, templateName, locale))
                 return _classpathAssetFactory.createAsset(base, component.getSpecification(), templateName, locale, component.getLocation());
-
+            
             // else try various forms of context searches
 
             templateName = className.substring((index + packages[i].length()) + 1, className.length()).replaceAll("\\.", "/");
             templateName =  templateName + "." + templateExtension;
-            Resource context = component.getNamespace().getSpecificationLocation();
-            
-            if (_contextAssetFactory.assetExists(component.getSpecification(), context, "/" + templateName, locale)) {
 
-                return _classpathAssetFactory.createAsset(context, component.getSpecification(), "/" + templateName, locale, component.getLocation());
-            } else if (_contextAssetFactory.assetExists(component.getSpecification(), context, WEB_INF + templateName, locale)) {
+            if (_contextAssetFactory.assetExists(component.getSpecification(), _webInfAppLocation, templateName, locale)) {
+
+                return _contextAssetFactory.createAsset(_webInfAppLocation, component.getSpecification(),  templateName, locale, component.getLocation());
+            } else if (_contextAssetFactory.assetExists(component.getSpecification(), _webInfLocation, templateName, locale)) {
 
-                return _classpathAssetFactory.createAsset(context, component.getSpecification(), WEB_INF + templateName, locale, component.getLocation());
+                return _contextAssetFactory.createAsset(_webInfLocation, component.getSpecification(), templateName, locale, component.getLocation());
             }
         }
         
@@ -631,5 +643,10 @@
     public void setContextAssetFactory(AssetFactory contextAssetFactory)
     {
         _contextAssetFactory = contextAssetFactory;
+    }
+
+    public void setApplicationId(String applicationId)
+    {
+        _applicationId = applicationId;
     }
 }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ContextAssetFactoryTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ContextAssetFactoryTest.java?view=diff&rev=534938&r1=534937&r2=534938
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ContextAssetFactoryTest.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/asset/ContextAssetFactoryTest.java Thu May  3 10:24:28 2007
@@ -110,6 +110,8 @@
         trainGetRelativeResource(base, "asset.png", relative);
         trainGetLocalization(relative, Locale.FRENCH, null);
 
+        trainGetRelativeResource(base, "asset.png", relative);
+        trainGetLocalization(relative, Locale.FRENCH, null);
         expect(spec.getLocation()).andReturn(l);
         expect(l.getResource()).andReturn(null);