tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r548533 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry/internal/services/PageTemplateLocatorImpl.java test/java/org/apache/tapestry/internal/services/PageTemplateLocatorImplTest.java
Date Mon, 18 Jun 2007 23:47:16 GMT
Author: hlship
Date: Mon Jun 18 16:47:15 2007
New Revision: 548533

URL: http://svn.apache.org/viewvc?view=rev&rev=548533
Log:
TAPESTRY-1590: Component template is located based on logical page/component name, rather
than on the class name itself

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageTemplateLocatorImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageTemplateLocatorImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageTemplateLocatorImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageTemplateLocatorImpl.java?view=diff&rev=548533&r1=548532&r2=548533
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageTemplateLocatorImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry/internal/services/PageTemplateLocatorImpl.java
Mon Jun 18 16:47:15 2007
@@ -20,6 +20,7 @@
 
 import org.apache.tapestry.internal.InternalConstants;
 import org.apache.tapestry.ioc.Resource;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
 import org.apache.tapestry.model.ComponentModel;
 import org.apache.tapestry.services.ComponentClassResolver;
 
@@ -41,10 +42,21 @@
 
         // A bit of a hack, but should work.
 
-        if (!className.contains(".pages."))
-            return null;
+        if (!className.contains(".pages.")) return null;
 
         String logicalName = _resolver.resolvePageClassNameToPageName(className);
+
+        int slashx = logicalName.lastIndexOf('/');
+
+        if (slashx > 0)
+        {
+            // However, the logical name isn't quite what we want. It may have been somewhat
+            // trimmed.
+
+            String simpleClassName = InternalUtils.lastTerm(className);
+
+            logicalName = logicalName.substring(0, slashx + 1) + simpleClassName;
+        }
 
         String path = format("WEB-INF/%s.%s", logicalName, InternalConstants.TEMPLATE_EXTENSION);
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageTemplateLocatorImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageTemplateLocatorImplTest.java?view=diff&rev=548533&r1=548532&r2=548533
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageTemplateLocatorImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry/internal/services/PageTemplateLocatorImplTest.java
Mon Jun 18 16:47:15 2007
@@ -70,6 +70,41 @@
         verify();
     }
 
+    /**
+     * Because of how Tapestry maps class names to logical page names, part of the name may
be have
+     * been stripped off and we want to make sure we get it back.
+     */
+    @Test
+    public void uses_simple_class_name_in_folders()
+    {
+        ComponentModel model = mockComponentModel();
+        Resource root = mockResource();
+        Resource withExtension = mockResource();
+        Resource forLocale = mockResource();
+        Locale locale = Locale.FRENCH;
+        String className = "myapp.pages.foo.CreateFoo";
+
+        ComponentClassResolver resolver = mockComponentClassResolver();
+
+        train_getComponentClassName(model, className);
+
+        // Notice: foo/Create not foo/CreateFoo; we're simulating how the redundancy gets
stripped
+        // out of the class name.
+        train_resolvePageClassNameToPageName(resolver, className, "foo/Create");
+
+        // Abnd here's where we're showing that PTLI stitches it back together.
+        train_forFile(root, "WEB-INF/foo/CreateFoo.html", withExtension);
+        train_forLocale(withExtension, locale, forLocale);
+
+        replay();
+
+        PageTemplateLocator locator = new PageTemplateLocatorImpl(root, resolver);
+
+        assertSame(locator.findPageTemplateResource(model, locale), forLocale);
+
+        verify();
+    }
+
     @Test
     public void template_not_found()
     {



Mime
View raw message