You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by fr...@apache.org on 2007/01/14 16:42:52 UTC
svn commit: r496092 - in /tapestry/tapestry5/tapestry-core/trunk: ./
src/main/java/org/apache/tapestry/internal/services/
src/main/java/org/apache/tapestry/services/
src/main/java/org/apache/tapestry/test/pagelevel/ src/test/app2/WEB-INF/
src/test/java...
Author: freemant
Date: Sun Jan 14 07:42:50 2007
New Revision: 496092
URL: http://svn.apache.org/viewvc?view=rev&rev=496092
Log:
Supports cookies and persistent locale.
Added:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookieSink.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookieSource.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/Cookies.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookiesImpl.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocale.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocaleImpl.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ComponentInvocationMapForPageTester.java
- copied, changed from r495829, tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/InAppInvocationMapForPageTester.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ContextForPageTester.java
- copied, changed from r495829, tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTesterContext.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/CookiesForPageTester.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/app2/WEB-INF/TestPageForTemplateInWEBINF.html
- copied unchanged from r495829, tapestry/tapestry5/tapestry-core/trunk/src/test/app2/WEB-INF/TestPageForTemplateInContext.html
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTemplateInWEBINF.java
- copied, changed from r495829, tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTemplateInContext.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/TemplateInWEBINFTest.java
- copied, changed from r495829, tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/TemplateInContextTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterImplTest.java
- copied, changed from r495829, tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpCookieSource.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentLocaleImplTest.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/services/CookiesImplTest.java (with props)
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/test/pagelevel/ContextForPageTesterTest.java
- copied, changed from r495829, tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/test/pagelevel/PageTesterContextTest.java
Removed:
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/InAppInvocationMapForPageTester.java
tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTesterContext.java
tapestry/tapestry5/tapestry-core/trunk/src/test/app2/WEB-INF/TestPageForTemplateInContext.html
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTemplateInContext.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/TemplateInContextTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterTest.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/test/pagelevel/PageTesterContextTest.java
Modified:
tapestry/tapestry5/tapestry-core/trunk/.classpath
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/LocalizationSetterImpl.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/pagelevel/PageTester.java
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/integration/app1/services/AppModule.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForLocale.java
tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LocaleTest.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/app2/pages/TestPageForLocale.html
Modified: tapestry/tapestry5/tapestry-core/trunk/.classpath
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/.classpath?view=diff&rev=496092&r1=496091&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/.classpath (original)
+++ tapestry/tapestry5/tapestry-core/trunk/.classpath Sun Jan 14 07:42:50 2007
@@ -1,11 +1,11 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src/main/java"/>
- <classpathentry kind="lib" path="src/main/resources"/>
- <classpathentry kind="src" path="src/test/java"/>
- <classpathentry kind="lib" path="src/test/resources"/>
- <classpathentry kind="lib" path="src/test/conf"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="lib" path="src/main/resources"/>
+ <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry kind="lib" path="src/test/resources"/>
+ <classpathentry kind="lib" path="src/test/conf"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
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=496092&r1=496091&r2=496092
==============================================================================
--- 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 Sun Jan 14 07:42:50 2007
@@ -61,6 +61,7 @@
import org.apache.tapestry.services.MarkupWriterFactory;
import org.apache.tapestry.services.PageRenderInitializer;
import org.apache.tapestry.services.PersistentFieldManager;
+import org.apache.tapestry.services.PersistentLocale;
import org.apache.tapestry.services.Request;
import org.apache.tapestry.services.RequestExceptionHandler;
import org.apache.tapestry.services.RequestFilter;
@@ -272,10 +273,11 @@
configuration.add("Localization", new LocalizationFilter(localizationSetter));
}
- public LocalizationSetter buildLocalizationSetter(@Inject("${tapestry.supported-locales}")
+ public LocalizationSetter buildLocalizationSetter(@InjectService("tapestry.PersistentLocale")
+ PersistentLocale persistentLocale, @Inject("${tapestry.supported-locales}")
String localeNames)
{
- return new LocalizationSetterImpl(_threadLocale, localeNames);
+ return new LocalizationSetterImpl(persistentLocale, _threadLocale, localeNames);
}
/**
@@ -286,6 +288,7 @@
{
configuration.add("tapestry.file-check-interval", "1000"); // 1 second
configuration.add("tapestry.supported-locales", "en");
+ configuration.add("tapestry.default-cookie-max-age", "604800"); // One week
}
/**
@@ -591,4 +594,4 @@
componentClassResolver);
}
-}
\ No newline at end of file
+ }
\ No newline at end of file
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetterImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetterImpl.java?view=diff&rev=496092&r1=496091&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetterImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/LocalizationSetterImpl.java Sun Jan 14 07:42:50 2007
@@ -22,6 +22,7 @@
import java.util.Set;
import org.apache.tapestry.ioc.services.ThreadLocale;
+import org.apache.tapestry.services.PersistentLocale;
/**
* Given a set of supported locales, for a specified desired locale, sets the current thread's
@@ -37,8 +38,12 @@
private final Map<String, Locale> _localeCache = newThreadSafeMap();
- public LocalizationSetterImpl(ThreadLocale threadLocale, String acceptedLocaleNames)
+ private PersistentLocale _persistentLocale;
+
+ public LocalizationSetterImpl(PersistentLocale persistentLocale, ThreadLocale threadLocale, String acceptedLocaleNames)
{
+ _persistentLocale = persistentLocale;
+
_threadLocale = threadLocale;
String[] names = acceptedLocaleNames.split(",");
@@ -85,6 +90,10 @@
public void setThreadLocale(Locale desiredLocale)
{
+ if (_persistentLocale.get() != null)
+ {
+ desiredLocale = _persistentLocale.get();
+ }
Locale locale = findClosestAcceptedLocale(desiredLocale);
_threadLocale.setLocale(locale);
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookieSink.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookieSink.java?view=auto&rev=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookieSink.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookieSink.java Sun Jan 14 07:42:50 2007
@@ -0,0 +1,30 @@
+// 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.services;
+
+import javax.servlet.http.Cookie;
+
+/**
+ * You can write cookies to it.
+ */
+public interface CookieSink
+{
+
+ /**
+ * Adds a cookie to the sink
+ */
+ void addCookie(Cookie cookie);
+
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookieSink.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookieSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookieSource.java?view=auto&rev=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookieSource.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookieSource.java Sun Jan 14 07:42:50 2007
@@ -0,0 +1,29 @@
+// 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.services;
+
+import javax.servlet.http.Cookie;
+
+/**
+ * Provides the cookies from the browser.
+ */
+public interface CookieSource
+{
+ /**
+ * Returns the cookies from the browser.
+ */
+ Cookie[] getCookies();
+
+}
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/Cookies.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/Cookies.java?view=auto&rev=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/Cookies.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/Cookies.java Sun Jan 14 07:42:50 2007
@@ -0,0 +1,83 @@
+// 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.services;
+
+/**
+ * Used by other services to obtain cookie values for the current request.
+ *
+ * @author Howard Lewis Ship
+ * @since 4.0
+ */
+public interface Cookies
+{
+ /**
+ * Returns the value of the first cookie whose name matches. Returns null if no such cookie
+ * exists. This method is only aware of cookies that are part of the incoming request; it does
+ * not know about additional cookies added since then (via
+ * {@link #writeCookieValue(String, String)}).
+ */
+ String readCookieValue(String name);
+
+ /**
+ * Creates or updates a cookie value. The value is stored using a max age (in seconds) defined
+ * by the symbol <code>org.apache.tapestry.default-cookie-max-age</code>. The factory default
+ * for this value is the equivalent of one week.
+ */
+
+ void writeCookieValue(String name, String value);
+
+ /**
+ * As with {@link #writeCookieValue(String, String)} but an explicit maximum age may be set.
+ *
+ * @param name
+ * the name of the cookie
+ * @param value
+ * the value to be stored in the cookie
+ * @param maxAge
+ * the maximum age, in seconds, to store the cookie
+ */
+
+ void writeCookieValue(String name, String value, int maxAge);
+
+ /**
+ * As with {@link #writeCookieValue(String, String)} but an explicit path
+ * may be set.
+ */
+ void writeCookieValue(String name, String value, String path);
+
+ /**
+ * As with {@link #writeCookieValue(String, String)} but an explicit path
+ * may be set.
+ */
+ void writeDomainCookieValue(String name, String value, String domain);
+
+ /**
+ * As with {@link #writeCookieValue(String, String)} but an explicit path
+ * may be set.
+ */
+ void writeDomainCookieValue(String name, String value, String domain, int maxAge);
+
+ /**
+ * As with {@link #writeCookieValue(String, String, String)} but an explicit
+ * domain may be set.
+ */
+ void writeCookieValue(String name, String value, String path, String domain);
+
+ /**
+ * Removes a previously written cookie, by writing a new cookie with a maxAge of 0.
+ */
+
+ void removeCookieValue(String name);
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/Cookies.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookiesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookiesImpl.java?view=auto&rev=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookiesImpl.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookiesImpl.java Sun Jan 14 07:42:50 2007
@@ -0,0 +1,116 @@
+// 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.services;
+
+import javax.servlet.http.Cookie;
+
+import org.apache.tapestry.internal.services.ContextPathSource;
+
+/**
+ * Implementation of the {@link org.apache.tapestry.services.Cookies} service interface.
+ *
+ * @author Howard Lewis Ship
+ * @since 4.0
+ */
+public class CookiesImpl implements Cookies
+{
+ private ContextPathSource _contextPathSource;
+
+ private CookieSource _cookieSource;
+
+ private CookieSink _cookieSink;
+
+ private int _defaultMaxAge;
+
+ public CookiesImpl(ContextPathSource contextPathSource, CookieSource cookieSource,
+ CookieSink cookieSink, int defaultMaxAge)
+ {
+ _contextPathSource = contextPathSource;
+ _cookieSource = cookieSource;
+ _cookieSink = cookieSink;
+ _defaultMaxAge = defaultMaxAge;
+ }
+
+ public String readCookieValue(String name)
+ {
+ Cookie[] cookies = _cookieSource.getCookies();
+
+ if (cookies == null)
+ return null;
+
+ for (int i = 0; i < cookies.length; i++)
+ {
+ if (cookies[i].getName().equals(name))
+ return cookies[i].getValue();
+ }
+
+ return null;
+ }
+
+ public void writeCookieValue(String name, String value)
+ {
+ writeCookieValue(name, value, _defaultMaxAge);
+ }
+
+ public void writeCookieValue(String name, String value, int maxAge)
+ {
+ Cookie cookie = new Cookie(name, value);
+ cookie.setPath(_contextPathSource.getContextPath() + "/");
+ cookie.setMaxAge(maxAge);
+
+ _cookieSink.addCookie(cookie);
+ }
+
+ public void writeCookieValue(String name, String value, String path)
+ {
+ Cookie cookie = new Cookie(name, value);
+ cookie.setPath(path);
+ _cookieSink.addCookie(cookie);
+ }
+
+ public void writeDomainCookieValue(String name, String value, String domain)
+ {
+ Cookie cookie = new Cookie(name, value);
+ cookie.setPath(_contextPathSource.getContextPath() + "/");
+ cookie.setDomain(domain);
+ _cookieSink.addCookie(cookie);
+ }
+
+ public void writeDomainCookieValue(String name, String value, String domain, int maxAge)
+ {
+ Cookie cookie = new Cookie(name, value);
+ cookie.setPath(_contextPathSource.getContextPath() + "/");
+ cookie.setDomain(domain);
+ cookie.setMaxAge(maxAge);
+ _cookieSink.addCookie(cookie);
+ }
+
+ public void writeCookieValue(String name, String value, String path, String domain)
+ {
+ Cookie cookie = new Cookie(name, value);
+ cookie.setPath(path);
+ cookie.setDomain(domain);
+ _cookieSink.addCookie(cookie);
+ }
+
+ public void removeCookieValue(String name)
+ {
+ Cookie cookie = new Cookie(name, null);
+ cookie.setPath(_contextPathSource.getContextPath() + "/");
+ cookie.setMaxAge(0);
+ _cookieSink.addCookie(cookie);
+ }
+
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/CookiesImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocale.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocale.java?view=auto&rev=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocale.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocale.java Sun Jan 14 07:42:50 2007
@@ -0,0 +1,39 @@
+// 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.services;
+
+import java.util.Locale;
+
+/**
+ * It represents the persistent locale stored as a cookie in the browser.
+ */
+public interface PersistentLocale
+{
+ /**
+ * Sets the locale cookie in the browser.
+ */
+ void set(Locale locale);
+
+ /**
+ * Gets the locale cookie in the browser.
+ */
+ Locale get();
+
+ /**
+ * @return true if a locale cookie is set in the browser; false otherwise.
+ */
+ boolean isSet();
+
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocale.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocaleImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocaleImpl.java?view=auto&rev=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocaleImpl.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocaleImpl.java Sun Jan 14 07:42:50 2007
@@ -0,0 +1,56 @@
+// 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.services;
+
+import java.util.Locale;
+
+import org.apache.tapestry.services.Cookies;
+
+public class PersistentLocaleImpl implements PersistentLocale
+{
+ /**
+ * Name of the cookie written to the client web browser to identify the locale.
+ */
+ private static final String LOCALE_COOKIE_NAME = "org.apache.tapestry.locale";
+
+ private Cookies _cookieSource;
+
+ public PersistentLocaleImpl(Cookies cookieSource)
+ {
+ _cookieSource = cookieSource;
+ }
+
+ public void set(Locale locale)
+ {
+ _cookieSource.writeCookieValue(LOCALE_COOKIE_NAME, locale.toString());
+ }
+
+ public Locale get()
+ {
+ String localeCookieValue = getCookieValue();
+ return localeCookieValue != null ? new Locale(localeCookieValue) : null;
+ }
+
+ private String getCookieValue()
+ {
+ return _cookieSource.readCookieValue(LOCALE_COOKIE_NAME);
+ }
+
+ public boolean isSet()
+ {
+ return getCookieValue() != null;
+ }
+
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/services/PersistentLocaleImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
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=496092&r1=496091&r2=496092
==============================================================================
--- 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 Sun Jan 14 07:42:50 2007
@@ -22,6 +22,7 @@
import java.util.Map;
import javax.servlet.ServletContext;
+import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -68,6 +69,7 @@
import org.apache.tapestry.internal.services.ComponentSourceImpl;
import org.apache.tapestry.internal.services.ComponentWorker;
import org.apache.tapestry.internal.services.ContextImpl;
+import org.apache.tapestry.internal.services.ContextPathSource;
import org.apache.tapestry.internal.services.DefaultInjectionProvider;
import org.apache.tapestry.internal.services.DefaultValidationDelegateCommand;
import org.apache.tapestry.internal.services.EnvironmentImpl;
@@ -405,7 +407,7 @@
}
/**
- * Contributes filter "tapestry.StaticFilesFilter" that idenfies requests for static resources
+ * Contributes filter "tapestry.StaticFilesFilter" that identifies requests for static resources
* and terminates the pipeline by returning false. Generally, most filters should be ordered
* after this filter.
*/
@@ -666,8 +668,8 @@
configuration.add("Environment", new EnvironmentalWorker(environment));
configuration.add("Mixin", new MixinWorker(resolver));
configuration.add("OnEvent", new OnEventWorker());
- configuration.add("SupportsInf" +
- "ormalParameters", new SupportsInformalParametersWorker());
+ configuration
+ .add("SupportsInf" + "ormalParameters", new SupportsInformalParametersWorker());
configuration.add("InjectPage", new InjectPageWorker(requestPageCache));
configuration.add("InjectComponent", new InjectComponentWorker());
configuration.add("RenderCommand", new RenderCommandWorker());
@@ -1063,5 +1065,46 @@
public ComponentEventResultProcessor buildComponentInstanceResultProcessor(Log log)
{
return new ComponentInstanceResultProcessor(_requestPageCache, _linkFactory, log);
+ }
+
+ public static PersistentLocale buildPersistentLocale(@InjectService("Cookies")
+ Cookies cookies)
+ {
+ return new PersistentLocaleImpl(cookies);
+ }
+
+ public static Cookies buildCookies(@InjectService("tapestry.internal.ContextPathSource")
+ ContextPathSource contextPathSource, @InjectService("CookieSource")
+ CookieSource cookieSource, @InjectService("CookieSink")
+ CookieSink cookieSink, @Inject("${tapestry.default-cookie-max-age}")
+ int defaultMaxAge)
+ {
+ return new CookiesImpl(contextPathSource, cookieSource, cookieSink, defaultMaxAge);
+ }
+
+ public CookieSource buildCookieSource()
+ {
+ return new CookieSource()
+ {
+
+ public Cookie[] getCookies()
+ {
+ return _requestGlobals.getHTTPServletRequest().getCookies();
+ }
+
+ };
+ }
+
+ public CookieSink buildCookieSink()
+ {
+ return new CookieSink()
+ {
+
+ public void addCookie(Cookie cookie)
+ {
+ _requestGlobals.getHTTPServletResponse().addCookie(cookie);
+ }
+
+ };
}
}
Copied: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ComponentInvocationMapForPageTester.java (from r495829, tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/InAppInvocationMapForPageTester.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ComponentInvocationMapForPageTester.java?view=diff&rev=496092&p1=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/InAppInvocationMapForPageTester.java&r1=495829&p2=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ComponentInvocationMapForPageTester.java&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/InAppInvocationMapForPageTester.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ComponentInvocationMapForPageTester.java Sun Jan 14 07:42:50 2007
@@ -23,7 +23,7 @@
import org.apache.tapestry.internal.services.ComponentInvocation;
import org.apache.tapestry.internal.services.ComponentInvocationMap;
-public class InAppInvocationMapForPageTester implements ComponentInvocationMap
+public class ComponentInvocationMapForPageTester implements ComponentInvocationMap
{
private final Map<Element, Link> _elementToLink = newMap();
Copied: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ContextForPageTester.java (from r495829, tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTesterContext.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ContextForPageTester.java?view=diff&rev=496092&p1=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTesterContext.java&r1=495829&p2=tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ContextForPageTester.java&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTesterContext.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/ContextForPageTester.java Sun Jan 14 07:42:50 2007
@@ -20,11 +20,11 @@
import org.apache.tapestry.services.Context;
-public class PageTesterContext implements Context
+public class ContextForPageTester implements Context
{
private final String _contextRoot;
- public PageTesterContext(final String contextRoot)
+ public ContextForPageTester(final String contextRoot)
{
_contextRoot = contextRoot;
}
Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/CookiesForPageTester.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/CookiesForPageTester.java?view=auto&rev=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/CookiesForPageTester.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/CookiesForPageTester.java Sun Jan 14 07:42:50 2007
@@ -0,0 +1,44 @@
+// 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.test.pagelevel;
+
+import java.util.Map;
+
+import javax.servlet.http.Cookie;
+
+import org.apache.tapestry.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry.services.CookieSink;
+import org.apache.tapestry.services.CookieSource;
+
+public class CookiesForPageTester implements CookieSource, CookieSink
+{
+ private Map<String, Cookie> _cookies;
+
+ public CookiesForPageTester()
+ {
+ _cookies = CollectionFactory.newMap();
+ }
+
+ public Cookie[] getCookies()
+ {
+ return _cookies.values().toArray(new Cookie[_cookies.size()]);
+ }
+
+ public void addCookie(Cookie cookie)
+ {
+ _cookies.put(cookie.getName(), cookie);
+ }
+
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/CookiesForPageTester.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java?view=diff&rev=496092&r1=496091&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/test/pagelevel/PageTester.java Sun Jan 14 07:42:50 2007
@@ -43,10 +43,12 @@
{
private Registry _registry;
- private InAppInvocationMapForPageTester _invocationMap = new InAppInvocationMapForPageTester();
+ private ComponentInvocationMapForPageTester _invocationMap = new ComponentInvocationMapForPageTester();
private FormParameterLookupForPageTester _formParameterLookup = new FormParameterLookupForPageTester();
+ private CookiesForPageTester _cookies;
+
// For the moment, a page tester instance works in a single session.
private SessionHolderForPageTester _sessionHolder = new SessionHolderForPageTester();
@@ -100,8 +102,9 @@
public PageTester(String appPackage, String appName, String contextPath,
Map<String, Object> serviceOverrides)
{
+ _preferedLanguage = Locale.ENGLISH;
_contextPath = contextPath;
-
+ _cookies = new CookiesForPageTester();
_registry = new TapestryAppInitializer(appPackage, appName, "test",
addDefaultOverrides(serviceOverrides)).getRegistry();
@@ -113,7 +116,7 @@
"infrastructure:ApplicationGlobals",
ApplicationGlobals.class);
- globals.store(new PageTesterContext(_contextPath));
+ globals.store(new ContextForPageTester(_contextPath));
buildInvokersRegistry();
}
@@ -144,7 +147,8 @@
"tapestry.internal.FormParameterLookup",
_formParameterLookup);
addDefaultOverride(modifiedOverrides, "tapestry.internal.SessionHolder", _sessionHolder);
-
+ addDefaultOverride(modifiedOverrides, "tapestry.CookieSource", _cookies);
+ addDefaultOverride(modifiedOverrides, "tapestry.CookieSink", _cookies);
return modifiedOverrides;
}
@@ -216,10 +220,7 @@
private void setThreadLocale()
{
- if (_preferedLanguage != null)
- {
- _localizationSetter.setThreadLocale(_preferedLanguage);
- }
+ _localizationSetter.setThreadLocale(_preferedLanguage);
}
/**
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=496092&r1=496091&r2=496092
==============================================================================
--- 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 Sun Jan 14 07:42:50 2007
@@ -389,6 +389,10 @@
assertTextPresent("Via injected Messages property: [Accessed via injected Messages]");
assertTextPresent("Via message: binding prefix: [Accessed via message: binding prefix]");
assertTextPresent("Page locale: [en]");
+ clickAndWait("link=French");
+ assertTextPresent("Page locale: [fr]");
+ clickAndWait("link=English");
+ assertTextPresent("Page locale: [en]");
}
@Test
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=496092&r1=496091&r2=496092
==============================================================================
--- 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 Sun Jan 14 07:42:50 2007
@@ -18,8 +18,10 @@
import org.apache.tapestry.annotations.ComponentClass;
import org.apache.tapestry.annotations.Inject;
+import org.apache.tapestry.annotations.OnEvent;
import org.apache.tapestry.ioc.Messages;
import org.apache.tapestry.ioc.services.ClassFactory;
+import org.apache.tapestry.services.PersistentLocale;
import org.apache.tapestry.services.Request;
@ComponentClass
@@ -63,6 +65,21 @@
public ClassFactory getIocClassFactory()
{
return _iocClassFactory;
+ }
+
+ @Inject
+ private PersistentLocale persistentLocale;
+
+ @OnEvent(component = "french")
+ public void changeLocaleToFrench()
+ {
+ persistentLocale.set(Locale.FRENCH);
+ }
+
+ @OnEvent(component = "english")
+ public void changeLocaleToEnglish()
+ {
+ persistentLocale.set(Locale.ENGLISH);
}
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java?view=diff&rev=496092&r1=496091&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/services/AppModule.java Sun Jan 14 07:42:50 2007
@@ -80,4 +80,11 @@
}
};
}
+
+ @Contribute("tapestry.ioc.ApplicationDefaults")
+ public static void contributeApplicationDefaults(
+ MappedConfiguration<String, String> configuration)
+ {
+ configuration.add("tapestry.supported-locales", "en,fr");
+ }
}
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForLocale.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForLocale.java?view=diff&rev=496092&r1=496091&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForLocale.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForLocale.java Sun Jan 14 07:42:50 2007
@@ -14,10 +14,23 @@
package org.apache.tapestry.integration.app2.pages;
+import java.util.Locale;
+
import org.apache.tapestry.annotations.ComponentClass;
+import org.apache.tapestry.annotations.Inject;
+import org.apache.tapestry.annotations.OnEvent;
+import org.apache.tapestry.services.PersistentLocale;
@ComponentClass
public class TestPageForLocale
-{
-
+{
+ @Inject
+ private PersistentLocale persistentLocale;
+
+ @OnEvent(component="changeLocale")
+ public void changeLocaleToFrench()
+ {
+ persistentLocale.set(Locale.FRENCH);
+ }
+
}
Copied: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTemplateInWEBINF.java (from r495829, tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTemplateInContext.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTemplateInWEBINF.java?view=diff&rev=496092&p1=tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTemplateInContext.java&r1=495829&p2=tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTemplateInWEBINF.java&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTemplateInContext.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app2/pages/TestPageForTemplateInWEBINF.java Sun Jan 14 07:42:50 2007
@@ -17,7 +17,7 @@
import org.apache.tapestry.annotations.ComponentClass;
@ComponentClass
-public class TestPageForTemplateInContext
+public class TestPageForTemplateInWEBINF
{
public String getMsg()
{
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LocaleTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LocaleTest.java?view=diff&rev=496092&r1=496091&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LocaleTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/LocaleTest.java Sun Jan 14 07:42:50 2007
@@ -43,12 +43,20 @@
}
@Test
- public void change_language()
+ public void change_language_in_browser()
{
Document doc = _tester.renderPage("TestPageForLocale");
assertEquals(doc.getElementById("id1").getChildText(), "English page");
_tester.setPreferedLanguage(Locale.CANADA_FRENCH);
doc = _tester.renderPage("TestPageForLocale");
+ assertEquals(doc.getElementById("id1").getChildText(), "French page");
+ }
+
+ @Test
+ public void persist_locale()
+ {
+ Document doc = _tester.renderPage("TestPageForLocale");
+ doc = _tester.clickLink(doc.getElementById("changeLocale"));
assertEquals(doc.getElementById("id1").getChildText(), "French page");
}
Copied: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/TemplateInWEBINFTest.java (from r495829, tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/TemplateInContextTest.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/TemplateInWEBINFTest.java?view=diff&rev=496092&p1=tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/TemplateInContextTest.java&r1=495829&p2=tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/TemplateInWEBINFTest.java&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/TemplateInContextTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/pagelevel/TemplateInWEBINFTest.java Sun Jan 14 07:42:50 2007
@@ -20,17 +20,17 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
-public class TemplateInContextTest extends Assert
+public class TemplateInWEBINFTest extends Assert
{
private PageTester _tester;
@Test
- public void template_in_context_root()
+ public void template_in_web_inf()
{
String appPackage = "org.apache.tapestry.integration.app2";
String appName = "";
_tester = new PageTester(appPackage, appName, "src/test/app2");
- Document doc = _tester.renderPage("TestPageForTemplateInContext");
+ Document doc = _tester.renderPage("TestPageForTemplateInWEBINF");
assertTrue(doc.toString().contains("How are you?"));
}
Copied: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterImplTest.java (from r495829, tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterTest.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterImplTest.java?view=diff&rev=496092&p1=tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterTest.java&r1=495829&p2=tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterImplTest.java&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/LocalizationSetterImplTest.java Sun Jan 14 07:42:50 2007
@@ -17,11 +17,50 @@
import java.util.Locale;
import org.apache.tapestry.ioc.services.ThreadLocale;
+import org.apache.tapestry.services.PersistentLocale;
import org.testng.Assert;
import org.testng.annotations.Test;
-public class LocalizationSetterTest extends Assert
+public class LocalizationSetterImplTest extends Assert
{
+ private PersistentLocale _nullPersistentLocale = new PersistentLocale()
+ {
+ public boolean isSet()
+ {
+ return false;
+ }
+
+ public Locale get()
+ {
+ return null;
+ }
+
+ public void set(Locale locale)
+ {
+
+ }
+
+ };
+
+ private PersistentLocale _frenchPersistentLocale = new PersistentLocale()
+ {
+ public boolean isSet()
+ {
+ return true;
+ }
+
+ public Locale get()
+ {
+ return Locale.FRENCH;
+ }
+
+ public void set(Locale locale)
+ {
+
+ }
+
+ };
+
private static class ThreadLocaleImpl implements ThreadLocale
{
public Locale _locale;
@@ -49,7 +88,8 @@
@Test
public void to_locale_is_cached()
{
- LocalizationSetterImpl filter = new LocalizationSetterImpl(null, "en");
+ LocalizationSetterImpl filter = new LocalizationSetterImpl(_nullPersistentLocale, null,
+ "en");
Locale l1 = filter.toLocale("en");
@@ -71,7 +111,8 @@
@Test
public void to_locale()
{
- LocalizationSetterImpl filter = new LocalizationSetterImpl(null, "en");
+ LocalizationSetterImpl filter = new LocalizationSetterImpl(_nullPersistentLocale, null,
+ "en");
checkLocale(filter.toLocale("en"), "en", "", "");
checkLocale(filter.toLocale("klingon_Gach"), "klingon", "GACH", "");
@@ -83,7 +124,8 @@
{
ThreadLocale threadLocale = new ThreadLocaleImpl();
threadLocale.setLocale(Locale.FRENCH);
- LocalizationSetter setter = new LocalizationSetterImpl(threadLocale, "en,fr");
+ LocalizationSetter setter = new LocalizationSetterImpl(_nullPersistentLocale, threadLocale,
+ "en,fr");
setter.setThreadLocale(Locale.CANADA_FRENCH);
assertEquals(threadLocale.getLocale(), Locale.FRENCH);
@@ -94,9 +136,20 @@
{
ThreadLocale threadLocale = new ThreadLocaleImpl();
threadLocale.setLocale(Locale.FRENCH);
- LocalizationSetter setter = new LocalizationSetterImpl(threadLocale, "en,fr");
+ LocalizationSetter setter = new LocalizationSetterImpl(_nullPersistentLocale, threadLocale,
+ "en,fr");
setter.setThreadLocale(Locale.JAPANESE);
assertEquals(threadLocale.getLocale(), Locale.ENGLISH);
+ }
+
+ @Test
+ public void use_persistent_locale()
+ {
+ ThreadLocale threadLocale = new ThreadLocaleImpl();
+ LocalizationSetter setter = new LocalizationSetterImpl(_frenchPersistentLocale,
+ threadLocale, "en,fr");
+ setter.setThreadLocale(Locale.ENGLISH);
+ assertEquals(threadLocale.getLocale(), Locale.FRENCH);
}
}
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpCookieSource.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpCookieSource.java?view=auto&rev=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpCookieSource.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpCookieSource.java Sun Jan 14 07:42:50 2007
@@ -0,0 +1,49 @@
+package org.apache.tapestry.internal.services;
+
+import org.apache.tapestry.services.Cookies;
+
+public class NoOpCookieSource implements Cookies
+{
+
+ public String readCookieValue(String name)
+ {
+ return null;
+ }
+
+ public void writeCookieValue(String name, String value)
+ {
+
+ }
+
+ public void writeCookieValue(String name, String value, int maxAge)
+ {
+
+ }
+
+ public void writeCookieValue(String name, String value, String path)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void writeDomainCookieValue(String name, String value, String domain)
+ {
+
+ }
+
+ public void writeDomainCookieValue(String name, String value, String domain, int maxAge)
+ {
+
+ }
+
+ public void writeCookieValue(String name, String value, String path, String domain)
+ {
+
+ }
+
+ public void removeCookieValue(String name)
+ {
+
+ }
+
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/NoOpCookieSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentLocaleImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentLocaleImplTest.java?view=auto&rev=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentLocaleImplTest.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentLocaleImplTest.java Sun Jan 14 07:42:50 2007
@@ -0,0 +1,81 @@
+// 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.services;
+
+import java.io.IOException;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.tapestry.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry.services.Cookies;
+import org.apache.tapestry.services.PersistentLocale;
+import org.apache.tapestry.services.PersistentLocaleImpl;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class PersistentLocaleImplTest extends Assert
+{
+ @Test
+ public void get() throws IOException
+ {
+ Cookies cookieSource = new NoOpCookieSource()
+ {
+
+ @Override
+ public String readCookieValue(String name)
+ {
+ return name.equals("org.apache.tapestry.locale") ? "fr" : null;
+ }
+
+ };
+ PersistentLocale persistentLocale = new PersistentLocaleImpl(cookieSource);
+ assertEquals(persistentLocale.get(), Locale.FRENCH);
+ }
+ @Test
+ public void get_none() throws IOException
+ {
+ Cookies cookieSource = new NoOpCookieSource()
+ {
+
+ @Override
+ public String readCookieValue(String name)
+ {
+ return null;
+ }
+
+ };
+ PersistentLocale persistentLocale = new PersistentLocaleImpl(cookieSource);
+ assertNull(persistentLocale.get());
+ }
+ @Test
+ public void set() throws IOException
+ {
+ final Map<String, String> cookies = CollectionFactory.newMap();
+ Cookies cookieSource = new NoOpCookieSource()
+ {
+ @Override
+ public void writeCookieValue(String name, String value)
+ {
+ cookies.put(name, value);
+ }
+
+ };
+ PersistentLocale persistentLocale = new PersistentLocaleImpl(cookieSource);
+ persistentLocale.set(Locale.CANADA_FRENCH);
+ assertEquals(cookies.size(), 1);
+ assertEquals(cookies.get("org.apache.tapestry.locale"), "fr_CA");
+ }
+
+}
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/PersistentLocaleImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/services/CookiesImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/services/CookiesImplTest.java?view=auto&rev=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/services/CookiesImplTest.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/services/CookiesImplTest.java Sun Jan 14 07:42:50 2007
@@ -0,0 +1,225 @@
+// 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.services;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.Cookie;
+
+import org.apache.tapestry.internal.services.ContextPathSource;
+import org.apache.tapestry.ioc.internal.util.CollectionFactory;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * Tests for {@link org.apache.tapestry.services.impl.CookiesImpl}.
+ *
+ * @author Howard Lewis Ship
+ * @since 4.0
+ */
+@Test
+public class CookiesImplTest extends Assert
+{
+ private static class ComparableCookie extends Cookie
+ {
+ public ComparableCookie(String name, String value, int maxAge)
+ {
+ super(name, value);
+ setMaxAge(maxAge);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ Cookie c = (Cookie) obj;
+
+ return equals(getName(), c.getName()) && equals(getValue(), c.getValue())
+ && equals(getPath(), c.getPath()) && getMaxAge() == c.getMaxAge();
+ }
+
+ private boolean equals(Object value, Object other)
+ {
+ return value == other || (value != null && value.equals(other));
+ }
+ }
+
+ private CookieSource newCookieSource(final String[] nameValues)
+ {
+ return new CookieSource()
+ {
+ public Cookie[] getCookies()
+ {
+
+ Cookie[] cookies = null;
+
+ if (nameValues != null)
+ {
+
+ List<Cookie> l = new ArrayList<Cookie>();
+
+ for (int i = 0; i < nameValues.length; i += 2)
+ {
+ String name = nameValues[i];
+ String value = nameValues[i + 1];
+
+ Cookie c = new Cookie(name, value);
+
+ l.add(c);
+ }
+
+ cookies = l.toArray(new Cookie[l.size()]);
+ }
+ return cookies;
+ }
+ };
+ }
+
+ private void attempt(String name, String expected, String[] nameValues)
+ {
+ // In seconds
+ final int ONE_WEEK = 7 * 24 * 60 * 60;
+ CookiesImpl cs = new CookiesImpl(null, newCookieSource(nameValues), null, ONE_WEEK);
+ String actual = cs.readCookieValue(name);
+ assertEquals(actual, expected);
+ }
+
+ public void test_No_Cookies()
+ {
+ attempt("foo", null, null);
+ }
+
+ public void test_Match()
+ {
+ attempt("fred", "flintstone", new String[]
+ { "barney", "rubble", "fred", "flintstone" });
+ }
+
+ public void test_No_Match()
+ {
+ attempt("foo", null, new String[]
+ { "bar", "baz" });
+ }
+
+ public void test_Write_Cookie_Domain()
+ {
+ final List<Cookie> cookies = CollectionFactory.newList();
+ CookiesImpl cs = new CookiesImpl(new ContextPathSource()
+ {
+
+ public String getContextPath()
+ {
+ return "/context";
+ }
+
+ }, null, new CookieSink()
+ {
+
+ public void addCookie(Cookie cookie)
+ {
+ cookies.add(cookie);
+ }
+
+ }, 1000);
+
+ cs.writeDomainCookieValue("foo", "bar", "fobar.com", 1234);
+ Cookie expectedCookie = new ComparableCookie("foo", "bar", 1234);
+ expectedCookie.setPath("/context/");
+ expectedCookie.setDomain("fobar.com");
+ assertEquals(cookies.size(), 1);
+ assertEquals(cookies.get(0), expectedCookie);
+ }
+
+ public void test_Write_Cookie_With_Max_Age()
+ {
+ final List<Cookie> cookies = CollectionFactory.newList();
+ CookiesImpl cs = new CookiesImpl(new ContextPathSource()
+ {
+
+ public String getContextPath()
+ {
+ return "/ctx";
+ }
+
+ }, null, new CookieSink()
+ {
+
+ public void addCookie(Cookie cookie)
+ {
+ cookies.add(cookie);
+ }
+
+ }, 1000);
+ cs.writeCookieValue("foo", "bar", -1);
+ Cookie expectedCookie = new ComparableCookie("foo", "bar", -1);
+ expectedCookie.setPath("/ctx/");
+ assertEquals(cookies.size(), 1);
+ assertEquals(cookies.get(0), expectedCookie);
+ }
+
+ public void test_Write_Cookie()
+ {
+ final List<Cookie> cookies = CollectionFactory.newList();
+ CookiesImpl cs = new CookiesImpl(new ContextPathSource()
+ {
+
+ public String getContextPath()
+ {
+ return "/ctx";
+ }
+
+ }, null, new CookieSink()
+ {
+
+ public void addCookie(Cookie cookie)
+ {
+ cookies.add(cookie);
+ }
+
+ }, 1000);
+ cs.writeCookieValue("foo", "bar");
+ Cookie expectedCookie = new ComparableCookie("foo", "bar", 1000);
+ expectedCookie.setPath("/ctx/");
+ assertEquals(cookies.size(), 1);
+ assertEquals(cookies.get(0), expectedCookie);
+ }
+
+ public void test_Remove_Cookie()
+ {
+ final List<Cookie> cookies = CollectionFactory.newList();
+ CookiesImpl cs = new CookiesImpl(new ContextPathSource()
+ {
+
+ public String getContextPath()
+ {
+ return "/ctx";
+ }
+
+ }, null, new CookieSink()
+ {
+
+ public void addCookie(Cookie cookie)
+ {
+ cookies.add(cookie);
+ }
+
+ }, 1000);
+ cs.removeCookieValue("foo");
+ Cookie expectedCookie = new ComparableCookie("foo", null, 0);
+ expectedCookie.setPath("/ctx/");
+ assertEquals(cookies.size(), 1);
+ assertEquals(cookies.get(0), expectedCookie);
+ }
+}
\ No newline at end of file
Propchange: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/services/CookiesImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/test/pagelevel/ContextForPageTesterTest.java (from r495829, tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/test/pagelevel/PageTesterContextTest.java)
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/test/pagelevel/ContextForPageTesterTest.java?view=diff&rev=496092&p1=tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/test/pagelevel/PageTesterContextTest.java&r1=495829&p2=tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/test/pagelevel/ContextForPageTesterTest.java&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/test/pagelevel/PageTesterContextTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/test/pagelevel/ContextForPageTesterTest.java Sun Jan 14 07:42:50 2007
@@ -21,12 +21,12 @@
import org.testng.Assert;
import org.testng.annotations.Test;
-public class PageTesterContextTest extends Assert
+public class ContextForPageTesterTest extends Assert
{
@Test
public void to_URL() throws IOException
{
- PageTesterContext context = new PageTesterContext("src/test/app2");
+ ContextForPageTester context = new ContextForPageTester("src/test/app2");
URL resource = context.getResource("/OpaqueResource.txt");
InputStream stream = resource.openStream();
stream.close();
@@ -35,7 +35,7 @@
@Test
public void to_URL_no_file() throws IOException
{
- PageTesterContext context = new PageTesterContext("src/test/app2");
+ ContextForPageTester context = new ContextForPageTester("src/test/app2");
URL resource = context.getResource("/NonExisting.txt");
assertNull(resource);
}
@@ -43,7 +43,7 @@
@Test
public void to_URL_is_dir() throws IOException
{
- PageTesterContext context = new PageTesterContext("src/test");
+ ContextForPageTester context = new ContextForPageTester("src/test");
URL resource = context.getResource("/app2");
assertNull(resource);
}
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/resources/org/apache/tapestry/integration/app1/pages/Localization.html?view=diff&rev=496092&r1=496091&r2=496092
==============================================================================
--- 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 Sun Jan 14 07:42:50 2007
@@ -13,7 +13,11 @@
<p> Page locale: [${locale}]</p>
<p> Request locale: [${request.locale}]</p>
+
+ <p t:type="ActionLink" t:id="french">French</p>
+ <p t:type="ActionLink" t:id="english">English</p>
+
<hr/>
<h2>Fabricated classes:</h2>
Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale.html?view=diff&rev=496092&r1=496091&r2=496092
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale.html (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/integration/app2/pages/TestPageForLocale.html Sun Jan 14 07:42:50 2007
@@ -1,3 +1,4 @@
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<p id="id1">English page</p>
+<p t:type="ActionLink" t:id="changeLocale">Change locale</p>
</html>