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/09/01 21:01:36 UTC

svn commit: r1164205 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/services/ test/appfolder/ test/groovy/org/apache/tapestry5/integration/appfolder/pages/ test/groovy/org/apache/tapestry5/internal/services/te...

Author: hlship
Date: Thu Sep  1 19:01:35 2011
New Revision: 1164205

URL: http://svn.apache.org/viewvc?rev=1164205&view=rev
Log:
TAP5-743: Fix logic inside ComponentEventLinkEncoderImpl that checks for the application folder (when configured)

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/test/appfolder/static.html
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/pages/Index.groovy
    tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/templates/PageTemplateLocatorTest.groovy
    tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/appfolder/pages/Index.tml

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java?rev=1164205&r1=1164204&r2=1164205&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java Thu Sep  1 19:01:35 2011
@@ -46,6 +46,8 @@ public class ComponentEventLinkEncoderIm
 
     private final String applicationFolder;
 
+    private final String applicationFolderPrefix;
+
     private static final int BUFFER_SIZE = 100;
 
     private static final char SLASH = '/';
@@ -60,7 +62,7 @@ public class ComponentEventLinkEncoderIm
     // path is most likely a page render request. After the optional event name,
     // the next piece is the action context, which is the remainder of the path.
 
-    private final Pattern PATH_PATTERN;
+    private final Pattern COMPONENT_EVENT_REQUEST_PATH_PATTERN;
 
     // Constants for the match groups in the above pattern.
     private static final int LOGICAL_PAGE_NAME = 1;
@@ -85,12 +87,16 @@ public class ComponentEventLinkEncoderIm
         this.encodeLocaleIntoPath = encodeLocaleIntoPath;
         this.applicationFolder = applicationFolder;
 
-        String folderPattern = applicationFolder.equals("") ? "" : SLASH + applicationFolder;
+        boolean hasAppFolder = applicationFolder.equals("");
+
+        applicationFolderPrefix = hasAppFolder ? null : SLASH + applicationFolder + SLASH;
+
+        String applicationFolderPattern = hasAppFolder ? "" : applicationFolder + SLASH;
 
-        PATH_PATTERN = Pattern.compile(
+        COMPONENT_EVENT_REQUEST_PATH_PATTERN = Pattern.compile(
 
                 "^/" + // The leading slash is recognized but skipped
-                        folderPattern + // The folder containing the application (TAP5-743)
+                        applicationFolderPattern + // The folder containing the application (TAP5-743)
                         "(((\\w+)/)*(\\w+))" + // A series of folder names leading up to the page name, forming
                         // the logical page name (may include the locale name)
                         "(\\.(\\w+(\\.\\w+)*))?" + // The first dot separates the page name from the nested
@@ -221,7 +227,7 @@ public class ComponentEventLinkEncoderIm
 
     public ComponentEventRequestParameters decodeComponentEventRequest(Request request)
     {
-        Matcher matcher = PATH_PATTERN.matcher(request.getPath());
+        Matcher matcher = COMPONENT_EVENT_REQUEST_PATH_PATTERN.matcher(request.getPath());
 
         if (!matcher.matches())
             return null;
@@ -279,6 +285,19 @@ public class ComponentEventLinkEncoderIm
 
         String path = request.getPath();
 
+
+        if (applicationFolderPrefix != null)
+        {
+            int prefixLength = applicationFolderPrefix.length();
+
+            assert path.substring(0, prefixLength).equalsIgnoreCase(applicationFolderPrefix);
+
+            // Strip off the folder prefix (i.e., "/foldername"), leaving the rest of the path (i.e., "/en/pagename").
+
+            path = path.substring(prefixLength - 1);
+        }
+
+
         // TAPESTRY-1343: Sometimes path is the empty string (it should always be at least a slash,
         // but Tomcat may return the empty string for a root context request).
 

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/appfolder/static.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/appfolder/static.html?rev=1164205&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/appfolder/static.html (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/appfolder/static.html Thu Sep  1 19:01:35 2011
@@ -0,0 +1,9 @@
+<html>
+
+<h1>Static File in Context</h1>
+
+<p>
+    <a href="t5app">to Tapestry application</a>
+</p>
+
+</html>
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/pages/Index.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/pages/Index.groovy?rev=1164205&r1=1164204&r2=1164205&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/pages/Index.groovy (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/appfolder/pages/Index.groovy Thu Sep  1 19:01:35 2011
@@ -1,7 +1,15 @@
 package org.apache.tapestry5.integration.appfolder.pages
 
-/**
- *
- */
-class Index {
+import org.apache.tapestry5.alerts.AlertManager
+import org.apache.tapestry5.ioc.annotations.Inject
+
+class Index
+{
+    @Inject
+    private AlertManager alertManager
+
+    void onActionFromShowAlert()
+    {
+        alertManager.info "index page alert"
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/templates/PageTemplateLocatorTest.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/templates/PageTemplateLocatorTest.groovy?rev=1164205&r1=1164204&r2=1164205&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/templates/PageTemplateLocatorTest.groovy (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/templates/PageTemplateLocatorTest.groovy Thu Sep  1 19:01:35 2011
@@ -25,7 +25,7 @@ class PageTemplateLocatorTest extends In
 
         replay()
 
-        closure.call(new PageTemplateLocator(root, resolver))
+        closure.call(new PageTemplateLocator(root, resolver, ""))
 
         verify()
     }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/appfolder/pages/Index.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/appfolder/pages/Index.tml?rev=1164205&r1=1164204&r2=1164205&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/appfolder/pages/Index.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/appfolder/pages/Index.tml Thu Sep  1 19:01:35 2011
@@ -2,8 +2,18 @@
 
 <h1>App Folder Demo Application</h1>
 
+<t:alerts/>
+
 <img src="${context:images/t5-logo.png}" alt="Logo"/>
 
-<t:pagelink page="contexttemplate">context template demo</t:pagelink>
+<p>
+
+    <t:pagelink page="contexttemplate">context template demo</t:pagelink>
+
+</p>
+
+<p>
+    <t:actionlink t:id="showAlert">show index page alert</t:actionlink>
+</p>
 
 </html>