tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r500347 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/internal/services/ test/java/org/apache/tapestry/internal/services/
Date Fri, 26 Jan 2007 21:09:44 GMT
Author: hlship
Date: Fri Jan 26 13:09:43 2007
New Revision: 500347

URL: http://svn.apache.org/viewvc?view=rev&rev=500347
Log:
Change the way action URLs are formatted.

Added:
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentEventDispatcherTest.java
Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandler.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandlerImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkTarget.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventDispatcher.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LinkFactoryImplTest.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandler.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandler.java?view=diff&rev=500347&r1=500346&r2=500347
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandler.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandler.java
Fri Jan 26 13:09:43 2007
@@ -25,4 +25,11 @@
 {
     /** Handle the event, and return a generator that is used to create a response for the
client. */
     ActionResponseGenerator handle(ComponentInvocation invocation);
+
+    /**
+     * A convienience for handling a typical request, which returns a response generator
used to
+     * send the final response to the client.
+     */
+    ActionResponseGenerator handle(String logicalPageName, String nestedComponentId,
+            String eventType, String[] context);
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandlerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandlerImpl.java?view=diff&rev=500347&r1=500346&r2=500347
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandlerImpl.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkHandlerImpl.java
Fri Jan 26 13:09:43 2007
@@ -40,6 +40,17 @@
         _linkFactory = linkFactory;
     }
 
