[prev in list] [next in list] [prev in thread] [next in thread]
List: tapestry-dev
Subject: svn commit: r480804 - in /tapestry/tapestry5/tapestry-core/trunk/src:
From: hlship () apache ! org
Date: 2006-11-30 2:00:44
Message-ID: 20061130020045.5C45E1A984A () eris ! apache ! org
[Download RAW message or body]
Author: hlship
Date: Wed Nov 29 18:00:43 2006
New Revision: 480804
URL: http://svn.apache.org/viewvc?view=rev&rev=480804
Log:
Properly use the thread's locale when loading pages and component templates.
Document the current state of localization.
Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/MessageBindingFactory.java
tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/localization.apt
Modified:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PagePoolImpl.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/parameters.apt
tapestry/tapestry5/tapestry-core/trunk/src/site/site.xml
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/Localization.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PagePoolImplTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Localization.html
tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Localization.properties
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/MessageBindingFactory.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java \
/org/apache/tapestry/internal/bindings/MessageBindingFactory.java?view=auto&rev=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/MessageBindingFactory.java \
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/bindings/MessageBindingFactory.java \
Wed Nov 29 18:00:43 2006 @@ -0,0 +1,37 @@
+// Copyright 2006 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.bindings;
+
+import org.apache.tapestry.ComponentResources;
+import org.apache.tapestry.ioc.Location;
+import org.apache.tapestry.services.Binding;
+import org.apache.tapestry.services.BindingFactory;
+
+/**
+ * Implementation of the message: binding prefix -- we simply get the message key \
and store it + * inside at {@link LiteralBinding}.
+ */
+public class MessageBindingFactory implements BindingFactory
+{
+
+ public Binding newBinding(String description, ComponentResources component, \
String expression, + Location location)
+ {
+ String messageValue = component.getMessages().get(expression);
+
+ return new LiteralBinding(description, messageValue, location);
+ }
+
+}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java \
/org/apache/tapestry/internal/services/InternalModule.java?view=diff&rev=480804&r1=480803&r2=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java \
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/InternalModule.java \
Wed Nov 29 18:00:43 2006 @@ -84,6 +84,8 @@
private final WebResponse _response;
+ private final ThreadLocale _threadLocale;
+
public InternalModule(@InjectService("ComponentInstantiatorSource")
ComponentInstantiatorSource componentInstantiatorSource, \
@InjectService("UpdateListenerHub")
UpdateListenerHub updateListenerHub, \
@InjectService("tapestry.ioc.ThreadCleanupHub") @@ -94,7 +96,8 @@
@InjectService("tapestry.ioc.ChainBuilder")
ChainBuilder chainBuilder, @Inject("infrastructure:request")
WebRequest request, @Inject("infrastructure:response")
- WebResponse response)
+ WebResponse response, @InjectService("tapestry.ioc.ThreadLocale")
+ ThreadLocale threadLocale)
{
_componentInstantiatorSource = componentInstantiatorSource;
_updateListenerHub = updateListenerHub;
@@ -104,6 +107,7 @@
_chainBuilder = chainBuilder;
_request = request;
_response = response;
+ _threadLocale = threadLocale;
}
public ComponentClassTransformer buildComponentClassTransformer(
@@ -179,7 +183,7 @@
PageLoader pageLoader, @Inject("infrastructure:componentMessagesSource")
ComponentMessagesSource componentMessagesSource)
{
- PagePoolImpl service = new PagePoolImpl(log, pageLoader);
+ PagePoolImpl service = new PagePoolImpl(log, pageLoader, _threadLocale);
// This covers invalidations due to changes to classes
@@ -248,15 +252,14 @@
@Contribute("tapestry.WebRequestHandler")
public void contributeWebRequestFilters(OrderedConfiguration<WebRequestFilter> \
configuration, @InjectService("tapestry.RequestGlobals")
- final RequestGlobals requestGlobals, \
@InjectService("tapestry.ioc.ThreadLocale")
- ThreadLocale threadLocale, @Inject("${tapestry.file-check-interval}")
+ final RequestGlobals requestGlobals, \
@Inject("${tapestry.file-check-interval}") long checkInterval, \
@Inject("${tapestry.supported-locales}") String localeNames)
{
configuration.add("CheckForUpdates", new \
CheckForUpdatesFilter(_updateListenerHub, checkInterval), "before:*.*");
- configuration.add("Localization", new LocalizationFilter(threadLocale, \
localeNames)); + configuration.add("Localization", new \
LocalizationFilter(_threadLocale, localeNames)); }
/**
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PagePoolImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java \
/org/apache/tapestry/internal/services/PagePoolImpl.java?view=diff&rev=480804&r1=480803&r2=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PagePoolImpl.java \
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/PagePoolImpl.java \
Wed Nov 29 18:00:43 2006 @@ -12,74 +12,84 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry.internal.services;
-
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.tapestry.events.InvalidationListener;
-import org.apache.tapestry.internal.structure.Page;
+package org.apache.tapestry.internal.services;
+
+import static org.apache.tapestry.ioc.internal.util.CollectionFactory.newMap;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.tapestry.events.InvalidationListener;
+import org.apache.tapestry.internal.structure.Page;
import org.apache.tapestry.ioc.internal.util.CollectionFactory;
-
-/**
- * A very naive implementation just to get us past the start line.
- * <p>
- * Registered as an invalidation listener with the
- * {@link org.apache.tapestry.internal.services.PageLoader}; thus the pool is \
cleared whenever
- */
-public class PagePoolImpl implements PagePool, InvalidationListener
-{
- private final Log _log;
-
- private final PageLoader _pageLoader;
-
- private final Map<String, List<Page>> _pool = CollectionFactory.newMap();
-
- public PagePoolImpl(Log log, PageLoader pageLoader)
- {
- _log = log;
- _pageLoader = pageLoader;
- }
-
- public synchronized Page checkout(String pageName)
- {
- List<Page> pages = _pool.get(pageName);
-
- if (pages == null || pages.isEmpty())
- return _pageLoader.loadPage(pageName, Locale.getDefault());
-
- // Remove and return the last page in the pool.
-
- return pages.remove(pages.size() - 1);
- }
-
- public synchronized void release(Page page)
- {
- boolean dirty = page.detached();
-
- if (dirty)
- {
- _log.error(ServicesMessages.pageIsDirty(page));
- return;
- }
-
- String key = page.getName();
- List<Page> pages = _pool.get(key);
-
- if (pages == null)
- {
- pages = CollectionFactory.newList();
- _pool.put(key, pages);
- }
-
- pages.add(page);
- }
-
- public synchronized void objectWasInvalidated()
- {
- _pool.clear();
- }
-
-}
+import org.apache.tapestry.ioc.services.ThreadLocale;
+
+/**
+ * A very naive implementation just to get us past the start line.
+ * <p>
+ * Registered as an invalidation listener with the
+ * {@link org.apache.tapestry.internal.services.PageLoader}; thus the pool is \
cleared whenever + */
+public class PagePoolImpl implements PagePool, InvalidationListener
+{
+ private final Log _log;
+
+ private final PageLoader _pageLoader;
+
+ private final ThreadLocale _threadLocale;
+
+ private final Map<String, List<Page>> _pool = newMap();
+
+ public PagePoolImpl(Log log, PageLoader pageLoader, ThreadLocale threadLocale)
+ {
+ _log = log;
+ _pageLoader = pageLoader;
+ _threadLocale = threadLocale;
+ }
+
+ public synchronized Page checkout(String pageName)
+ {
+ List<Page> pages = _pool.get(pageName);
+
+ // When we load a page, we load it in the active locale, whatever that is.
+ // Even if the locale later changes, we keep the version we originally got.
+ // This is not as bad in T5 as in T4, since a seperate request will
+ // render the response (and will have a chance to get the page in a \
different locale). +
+ if (pages == null || pages.isEmpty())
+ return _pageLoader.loadPage(pageName, _threadLocale.getLocale());
+
+ // Remove and return the last page in the pool.
+
+ return pages.remove(pages.size() - 1);
+ }
+
+ public synchronized void release(Page page)
+ {
+ boolean dirty = page.detached();
+
+ if (dirty)
+ {
+ _log.error(ServicesMessages.pageIsDirty(page));
+ return;
+ }
+
+ String key = page.getName();
+ List<Page> pages = _pool.get(key);
+
+ if (pages == null)
+ {
+ pages = CollectionFactory.newList();
+ _pool.put(key, pages);
+ }
+
+ pages.add(page);
+ }
+
+ public synchronized void objectWasInvalidated()
+ {
+ _pool.clear();
+ }
+
+}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java \
/org/apache/tapestry/services/TapestryModule.java?view=diff&rev=480804&r1=480803&r2=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java \
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/TapestryModule.java \
Wed Nov 29 18:00:43 2006 @@ -42,6 +42,7 @@
import org.apache.tapestry.internal.InternalConstants;
import org.apache.tapestry.internal.bindings.ComponentBindingFactory;
import org.apache.tapestry.internal.bindings.LiteralBindingFactory;
+import org.apache.tapestry.internal.bindings.MessageBindingFactory;
import org.apache.tapestry.internal.services.ApplicationGlobalsImpl;
import org.apache.tapestry.internal.services.BindingSourceImpl;
import org.apache.tapestry.internal.services.CommonResourcesInjectionProvider;
@@ -459,7 +460,10 @@
return new BindingSourceImpl(configuration);
}
- /** Contributes the factory for "literal:" bindings. */
+ /**
+ * Contributes the factory for serveral built-in binding prefixes ("literal", \
prop", "component" + * and "message").
+ */
public static void contributeBindingSource(
MappedConfiguration<String, BindingFactory> configuration,
@InjectService("tapestry.internal.PropBindingFactory")
@@ -468,6 +472,7 @@
configuration.add(InternalConstants.LITERAL_BINDING_PREFIX, new \
LiteralBindingFactory());
configuration.add(InternalConstants.PROP_BINDING_PREFIX, \
propBindingFactory); configuration.add("component", new ComponentBindingFactory());
+ configuration.add("message", new MessageBindingFactory());
}
/**
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java \
/org/apache/tapestry/test/TapestryTestCase.java?view=diff&rev=480804&r1=480803&r2=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java \
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/TapestryTestCase.java \
Wed Nov 29 18:00:43 2006 @@ -41,6 +41,7 @@
import org.apache.tapestry.ioc.Resource;
import org.apache.tapestry.ioc.ServiceLocator;
import org.apache.tapestry.ioc.internal.util.ClasspathResource;
+import org.apache.tapestry.ioc.services.ThreadLocale;
import org.apache.tapestry.ioc.test.IOCTestCase;
import org.apache.tapestry.model.ComponentModel;
import org.apache.tapestry.model.MutableComponentModel;
@@ -406,5 +407,10 @@
protected final void train_getBaseResource(ComponentModel model, Resource \
resource) {
expect(model.getBaseResource()).andReturn(resource).atLeastOnce();
+ }
+
+ protected final void train_getLocale(ThreadLocale threadLocale, Locale locale)
+ {
+ expect(threadLocale.getLocale()).andReturn(locale);
}
}
Added: tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/localization.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/localization.apt?view=auto&rev=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/localization.apt \
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/localization.apt Wed \
Nov 29 18:00:43 2006 @@ -0,0 +1,144 @@
+ ----
+ Localization
+ ----
+
+Localization
+
+ Localization is all about getting the right text to the user, in the right \
language. +
+ Localization support is well integrated into Tapestry. Tapestry allows you to \
easily seperate the text you present to your users + from the rest of your \
application ... pull it out of your Java code and even out of your component \
templates. You can then translate + your messages into other languages and let \
Tapestry put everthing together. +
+Component Message Catalogs
+
+ Each component class may have a component message catalog. A component message \
catalog is a set of files with the extension ".properties". + These property files \
are the same format used by java.util.ResourceBundle, just lines of <<<key=value>>>. \
These files are packaged with the component's HTML template. +
+ So for a class named org.example.myapp.pages.MyPage, you would have a main \
properties file as <<<org/example/myapp/pages/MyPage.properties>>>. +
+ If you have a translations of these values, you provide additional properties \
file, adding an + {{{http://www.loc.gov/standards/iso639-2/englangn.html}ISO \
language code}} before the extension. Thus, if you have a French translation, + you \
could create a file <<<MyPage_fr.properties>>>. +
+ Any values in the more language specific file will <override> values from the main \
properties file. If you had an even more specific + localization for just French as \
spoken in France, you could create <<<MyPage_fr_FR.properties>>> (thats a language \
code plus a country code, you can even go further + and add variants ... but its \
unlikely that you'll ever need to go beyond just language codes in practice). +
+Message Catalog Inheritance
+
+ If a component class is a subclass of another component class, then it inherits \
that base class' message catalog. Its own message catalog extends and overrides + \
the values inherited from the base class. +
+ In this way, you could have a base component class that contained common messages, \
and extend or override those messages in subclasses (just as you would + extend or \
override the methods of the base component class). This, of course, works for as many \
levels of inheritance as you care to support. +
+Application Message Catalog
+
+ Tapestry 4 supports an application-wide message catalog; this is <<not yet>> in \
Tapestry 5, but will likely be coming soon. +
+Localized Component Templates
+
+ The same lookup mechanism applies to component templates. Tapestry will search \
for a localized version of each component template and use the closest + match. \
Thus you could have <<<MyPage_fr.html>>> for French users, and <<<MyPage.html>>> for \
all other users. +
+Accessing Localized Messages
+
+ The above discusses what files to create and where to store them, but doesn't \
address how to make use of that information. +
+ Messages can be accessed in one of two ways:
+
+ * Using the {{{parameters.html}message: binding prefix}} in a component template
+
+ * By injecting the comopnent's Messages object
+
+ []
+
+ In the first case, you may use the message: binding prefix with component \
parameters, or with template expansions: +
++-----+
+<t:comp type="Border" title="message:page-title">
+
+ ${message:greeting}, ${user.name}!
+
+ . . .
+</t:comp>
++-----+
+
+ Here, the <<<page-title>>> message is extracted from the catalog and passed to the \
Border component's title parameter. +
+ In addition, the <<<greeting>>> message is extracted and written into the response \
as part of the template. +
+ As usual, "prop:" is the defalt binding prefix, thus <<<user.name>>> is a property \
path, not a message key. +
+ You would extend this with a set of properties files:
+
++----+
+page-title=Your Account
+greeting=Welcome back
++----+
+
+ Or, perhaps, a French version:
+
++----+
+page-title=Votre Compte
+greeting=Bienvenue en arriere
++----+
+
+ Programattically, you may inject your component message catalog into your class, \
as an instance of the Messages interface: +
++----+
+ @Inject
+ private Messages _messages;
++----+
+
+ You could then <<<get()>>> messages, or <<<format()>>> them:
+
++----+
+
+ public String getCartSummary()
+ {
+ if (_items.isEmpty())
+ return _messages.get("no-items");
+
+ return _messages.format("item-summary", _items.size());
+ }
++----+
+
+ The format() option works using a java.text.Formatter, with all the printf-style \
loveliness you've come to expect: +
++----+
+no-items=Your shopping cart is empty.
+item-summary=You have %d items in your cart.
++----+
+
+ As easy as conditionals are to do inside a Tapestry template, sometimes its even \
easier to do it in Java code. +
+Missing Keys
+
+ If you reference a key that is not in the message catalog, Tapestry does not throw \
an exception (that would make initially developing + an application very \
frustrating). Instead, it converts the key to upper case, surrounds it in brackets, \
and returns it. You'll sometimes + see output such as <<<[NO-ITMS]>>> in your \
output when a key (here, "no-itms") is misspelled. +
+Reloading
+
+ If you change a property file in a message catalog, you'll see the change \
immediately, just as with component classes and component templates. +
+Locale Selection
+
+ The locale for each request is determined from the HTTP request headers. The \
request locale reflects the environment of the web browser and possibly even + the \
keyboard selection of the user on the client. It can be highly specific, for \
example, identifying British English (as en_GB) vs. American English (en). +
+ Tapestry "narrows" the raw request locale, as specified in the request, to a known \
quantity. + It uses the {{{conf.html}configuration symbol}} \
tapestry.supported-locales to choose the effective locale for each request. This \
value is a comma-separated + list of locale names. Tapestry searches the list for \
the best + match for the request locale; for example, a request locale of "fr_FR" \
would match "fr" but not "de". If no match is found, then the first locale name + \
in the list is used as the effective locale (it is used as the default for \
non-matches). Thus a site that primarily caters to French speakers + would want to \
list "fr" as the first locale in the list. +
+Changing the Locale
+
+ Tapestry does not yet support changing the locale, but that will be available \
shortly. The intent is to mimic Tapestry 4 behavior: store a cookie + on the client \
to provide the default for the locale on the next visit, and store a locale name in \
the session (if a session exists). +
+
\ No newline at end of file
Modified: tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/parameters.apt
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/parameters.apt?view=diff&rev=480804&r1=480803&r2=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/parameters.apt \
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/site/apt/guide/parameters.apt Wed Nov \
29 18:00:43 2006 @@ -121,8 +121,11 @@
*------------+----------------------------------------------------------------------------------+
| literal: | A literal string. \
|
*------------+----------------------------------------------------------------------------------+
+| message | Retrieves a value from the component's {{{localization.html}message \
catalog}}. | +*------------+----------------------------------------------------------------------------------+
| prop: | The name of a property of the containing component to read or \
update. |
*------------+----------------------------------------------------------------------------------+
+
The default binding prefix is "prop:".
Modified: tapestry/tapestry5/tapestry-core/trunk/src/site/site.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/site/site.xml?view=diff&rev=480804&r1=480803&r2=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/site/site.xml (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/site/site.xml Wed Nov 29 18:00:43 2006
@@ -56,6 +56,7 @@
<item name="Component Parameters" href="guide/parameters.html"/>
<item name="Component Events" href="guide/event.html"/>
<item name="Component Mixins" href="guide/mixins.html"/>
+ <item name="Localization" href="guide/localization.html"/>
<item name="Type Coercion" href="guide/coercion.html"/>
<item name="Component Rendering" href="guide/rendering.html"/>
<item name="Persistent Data" href="guide/persist.html"/>
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java \
/org/apache/tapestry/integration/IntegrationTests.java?view=diff&rev=480804&r1=480803&r2=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java \
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java \
Wed Nov 29 18:00:43 2006 @@ -316,6 +316,8 @@
clickAndWait("link=Localization");
assertTextPresent("Via injected Messages property: [Accessed via injected \
Messages]"); + assertTextPresent("Via message: binding prefix: [Accessed via \
message: binding prefix]"); + assertTextPresent("Page locale: [en]");
}
private void assertText(String locator, String expected)
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/Localization.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java \
/org/apache/tapestry/integration/app1/pages/Localization.java?view=diff&rev=480804&r1=480803&r2=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/Localization.java \
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/Localization.java \
Wed Nov 29 18:00:43 2006 @@ -14,10 +14,13 @@
package org.apache.tapestry.integration.app1.pages;
+import java.util.Locale;
+
import org.apache.tapestry.annotations.ComponentClass;
import org.apache.tapestry.annotations.Inject;
import org.apache.tapestry.ioc.Messages;
import org.apache.tapestry.ioc.services.ClassFactory;
+import org.apache.tapestry.services.WebRequest;
@ComponentClass
public class Localization
@@ -30,6 +33,22 @@
@Inject("service:tapestry.ComponentClassFactory")
private ClassFactory _componentClassFactory;
+
+ @Inject
+ private Locale _locale;
+
+ @Inject("infrastructure:request")
+ private WebRequest _request;
+
+ public Locale getLocale()
+ {
+ return _locale;
+ }
+
+ public WebRequest getRequest()
+ {
+ return _request;
+ }
public String getInjectedMessage()
{
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PagePoolImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java \
/org/apache/tapestry/internal/services/PagePoolImplTest.java?view=diff&rev=480804&r1=480803&r2=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PagePoolImplTest.java \
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PagePoolImplTest.java \
Wed Nov 29 18:00:43 2006 @@ -21,6 +21,7 @@
import org.apache.commons.logging.Log;
import org.apache.tapestry.internal.structure.Page;
import org.apache.tapestry.internal.test.InternalBaseTestCase;
+import org.apache.tapestry.ioc.services.ThreadLocale;
import org.testng.annotations.Test;
/**
@@ -39,12 +40,15 @@
{
PageLoader loader = newPageLoader();
Page page = newPage();
+ ThreadLocale tl = newThreadLocale();
+
+ train_getLocale(tl, _locale);
train_loadPage(loader, PAGE_NAME, _locale, page);
replay();
- PagePool pool = new PagePoolImpl(null, loader);
+ PagePool pool = new PagePoolImpl(null, loader, tl);
assertSame(page, pool.checkout(PAGE_NAME));
@@ -57,15 +61,18 @@
PageLoader loader = newPageLoader();
Page page1 = newPage();
Page page2 = newPage();
+ ThreadLocale tl = newThreadLocale();
train_detached(page1, false);
train_getName(page1, PAGE_NAME);
+ train_getLocale(tl, _locale);
+
train_loadPage(loader, PAGE_NAME, _locale, page2);
replay();
- PagePool pool = new PagePoolImpl(null, loader);
+ PagePool pool = new PagePoolImpl(null, loader, tl);
pool.release(page1);
@@ -78,6 +85,8 @@
verify();
}
+ // This should move up to IOCTestCase
+
protected final void train_detached(Page page, boolean dirty)
{
expect(page.detached()).andReturn(dirty);
@@ -100,7 +109,7 @@
replay();
- PagePool pool = new PagePoolImpl(null, loader);
+ PagePool pool = new PagePoolImpl(null, loader, null);
pool.release(page1);
pool.release(page2);
@@ -126,7 +135,7 @@
replay();
- PagePool pool = new PagePoolImpl(log, loader);
+ PagePool pool = new PagePoolImpl(log, loader, null);
pool.release(page);
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Localization.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/reso \
urces/org/apache/tapestry/integration/app1/pages/Localization.html?view=diff&rev=480804&r1=480803&r2=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Localization.html \
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Localization.html \
Wed Nov 29 18:00:43 2006 @@ -8,6 +8,13 @@
<p> Via injected Messages property: [${injectedMessage}] </p>
+ <p> Via message: binding prefix: [${message:via-prefix}]</p>
+
+ <p> Page locale: [${locale}]</p>
+
+ <p> Request locale: [${request.locale}]</p>
+
+<hr/>
<h2>Fabricated classes:</h2>
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Localization.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/reso \
urces/org/apache/tapestry/integration/app1/pages/Localization.properties?view=diff&rev=480804&r1=480803&r2=480804
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Localization.properties \
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app1/pages/Localization.properties \
Wed Nov 29 18:00:43 2006 @@ -1 +1,2 @@
-via-inject=Accessed via injected Messages
\ No newline at end of file
+via-inject=Accessed via injected Messages
+via-prefix=Accessed via message: binding prefix
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic