You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by jk...@apache.org on 2014/12/08 17:36:49 UTC
tapestry-5 git commit: TAP5-2424: Trim the applicationFolderPrefix
for Event Request
Repository: tapestry-5
Updated Branches:
refs/heads/master d871f66b3 -> 91bd025fc
TAP5-2424: Trim the applicationFolderPrefix for Event Request
Use the same method used in Page Request for Event Request to remove
the applicationFolderPrefix.
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/91bd025f
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/91bd025f
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/91bd025f
Branch: refs/heads/master
Commit: 91bd025fc4a65f14f2e41a2373804812f6f6be51
Parents: d871f66
Author: Nicolas Bouillon <ni...@bouil.org>
Authored: Fri Dec 5 11:09:40 2014 +0100
Committer: Jochen Kemnade <jo...@eddyson.de>
Committed: Mon Dec 8 17:35:26 2014 +0100
----------------------------------------------------------------------
.../services/ComponentEventLinkEncoderImpl.java | 60 +++++++++-----------
.../ComponentEventLinkEncoderImplTest.java | 37 +++++++++++-
2 files changed, 62 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/91bd025f/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java
index c087893..5baec01 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImpl.java
@@ -252,35 +252,22 @@ public class ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder
return builder.toString();
}
- private String peekFirst(List<String> path)
- {
- if (path.size() == 0)
- {
- return null;
- }
-
- return path.get(0);
- }
-
public ComponentEventRequestParameters decodeComponentEventRequest(Request request)
{
String explicitLocale = null;
// Split the path around slashes into a mutable list of terms, which will be consumed term by term.
- List<String> path = splitPath(request.getPath());
+ String requestPath = request.getPath();
- if (this.applicationFolder.length() > 0)
+ if (applicationFolderPrefix != null)
{
- // TODO: Should this be case insensitive
+ requestPath = removeApplicationPrefix(requestPath);
+ }
+
+ List<String> path = splitPath(requestPath);
- String inPath = path.remove(0);
- if (!inPath.equals(this.applicationFolder))
- {
- return null;
- }
- }
if (path.isEmpty())
{
@@ -408,21 +395,7 @@ public class ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder
if (applicationFolderPrefix != null)
{
- int prefixLength = applicationFolderPrefix.length();
-
- assert path.substring(0, prefixLength).equalsIgnoreCase(applicationFolderPrefix);
-
- // This checks that the character after the prefix is a slash ... the extra complexity
- // only seems to occur in Selenium. There's some ambiguity about what to do with a request for
- // the application folder that doesn't end with a slash. Manuyal with Chrome and IE 8 shows that such
- // requests are passed through with a training slash, automated testing with Selenium and FireFox
- // can include requests for the folder without the trailing slash.
-
- assert path.length() <= prefixLength || path.charAt(prefixLength) == '/';
-
- // Strip off the folder prefix (i.e., "/foldername"), leaving the rest of the path (i.e., "/en/pagename").
-
- path = path.substring(prefixLength);
+ path = removeApplicationPrefix(path);
}
@@ -488,6 +461,25 @@ public class ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder
return result;
}
+ private String removeApplicationPrefix(String path) {
+ int prefixLength = applicationFolderPrefix.length();
+
+ assert path.substring(0, prefixLength).equalsIgnoreCase(applicationFolderPrefix);
+
+ // This checks that the character after the prefix is a slash ... the extra complexity
+ // only seems to occur in Selenium. There's some ambiguity about what to do with a request for
+ // the application folder that doesn't end with a slash. Manuyal with Chrome and IE 8 shows that such
+ // requests are passed through with a training slash, automated testing with Selenium and FireFox
+ // can include requests for the folder without the trailing slash.
+
+ assert path.length() <= prefixLength || path.charAt(prefixLength) == '/';
+
+ // Strip off the folder prefix (i.e., "/foldername"), leaving the rest of the path (i.e., "/en/pagename").
+
+ path = path.substring(prefixLength);
+ return path;
+ }
+
private PageRenderRequestParameters checkIfPage(Request request, String pageName, String pageActivationContext)
{
if (!componentClassResolver.isPageName(pageName))
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/91bd025f/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImplTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImplTest.java
index a2b24df..a9f615f 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImplTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentEventLinkEncoderImplTest.java
@@ -360,7 +360,6 @@ public class ComponentEventLinkEncoderImplTest extends InternalBaseTestCase
verify();
}
-
@Test
public void context_passed_in_path_without_final_slash() throws Exception
{
@@ -443,4 +442,40 @@ public class ComponentEventLinkEncoderImplTest extends InternalBaseTestCase
verify();
}
+
+ @Test
+ public void decode_compoent_event_request_with_slash_in_context_path() throws Exception
+ {
+ ComponentClassResolver resolver = mockComponentClassResolver();
+ Request request = mockRequest();
+ Response response = mockResponse();
+ LocalizationSetter ls = mockLocalizationSetter();
+ MetaDataLocator metaDataLocator = neverWhitelistProtected();
+
+ expect(ls.isSupportedLocaleName("page.component:event")).andReturn(false);
+
+ train_getParameter(request, InternalConstants.PAGE_CONTEXT_NAME, null);
+ train_getParameter(request, InternalConstants.CONTAINER_PAGE_NAME, null);
+ train_getLocale(request, Locale.ENGLISH);
+
+ ls.setNonPersistentLocaleFromLocaleName("en");
+
+ train_getPath(request, "/foo/bar/page.component:event");
+
+ train_isPageName(resolver, "page", true);
+
+ train_canonicalizePageName(resolver, "page", "Page");
+
+ replay();
+
+ ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls,
+ response, null, null, null, true, null, "foo/bar", metaDataLocator, null);
+
+ ComponentEventRequestParameters parameters = linkEncoder.decodeComponentEventRequest(request);
+ assertNotNull(parameters);
+ assertEquals(parameters.getActivePageName(), "Page");
+ assertEquals(parameters.getEventType(), "event");
+
+ verify();
+ }
}