Author: hlship
Date: Thu Nov  6 13:01:14 2008
New Revision: 711974

URL: http://svn.apache.org/viewvc?rev=711974&view=rev
Log:
TAP5-253: Unable to effectively override default validation messages globally

Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ValidationMessagesSource.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImplTest.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/ValidationTestMessages.properties

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java?rev=711974&r1=711973&r2=711974&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImpl.java
 Thu Nov  6 13:01:14 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 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.
@@ -22,7 +22,7 @@
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.services.ValidationMessagesSource;
 
-import java.util.Collection;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
@@ -40,7 +40,7 @@
 
         private final MessagesBundle parent;
 
-        public ValidationMessagesBundle(final Resource baseResource, final 
MessagesBundle parent)
+        public ValidationMessagesBundle(Resource baseResource, MessagesBundle 
parent)
         {
             this.baseResource = baseResource;
             this.parent = parent;
@@ -60,7 +60,6 @@
         {
             return parent;
         }
-
     }
 
     /**
@@ -71,7 +70,7 @@
     {
         private final Locale locale;
 
-        public ValidationMessages(final Locale locale)
+        public ValidationMessages(Locale locale)
         {
             this.locale = locale;
         }
@@ -108,12 +107,12 @@
         }
     }
 
-    public ValidationMessagesSourceImpl(Collection<String> bundles, Resource 
classpathRoot)
+    public ValidationMessagesSourceImpl(List<String> bundles, Resource 
classpathRoot)
     {
         this(bundles, classpathRoot, new URLChangeTracker());
     }
 
-    ValidationMessagesSourceImpl(Collection<String> bundles, Resource 
classpathRoot, URLChangeTracker tracker)
+    ValidationMessagesSourceImpl(List<String> bundles, Resource classpathRoot, 
URLChangeTracker tracker)
     {
         messagesSource = new MessagesSourceImpl(tracker);
 
@@ -145,9 +144,8 @@
     public void checkForUpdates()
     {
         // When there are changes, the Messages cached inside the 
MessagesSource will be discarded
-        // and will be rebuilt on demand by the ValidatonMessages instances.
+        // and will be rebuilt on demand by the ValidationMessages instances.
 
         messagesSource.checkForUpdates();
     }
-
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=711974&r1=711973&r2=711974&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
 Thu Nov  6 13:01:14 2008
@@ -876,7 +876,7 @@
      * Builds the source of [EMAIL PROTECTED] Messages} containing validation 
messages. The contributions are paths to message
      * bundles (resource paths within the classpath); the default contribution 
is "org/apache/tapestry5/internal/ValidationMessages".
      */
-    public ValidationMessagesSource 
buildValidationMessagesSource(Collection<String> configuration,
+    public ValidationMessagesSource buildValidationMessagesSource(List<String> 
configuration,
 
                                                                   
UpdateListenerHub updateListenerHub,
 
@@ -1726,9 +1726,12 @@
         configuration.add("client", clientStrategy);
     }
 
-    public void contributeValidationMessagesSource(Configuration<String> 
configuration)
+    /**
+     * Contributes org/apache/tapestry5/internal/ValidationMessages as 
"Default", ordered first.
+     */
+    public void 
contributeValidationMessagesSource(OrderedConfiguration<String> configuration)
     {
-        configuration.add("org/apache/tapestry5/internal/ValidationMessages");
+        configuration.add("Default", 
"org/apache/tapestry5/internal/ValidationMessages", "before:*");
     }
 
     public ValueEncoderSource buildValueEncoderSource(Map<Class, 
ValueEncoderFactory> configuration)

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ValidationMessagesSource.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ValidationMessagesSource.java?rev=711974&r1=711973&r2=711974&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ValidationMessagesSource.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/ValidationMessagesSource.java
 Thu Nov  6 13:01:14 2008
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2008 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.
@@ -15,12 +15,16 @@
 package org.apache.tapestry5.services;
 
 import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.annotations.UsesOrderedConfiguration;
 
 import java.util.Locale;
 
 /**
  * Source for validation messages, within a particular locale.
+ * <p/>
+ * The service's configuration are paths, within the classpath, to bundles to 
load as part of the validation messages.
  */
[EMAIL PROTECTED](String.class)
 public interface ValidationMessagesSource
 {
     Messages getValidationMessages(Locale locale);

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImplTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImplTest.java?rev=711974&r1=711973&r2=711974&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImplTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ValidationMessagesSourceImplTest.java
 Thu Nov  6 13:01:14 2008
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2008 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.
@@ -49,6 +49,23 @@
                 "You must provide a value for My Field.");
     }
 
+
+    @Test
+    public void overriden_message()
+    {
+        Messages messages = source.getValidationMessages(Locale.ENGLISH);
+
+        assertEquals(messages.get("number-format-exception"), "Number Format 
Exception");
+    }
+
+    @Test
+    public void nonlocalized_override()
+    {
+        Messages messages = source.getValidationMessages(Locale.FRANCE);
+
+        assertEquals(messages.get("number-format-exception"), "Number Format 
Exception");
+    }
+
     @Test
     public void contributed_message()
     {

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/ValidationTestMessages.properties
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/ValidationTestMessages.properties?rev=711974&r1=711973&r2=711974&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/ValidationTestMessages.properties
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/ValidationTestMessages.properties
 Thu Nov  6 13:01:14 2008
@@ -1,4 +1,4 @@
-# Copyright 2006 The Apache Software Foundation
+# Copyright 2006, 2008 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.
@@ -13,3 +13,4 @@
 # limitations under the License.
 
 contributed=This message was contributed inside ValidationTestMessages.
+number-format-exception=Number Format Exception
\ No newline at end of file


Reply via email to