tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r501121 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/ main/java/org/apache/tapestry/internal/services/ main/java/org/apache/tapestry/internal/structure/ main/java/org/apache/tapestry/runtime/ main/resource...
Date Mon, 29 Jan 2007 17:32:49 GMT
Author: hlship
Date: Mon Jan 29 09:32:47 2007
New Revision: 501121

URL: http://svn.apache.org/viewvc?view=rev&rev=501121
Log:
Use case-insensitivity with blocks (within component templates).
Add case-insensitive matching for component events (caseless matching against the event type
and the component id).

Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResourcesCommon.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/OnEventWorker.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/StructureMessages.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/ComponentEvent.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/structure/StructureStrings.properties
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentEventImplTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/OnEventWorkerTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResourcesCommon.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResourcesCommon.java?view=diff&rev=501121&r1=501120&r2=501121
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResourcesCommon.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/ComponentResourcesCommon.java
Mon Jan 29 09:32:47 2007
@@ -17,6 +17,8 @@
 import java.util.Locale;
 
 import org.apache.commons.logging.Log;
+import org.apache.tapestry.annotations.OnEvent;
+import org.apache.tapestry.internal.services.OnEventWorker;
 import org.apache.tapestry.internal.structure.ComponentPageElement;
 import org.apache.tapestry.model.ComponentModel;
 import org.apache.tapestry.services.ComponentSource;
@@ -76,6 +78,8 @@
      * component, then its container, and so on. When a matching event handler method is
located, it
      * is invoked. If the method returns a value, the value is passed to the handler (if
handler is
      * null, then it is an error for a method to return a non-null vavlue).
+     * <p>
+     * Resolution of event type to event handler methods is case insensitive.
      * 
      * @param eventType
      *            event type (as determined from the request, or otherwise by design)
@@ -88,6 +92,8 @@
      *            that does not support return values from event handler methods
      * @return true if any event handler was invoked (even if no event handler method returns
a
      *         non-null value)
+     * @see OnEventWorker
+     * @see OnEvent
      */
     boolean triggerEvent(String eventType, Object[] context, ComponentEventHandler handler);
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java?view=diff&rev=501121&r1=501120&r2=501121
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/ComponentEventImpl.java
Mon Jan 29 09:32:47 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 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.
@@ -67,7 +67,7 @@
     {
         for (String id : componentId)
         {
-            if (id.equals(_originatingComponentId))
+            if (id.equalsIgnoreCase(_originatingComponentId))
                 return true;
         }
 
@@ -78,7 +78,7 @@
     {
         for (String type : eventTypes)
         {
-            if (type.equals(_eventType))
+            if (type.equalsIgnoreCase(_eventType))
                 return true;
         }
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/OnEventWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/OnEventWorker.java?view=diff&rev=501121&r1=501120&r2=501121
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/OnEventWorker.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/OnEventWorker.java
Mon Jan 29 09:32:47 2007
@@ -17,7 +17,6 @@
 import java.util.List;
 
 import org.apache.tapestry.annotations.OnEvent;
-import org.apache.tapestry.internal.TapestryUtils;
 import org.apache.tapestry.ioc.util.BodyBuilder;
 import org.apache.tapestry.model.MutableComponentModel;
 import org.apache.tapestry.runtime.Component;
@@ -157,7 +156,7 @@
         String componentId = name.substring(fromx + 4);
 
         return new String[]
-        { TapestryUtils.decapitalize(componentId) };
+        { componentId };
     }
 
     private String[] extractEventTypes(MethodSignature method, OnEvent annotation)
@@ -179,7 +178,7 @@
             return _empty;
 
         return new String[]
-        { TapestryUtils.decapitalize(eventName) };
+        { eventName };
     }
 
     private void buildMethodParameters(BodyBuilder builder, MethodSignature method)

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java?view=diff&rev=501121&r1=501120&r2=501121
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/ComponentPageElementImpl.java
Mon Jan 29 09:32:47 2007
@@ -16,6 +16,7 @@
 
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newList;
 import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
+import static org.apache.tapestry.ioc.internal.util.Defense.notBlank;
 
 import java.util.Iterator;
 import java.util.List;
