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 2010/05/12 00:50:30 UTC
svn commit: r943319 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/internal/services/
main/java/org/apache/tapestry5/services/
main/java/org/apache/tapestry5/services/messages/ test/app1/
test/app1/WEB-INF/ test/java/o...
Author: hlship
Date: Tue May 11 22:50:29 2010
New Revision: 943319
URL: http://svn.apache.org/viewvc?rev=943319&view=rev
Log:
TAP5-424: Allow the application message catalog to be composed from multiple resource files
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/LibraryMessagesDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/pre-app.properties (with props)
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/LibraryMessagesDemo.java (with props)
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.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/messages/ComponentMessagesSource.java
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/app.properties
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java?rev=943319&r1=943318&r2=943319&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImpl.java Tue May 11 22:50:29 2010
@@ -14,6 +14,9 @@
package org.apache.tapestry5.internal.services;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import java.util.Locale;
import org.apache.tapestry5.SymbolConstants;
@@ -21,6 +24,8 @@ import org.apache.tapestry5.internal.uti
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.annotations.Symbol;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.Operation;
import org.apache.tapestry5.ioc.services.ClasspathURLConverter;
import org.apache.tapestry5.model.ComponentModel;
import org.apache.tapestry5.services.InvalidationEventHub;
@@ -32,8 +37,6 @@ public class ComponentMessagesSourceImpl
{
private final MessagesSource messagesSource;
- private final Resource appCatalogResource;
-
private final MessagesBundle appCatalogBundle;
private class ComponentModelBundle implements MessagesBundle
@@ -66,23 +69,23 @@ public class ComponentMessagesSourceImpl
}
}
- public ComponentMessagesSourceImpl(@Symbol(SymbolConstants.APPLICATION_CATALOG)
- Resource appCatalogResource,
-
- PropertiesFileParser parser,
-
- ClasspathURLConverter classpathURLConverter)
+ public ComponentMessagesSourceImpl(List<Resource> appCatalogResources, PropertiesFileParser parser,
+ ClasspathURLConverter classpathURLConverter)
{
- this(appCatalogResource, parser, new URLChangeTracker(classpathURLConverter));
+ this(appCatalogResources, parser, new URLChangeTracker(classpathURLConverter));
}
ComponentMessagesSourceImpl(Resource appCatalogResource, PropertiesFileParser parser, URLChangeTracker tracker)
{
- this.appCatalogResource = appCatalogResource;
+ this(Arrays.asList(appCatalogResource), parser, tracker);
+ }
+ ComponentMessagesSourceImpl(List<Resource> appCatalogResources, PropertiesFileParser parser,
+ URLChangeTracker tracker)
+ {
messagesSource = new MessagesSourceImpl(tracker, parser);
- appCatalogBundle = createAppCatalogBundle();
+ appCatalogBundle = createAppCatalogBundle(appCatalogResources);
}
public void checkForUpdates()
@@ -102,23 +105,35 @@ public class ComponentMessagesSourceImpl
return messagesSource.getMessages(appCatalogBundle, locale);
}
- private MessagesBundle createAppCatalogBundle()
+ private MessagesBundle createAppCatalogBundle(List<Resource> resources)
+ {
+ MessagesBundle current = null;
+
+ for (Resource r : resources)
+ {
+ current = createMessagesBundle(r, current);
+ }
+
+ return current;
+ }
+
+ private MessagesBundle createMessagesBundle(final Resource resource, final MessagesBundle parent)
{
return new MessagesBundle()
{
public Resource getBaseResource()
{
- return appCatalogResource;
+ return resource;
}
public Object getId()
{
- return appCatalogResource.getPath();
+ return resource.getPath();
}
public MessagesBundle getParent()
{
- return null;
+ return parent;
}
};
}
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=943319&r1=943318&r2=943319&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 Tue May 11 22:50:29 2010
@@ -2881,4 +2881,15 @@ public final class TapestryModule
return service;
}
+ /**
+ * Contributes "AppCatalog" as the Resource defined by {@link SymbolConstants#APPLICATION_CATALOG}.
+ *
+ * @since 5.2.0
+ */
+ public static void contributeComponentMessagesSource(@Symbol(SymbolConstants.APPLICATION_CATALOG)
+ Resource applicationCatalog, OrderedConfiguration<Resource> configuration)
+ {
+ configuration.add("AppCatalog", applicationCatalog);
+ }
+
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/messages/ComponentMessagesSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/messages/ComponentMessagesSource.java?rev=943319&r1=943318&r2=943319&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/messages/ComponentMessagesSource.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/messages/ComponentMessagesSource.java Tue May 11 22:50:29 2010
@@ -17,13 +17,19 @@ package org.apache.tapestry5.services.me
import java.util.Locale;
import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.annotations.NotLazy;
+import org.apache.tapestry5.ioc.annotations.UsesOrderedConfiguration;
import org.apache.tapestry5.model.ComponentModel;
import org.apache.tapestry5.services.InvalidationEventHub;
/**
- * Used to connect a Tapestry component to its message catalog.
+ * Used to connect a Tapestry component to its message catalog, or to obtain the application catalog (that all
+ * component message catalogs extend from). The application catalog is defined by the collection of {@link Resource}s
+ * contributed to the service. In general, component libraries will contribute a Resource before the "AppCatalog" resource (representing
+ * the application message catalog, WEB-INF/app.properties) so that the application can override messages of the component library.
*/
+@UsesOrderedConfiguration(Resource.class)
public interface ComponentMessagesSource
{
/**
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/LibraryMessagesDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/LibraryMessagesDemo.tml?rev=943319&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/LibraryMessagesDemo.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/LibraryMessagesDemo.tml Tue May 11 22:50:29 2010
@@ -0,0 +1,13 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+ <h1>Library Messages Demo</h1>
+
+ <dl>
+ <dt>Library Message</dt>
+ <dd id="no-override">${message:pre-app}</dd>
+ <dt>Overriden Message</dt>
+ <dd id="override">${message:overridden-by-app}</dd>
+ </dl>
+
+</html>
+
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/app.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/app.properties?rev=943319&r1=943318&r2=943319&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/app.properties (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/app.properties Tue May 11 22:50:29 2010
@@ -15,3 +15,4 @@
app-catalog-status=Application Catalog Working
viewlink-label=View
+overridden-by-app=[app]
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/pre-app.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/pre-app.properties?rev=943319&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/pre-app.properties (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/pre-app.properties Tue May 11 22:50:29 2010
@@ -0,0 +1,2 @@
+overridden-by-app=[pre-app]
+pre-app=[pre-app]
\ No newline at end of file
Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/WEB-INF/pre-app.properties
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java?rev=943319&r1=943318&r2=943319&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java Tue May 11 22:50:29 2010
@@ -1436,7 +1436,7 @@ public class CoreBehaviorsTests extends
assertText("status", "Application Catalog Working");
}
-
+
/** TAP5-1121 */
@Test
public void discard_after()
@@ -1444,38 +1444,48 @@ public class CoreBehaviorsTests extends
clickThru("@DiscardAfter Demo");
type("stringValue", "foo bar baz");
-
+
clickAndWait("//input[@id='keep']");
-
+
assertTextPresent("Value is: 'foo bar baz'");
-
+
clickAndWait("//input[@id='discard']");
-
+
assertTextPresent("Value is: ''");
-
- //Once again
-
+
+ // Once again
+
type("stringValue", "barney quux");
-
+
clickAndWait("//input[@id='keep']");
-
+
assertTextPresent("Value is: 'barney quux'");
-
+
clickAndWait("//input[@id='discardWithCheckedException']");
-
+
assertTextPresent("Oops! Error occured");
-
+
clickThru("@DiscardAfter Demo");
-
+
assertTextPresent("Value is: 'barney quux'");
}
-
+
/** TAP5-1080 */
@Test
public void context_lost_on_secure_page_redirect()
{
open("/securepage/mycontext");
-
+
assertText("context", "mycontext");
}
+
+ /** TAP5-424 */
+ @Test
+ public void multiple_resources_contributed_to_global_message_catalog()
+ {
+ clickThru("Library Messages Demo");
+
+ assertText("id=no-override", "[pre-app]");
+ assertText("id=override", "[app]");
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java?rev=943319&r1=943318&r2=943319&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java Tue May 11 22:50:29 2010
@@ -67,6 +67,9 @@ public class Index
private static final List<Item> ITEMS = CollectionFactory
.newList(
+ new Item("LibraryMessagesDemo", "Library Messages Demo",
+ "Demo ability to contribute additional message catalog resources to the application global catalog."),
+
new Item("MultiZoneUpdateInsideForm", "MultiZone Update inside a Form",
"Update multiple zones within a single Form."),
@@ -432,8 +435,7 @@ public class Index
new Item("unavailablecomponentdemo", "Report Location of Unavailable Component",
"Report Location of Unavailable Component"),
- new Item("discardafterdemo", "@DiscardAfter Demo",
- "Demo using @DiscardAfter annotation")
+ new Item("discardafterdemo", "@DiscardAfter Demo", "Demo using @DiscardAfter annotation")
);
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/LibraryMessagesDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/LibraryMessagesDemo.java?rev=943319&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/LibraryMessagesDemo.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/LibraryMessagesDemo.java Tue May 11 22:50:29 2010
@@ -0,0 +1,20 @@
+// Copyright 2010 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.tapestry5.integration.app1.pages;
+
+public class LibraryMessagesDemo
+{
+
+}
Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/LibraryMessagesDemo.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java?rev=943319&r1=943318&r2=943319&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/services/AppModule.java Tue May 11 22:50:29 2010
@@ -34,9 +34,11 @@ import org.apache.tapestry5.internal.ser
import org.apache.tapestry5.ioc.Configuration;
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.OrderedConfiguration;
+import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.ServiceBinder;
import org.apache.tapestry5.ioc.annotations.Marker;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.services.TypeCoercer;
import org.apache.tapestry5.services.AliasContribution;
import org.apache.tapestry5.services.BaseURLSource;
import org.apache.tapestry5.services.ComponentClassTransformWorker;
@@ -271,4 +273,11 @@ public class AppModule
{
configuration.add("ReverseStringsWorker", new ReverseStringsWorker());
}
+
+ public static void contributeComponentMessagesSource(TypeCoercer coercer,
+ OrderedConfiguration<Resource> configuration)
+ {
+ configuration.add("PreApp", coercer.coerce("context:WEB-INF/pre-app.properties", Resource.class),
+ "before:AppCatalog");
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java?rev=943319&r1=943318&r2=943319&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentMessagesSourceImplTest.java Tue May 11 22:50:29 2010
@@ -14,6 +14,8 @@
package org.apache.tapestry5.internal.services;
+import java.util.Arrays;
+import java.util.List;
import java.util.Locale;
import org.apache.tapestry5.internal.services.messages.PropertiesFileParserImpl;
@@ -206,8 +208,11 @@ public class ComponentMessagesSourceImpl
forceCacheClear();
- ComponentMessagesSource source = new ComponentMessagesSourceImpl(simpleComponentResource
- .forFile("NoSuchAppCatalog.properties"), new PropertiesFileParserImpl(), converter);
+ Resource resource = simpleComponentResource.forFile("NoSuchAppCatalog.properties");
+ List<Resource> resources = Arrays.asList(resource);
+
+ ComponentMessagesSource source = new ComponentMessagesSourceImpl(resources, new PropertiesFileParserImpl(),
+ converter);
Messages messages = source.getMessages(model, Locale.ENGLISH);