+    public ActionResponseGenerator handle(String logicalPageName, String nestedComponentId,
+            String eventType, String[] context)
+    {
+        ActionLinkTarget actionLinkTarget = new ActionLinkTarget(eventType, logicalPageName,
+                nestedComponentId);
+
+        ComponentInvocation invocation = new ComponentInvocation(actionLinkTarget, context);
+
+        return handle(invocation);
+    }
+
     public ActionResponseGenerator handle(ComponentInvocation invocation)
     {
         InvocationTarget target = invocation.getTarget();

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkTarget.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkTarget.java?view=diff&rev=500347&r1=500346&r2=500347
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkTarget.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ActionLinkTarget.java
Fri Jan 26 13:09:43 2007
@@ -12,51 +12,53 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry.internal.services;
-
-/**
- * It represents an invocation target for an action link.
- */
-public class ActionLinkTarget implements InvocationTarget
-{
-    private final String _action;
-
-    private final String _pageName;
-
-    private final String _componentNestedId;
-
-    public ActionLinkTarget(String action, String pageName, String componentNestedId)
-    {
-        _action = action;
-        _pageName = pageName;
-        _componentNestedId = componentNestedId;
-
-    }
-
-    public String getPath()
-    {
-        StringBuilder builder = new StringBuilder();
-        builder.append(_pageName);
-        builder.append(".");
-        builder.append(_action);
-        builder.append("/");
-        builder.append(_componentNestedId);
-        return builder.toString();
-    }
-
-    public String getAction()
-    {
-        return _action;
-    }
-
-    public String getComponentNestedId()
-    {
-        return _componentNestedId;
-    }
-
-    public String getPageName()
-    {
-        return _pageName;
-    }
-
-}
+package org.apache.tapestry.internal.services;
+
+/**
+ * It represents an invocation target for an action link.
+ */
+public class ActionLinkTarget implements InvocationTarget
+{
+    private final String _action;
+
+    private final String _pageName;
+
+    private final String _componentNestedId;
+
+    public ActionLinkTarget(String action, String pageName, String componentNestedId)
+    {
+        _action = action;
+        _pageName = pageName;
+        _componentNestedId = componentNestedId;
+
+    }
+
+    public String getPath()
+    {
+        StringBuilder builder = new StringBuilder();
+
+        builder.append(_pageName);
+        builder.append(".");
+        builder.append(_componentNestedId);
+        builder.append(".");
+        builder.append(_action);
+
+        return builder.toString();
+    }
+
+    public String getAction()
+    {
+        return _action;
+    }
+
+    public String getComponentNestedId()
+    {
+        return _componentNestedId;
+    }
+
+    public String getPageName()
+    {
+        return _pageName;
+    }
+
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventDispatcher.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventDispatcher.java?view=diff&rev=500347&r1=500346&r2=500347
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventDispatcher.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventDispatcher.java
Fri Jan 26 13:09:43 2007
@@ -48,22 +48,23 @@
         String logicalPageName = path.substring(1, dotx);
 
         int slashx = path.indexOf('/', dotx + 1);
+        if (slashx < 0)
+            slashx = path.length();
 
-        String eventType = path.substring(dotx + 1, slashx);
+        int lastDotx = path.lastIndexOf('.', slashx);
 
-        String remainder = path.substring(slashx + 1);
+        String nestedComponentId = dotx != lastDotx ? path.substring(dotx + 1, lastDotx)
: "";
 
-        String[] chunks = remainder.split("/");
+        String eventType = path.substring(lastDotx + 1, slashx);
 
-        String nestedComponentId = chunks[0];
+        String[] context = slashx < path.length() ? path.substring(slashx + 1).split("/")
+                : new String[0];
 
-        String[] context = new String[chunks.length - 1];
-        for (int i = 1; i < chunks.length; i++)
-            context[i - 1] = chunks[i];
-
-        ActionResponseGenerator responseGenerator = _actionLinkHandler
-                .handle(new ComponentInvocation(new ActionLinkTarget(eventType, logicalPageName,
-                        nestedComponentId), context));
+        ActionResponseGenerator responseGenerator = _actionLinkHandler.handle(
+                logicalPageName,
+                nestedComponentId,
+                eventType,
+                context);
 
         responseGenerator.sendClientResponse(response);
 

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentEventDispatcherTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentEventDispatcherTest.java?view=auto&rev=500347
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentEventDispatcherTest.java
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentEventDispatcherTest.java
Fri Jan 26 13:09:43 2007
@@ -0,0 +1,115 @@
+// Copyright 2007 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry.internal.services;
+
+import java.io.IOException;
+
+import static org.easymock.EasyMock.eq;
+
+import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.services.ActionResponseGenerator;
+import org.apache.tapestry.services.Dispatcher;
+import org.apache.tapestry.services.Request;
+import org.apache.tapestry.services.Response;
+import org.easymock.EasyMock;
+import org.testng.annotations.Test;
+
+public class ComponentEventDispatcherTest extends InternalBaseTestCase
+{
+    @Test
+    public void no_dot_in_path() throws Exception
+    {
+        ActionLinkHandler handler = newActionLinkHandler();
+        Request request = newRequest();
+        Response response = newResponse();
+
+        train_getPath(request, "/foo/bar/baz");
+
+        replay();
+
+        Dispatcher dispatcher = new ComponentEventDispatcher(handler);
+
+        assertFalse(dispatcher.dispatch(request, response));
+
+        verify();
+    }
+
+    protected final ActionLinkHandler newActionLinkHandler()
+    {
+        return newMock(ActionLinkHandler.class);
+    }
+
+    @Test
+    public void event_on_page() throws Exception
+    {
+        test("/foo/MyPage.anevent", "foo/MyPage", "", "anevent");
+    }
+
+    @Test
+    public void event_on_component_within_page() throws Exception
+    {
+        test("/foo/MyPage.fred.anevent", "foo/MyPage", "fred", "anevent");
+    }
+
+    @Test
+    public void event_on_nested_component_within_page() throws Exception
+    {
+        test("/foo/MyPage.barney.fred.anevent", "foo/MyPage", "barney.fred", "anevent");
+    }
+
+    @Test
+    public void page_event_with_context() throws Exception
+    {
+        test("/foo/MyPage.trigger/foo", "foo/MyPage", "", "trigger", "foo");
+    }
+
+    @Test
+    public void nested_component_event_with_context() throws Exception
+    {
+        test(
+                "/foo/MyPage.nested.trigger/foo/bar/baz",
+                "foo/MyPage",
+                "nested",
+                "trigger",
+                "foo",
+                "bar",
+                "baz");
+    }
+
+    private void test(String requestPath, String logicalPageName, String nestedComponentId,
+            String eventType, String... context) throws IOException
+    {
+        ActionLinkHandler handler = newActionLinkHandler();
+        Request request = newRequest();
+        Response response = newResponse();
+        ActionResponseGenerator generator = newMock(ActionResponseGenerator.class);
+
+        train_getPath(request, requestPath);
+
+        expect(
+                handler.handle(eq(logicalPageName), eq(nestedComponentId), eq(eventType),
EasyMock
+                        .aryEq(context))).andReturn(generator);
+
+        generator.sendClientResponse(response);
+
+        replay();
+
+        Dispatcher dispatcher = new ComponentEventDispatcher(handler);
+
+        assertTrue(dispatcher.dispatch(request, response));
+
+        verify();
+    }
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LinkFactoryImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LinkFactoryImplTest.java?view=diff&rev=500347&r1=500346&r2=500347
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LinkFactoryImplTest.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LinkFactoryImplTest.java
Fri Jan 26 13:09:43 2007
@@ -41,18 +41,25 @@
     @Test
     public void action_link_root_context_no_ids()
     {
-        run(PAGE_CLASS_NAME, PAGE_LOGICAL_NAME, "foo.bar", "", "/sub/MyPage.someaction/foo.bar");
+        testActionLink(
+                PAGE_CLASS_NAME,
+                "",
+                PAGE_LOGICAL_NAME,
+                "foo.bar",
+                "someaction",
+                "/sub/MyPage.foo.bar.someaction");
     }
 
     @Test
     public void action_link_root_context_with_ids()
     {
-        run(
+        testActionLink(
                 PAGE_CLASS_NAME,
+                "",
                 PAGE_LOGICAL_NAME,
                 "foo.bar",
-                "",
-                "/sub/MyPage.someaction/foo.bar/fred/5",
+                "publish",
+                "/sub/MyPage.foo.bar.publish/fred/5",
                 "fred",
                 5);
     }
@@ -60,12 +67,13 @@
     @Test
     public void action_link_named_context_no_ids()
     {
-        run(
+        testActionLink(
                 PAGE_CLASS_NAME,
+                "/fred",
                 PAGE_LOGICAL_NAME,
                 "foo.bar",
-                "/fred",
-                "/fred/sub/MyPage.someaction/foo.bar");
+                "someaction",
+                "/fred/sub/MyPage.foo.bar.someaction");
     }
 
     @SuppressWarnings("unchecked")
@@ -236,8 +244,8 @@
     }
 
     @SuppressWarnings("unchecked")
-    private void run(String pageClassName, String logicalPageName, String nestedId,
-            String contextPath, String expectedURI, Object... context)
+    private void testActionLink(String pageClassName, String contextPath, String logicalPageName,
+            String nestedId, String eventName, String expectedURI, Object... context)
     {
         Request request = newRequest();
         Response response = newResponse();
@@ -281,7 +289,7 @@
         LinkFactory factory = new LinkFactoryImpl(request, response, resolver, map, null);
         factory.addListener(listener);
 
-        Link link = factory.createActionLink(element, "someaction", false, context);
+        Link link = factory.createActionLink(element, eventName, false, context);
 
         assertEquals(link.toURI(), ENCODED);
         assertSame(link, holder.get());



Mime
View raw message