@@ -1048,7 +1049,9 @@
 
     public Block getBlock(String id)
     {
-        Block result = InternalUtils.get(_blocks, id);
+        notBlank(id, "id");
+
+        Block result = InternalUtils.get(_blocks, id.toLowerCase());
 
         if (result == null)
             throw new BlockNotFoundException(StructureMessages.blockNotFound(_completeId,
id),
@@ -1062,9 +1065,13 @@
         if (_blocks == null)
             _blocks = newMap();
 
-        // TODO: Check for duplicates.
+        String caselessId = blockId.toLowerCase();
+
+        if (_blocks.containsKey(caselessId))
+            throw new TapestryException(StructureMessages.duplicateBlock(this, blockId),
block,
+                    null);
 
-        _blocks.put(blockId, block);
+        _blocks.put(caselessId, block);
     }
 
     public String getDefaultBindingPrefix(String parameterName)

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/StructureMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/StructureMessages.java?view=diff&rev=501121&r1=501120&r2=501121
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/StructureMessages.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/StructureMessages.java
Mon Jan 29 09:32:47 2007
@@ -90,4 +90,9 @@
     {
         return MESSAGES.format("duplicate-child-component", container.getCompleteId(), childId);
     }
+
+    static String duplicateBlock(ComponentPageElement component, String blockId)
+    {
+        return MESSAGES.format("duplicate-block", component.getCompleteId(), blockId);
+    }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/ComponentEvent.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/ComponentEvent.java?view=diff&rev=501121&r1=501120&r2=501121
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/ComponentEvent.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/runtime/ComponentEvent.java
Mon Jan 29 09:32:47 2007
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 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.
@@ -29,17 +29,18 @@
 public interface ComponentEvent extends Event
 {
     /**
-     * Returns true if the component event's type matches
+     * Returns true if the component event's type matches any of the provided values. Comparison
is
+     * caseless.
      * 
      * @param eventTypes
-     * @return
+     * @return true if there is any match
      */
     boolean matchesByEventType(String[] eventTypes);
 
     /**
      * Returns true if the originating component matches any of the components identified
by their
      * ids. This filter is only relevent in the immediate container of the originating component
(it
-     * will never match at higher levels).
+     * will never match at higher levels). Comparison is caseless.
      */
     boolean matchesByComponentId(ComponentResources resources, String[] componentId);
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/structure/StructureStrings.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/structure/StructureStrings.properties?view=diff&rev=501121&r1=501120&r2=501121
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/structure/StructureStrings.properties
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/structure/StructureStrings.properties
Mon Jan 29 09:32:47 2007
@@ -30,4 +30,6 @@
 page-is-dirty=Page %s was stored into the page pool in a dirty state. This should never happen,
\
   and may indicate that a reference to the page (or component within the page) was retained
past the end of a request.
 duplicate-child-component=Component %s already contains a child component with id '%s'. \
-  Embedded component ids must be unique (excluding case, which is ignored).
\ No newline at end of file
+  Embedded component ids must be unique (excluding case, which is ignored).
+duplicate-block=Component %s already contains a block with id '%s'. \
+  Block ids must be unique (excluding case, which is ignored).

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentEventImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentEventImplTest.java?view=diff&rev=501121&r1=501120&r2=501121
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentEventImplTest.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/ComponentEventImplTest.java
Mon Jan 29 09:32:47 2007
@@ -58,6 +58,22 @@
     }
 
     @Test
+    public void event_type_match_is_case_insensitive()
+    {
+        ComponentEventHandler handler = newComponentEventHandler();
+
+        replay();
+
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
+                _coercer);
+
+        assertTrue(event.matchesByEventType(new String[]
+        { "EVENTTYPE" }));
+
+        verify();
+    }
+
+    @Test
     public void matches_on_component_id()
     {
         ComponentEventHandler handler = newComponentEventHandler();
@@ -70,6 +86,21 @@
         { "foo", "someId", "bar" }));
         assertFalse(event.matchesByComponentId(null, new String[]
         { "foo", "bar" }));
+
+        verify();
+    }
+
+    @Test
+    public void component_id_matches_are_case_insensitive()
+    {
+        ComponentEventHandler handler = newComponentEventHandler();
+
+        replay();
+        ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler,
+                _coercer);
+
+        assertTrue(event.matchesByComponentId(null, new String[]
+        { "SOMEID" }));
 
         verify();
     }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/OnEventWorkerTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/OnEventWorkerTest.java?view=diff&rev=501121&r1=501120&r2=501121
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/OnEventWorkerTest.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/OnEventWorkerTest.java
Mon Jan 29 09:32:47 2007
@@ -154,7 +154,7 @@
 
         train_getMethodAnnotation(ct, signature, OnEvent.class, null);
 
-        train_addInjectedField(ct, "eventTypes", "_v", "submit");
+        train_addInjectedField(ct, "eventTypes", "_v", "Submit");
 
         train_getClassName(ct, "foo.Bar");
 
@@ -235,7 +235,7 @@
 
         train_getMethodAnnotation(ct, signature, OnEvent.class, null);
 
-        train_addInjectedField(ct, "componentIds", "_ids", "zork");
+        train_addInjectedField(ct, "componentIds", "_ids", "Zork");
 
         train_getResourcesFieldName(ct, "_res");
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java?view=diff&rev=501121&r1=501120&r2=501121
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/structure/ComponentPageElementImplTest.java
Mon Jan 29 09:32:47 2007
@@ -93,6 +93,8 @@
         cpe.addBlock("known", block);
 
         assertSame(resources.getBlock("known"), block);
+        // Caseless check
+        assertSame(resources.getBlock("KNOWN"), block);
 
         verify();
     }
@@ -123,6 +125,39 @@
 
         assertFalse(resources.isBound("fred"));
         assertTrue(resources.isBound("barney"));
+
+        verify();
+    }
+
+    @Test
+    public void duplicate_block_id()
+    {
+        Page page = newPage(PAGE_NAME);
+        Component component = newComponent();
+        ComponentModel model = newComponentModel();
+        TypeCoercer coercer = newTypeCoercer();
+        Block block1 = newBlock();
+        Block block2 = newBlock();
+
+        Instantiator ins = newInstantiator(component, model);
+
+        replay();
+
+        ComponentPageElement cpe = new ComponentPageElementImpl(page, ins, coercer, null);
+
+        cpe.addBlock("myblock", block1);
+
+        try
+        {
+            cpe.addBlock("MyBlock", block2);
+            unreachable();
+        }
+        catch (TapestryException ex)
+        {
+            assertEquals(
+                    ex.getMessage(),
+                    "Component org.test.pages.Foo already contains a block with id \'MyBlock\'.
Block ids must be unique (excluding case, which is ignored).");
+        }
 
         verify();
     }



Mime
View raw message