Author: jkuhnert
Date: Tue Aug 14 15:44:17 2007
New Revision: 565956
URL: http://svn.apache.org/viewvc?view=rev&rev=565956
Log:
Fixes TAPESTRY-399. Setting setLocale(Locale) on AbstractEngine was having no
effect in Redirects becuase locales are only persisted normally during a full
new render..
Changed Infrastructure so it detects a locale setting and appropriately
persists the changes automatically if necessary.
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/ListenerMethodBinding.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/AbstractEngine.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/RequestLocaleManager.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/InfrastructureImpl.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/RequestCycleFactoryImpl.java
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/RequestLocaleManagerImpl.java
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/ListenerMethodBinding.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/ListenerMethodBinding.java?view=diff&rev=565956&r1=565955&r2=565956
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/ListenerMethodBinding.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/binding/ListenerMethodBinding.java
Tue Aug 14 15:44:17 2007
@@ -37,7 +37,7 @@
private IActionListener _listener;
public ListenerMethodBinding(String description, ValueConverter
valueConverter, Location location,
- IComponent component, String methodName)
+ IComponent component, String methodName)
{
super(description, valueConverter, location);
@@ -89,11 +89,11 @@
throw ex;
}
catch (RuntimeException ex)
- {
+ {
throw new BindingException(BindingMessages.listenerMethodFailure(
- _component,
- _methodName,
- ex), _component, getLocation(), this, ex);
+ _component,
+ _methodName,
+ ex), _component, getLocation(), this, ex);
}
}
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/AbstractEngine.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/AbstractEngine.java?view=diff&rev=565956&r1=565955&r2=565956
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/AbstractEngine.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/engine/AbstractEngine.java
Tue Aug 14 15:44:17 2007
@@ -78,7 +78,7 @@
* available in JARs or WARs.</td>
* </tr>
* </table>
- *
+ *
* @author Howard Lewis Ship
*/
@@ -90,12 +90,12 @@
*/
public static final String VISIT_CLASS_PROPERTY_NAME =
"org.apache.tapestry.visit-class";
-
+
private static final Log LOG = LogFactory.getLog(AbstractEngine.class);
/**
* The link to the world of HiveMind services.
- *
+ *
* @since 4.0
*/
private Infrastructure _infrastructure;
@@ -119,7 +119,7 @@
/**
* Writes a detailed report of the exception to <code>System.err</code>.
- *
+ *
* @see org.apache.tapestry.error.RequestExceptionReporter
*/
@@ -150,7 +150,7 @@
/**
* Returns a service with the given name.
- *
+ *
* @see Infrastructure#getServiceMap()
* @see org.apache.tapestry.services.ServiceMap
*/
@@ -180,7 +180,8 @@
*/
protected void redirect(String pageName, IRequestCycle cycle,
- ApplicationRuntimeException exception) throws IOException
+ ApplicationRuntimeException exception)
+ throws IOException
{
IPage page = cycle.getPage(pageName);
@@ -194,7 +195,8 @@
* [EMAIL PROTECTED]
org.apache.tapestry.services.ResponseRenderer#renderResponse(IRequestCycle)}.
*/
- public void renderResponse(IRequestCycle cycle) throws IOException
+ public void renderResponse(IRequestCycle cycle)
+ throws IOException
{
_infrastructure.getResponseRenderer().renderResponse(cycle);
}
@@ -203,7 +205,8 @@
* Delegate method for the servlet. Services the request.
*/
- public void service(WebRequest request, WebResponse response) throws
IOException
+ public void service(WebRequest request, WebResponse response)
+ throws IOException
{
IRequestCycle cycle = null;
IEngineService service = null;
@@ -232,11 +235,10 @@
try
{
service = cycle.getService();
+
// Let the service handle the rest of the request.
-
+
service.service(cycle);
-
- return;
}
catch (PageRedirectException ex)
{
@@ -279,19 +281,19 @@
}
}
}
-
+
/**
* Handles [EMAIL PROTECTED] PageRedirectException} which involves
executing
* [EMAIL PROTECTED] IRequestCycle#activate(IPage)} on the target page (of
the exception), until either a
* loop is found, or a page succesfully activates.
* <p>
* This should generally not be overriden in subclasses.
- *
+ *
* @since 3.0
*/
protected void handlePageRedirectException(IRequestCycle cycle,
PageRedirectException exception)
- throws IOException
+ throws IOException
{
List pageNames = new ArrayList();
@@ -344,12 +346,12 @@
* implementation (probably a good idea, because the default page hints at
"application errors"
* and isn't localized). The overriding StaleLink implementation must
implement a message
* property of type String.
- *
+ *
* @since 0.2.10
*/
protected void handleStaleLinkException(IRequestCycle cycle,
StaleLinkException exception)
- throws IOException
+ throws IOException
{
_infrastructure.getStaleLinkExceptionPresenter().presentStaleLinkException(cycle,
exception);
}
@@ -363,12 +365,12 @@
* Subclasses may overide this method (without invoking this
implementation), but it is better
* to override the tapestry.error.StaleSessionExceptionReporter service
instead (or contribute a
* replacement to the tapestry.InfrastructureOverrides configuration
point).
- *
+ *
* @since 0.2.10
*/
protected void handleStaleSessionException(IRequestCycle cycle,
StaleSessionException exception)
- throws IOException
+ throws IOException
{
_infrastructure.getStaleSessionExceptionPresenter().presentStaleSessionException(cycle,
exception);
}
@@ -401,7 +403,7 @@
/**
* [EMAIL PROTECTED]
*/
-
+
public String toString()
{
ToStringBuilder builder = new ToStringBuilder(this);
@@ -453,7 +455,7 @@
/**
* Allows subclasses to include listener methods easily.
- *
+ *
* @since 1.0.2
*/
@@ -467,7 +469,7 @@
/**
* Invoked when a [EMAIL PROTECTED] RedirectException} is thrown during
the processing of a request.
- *
+ *
* @throws ApplicationRuntimeException
* if an [EMAIL PROTECTED] IOException},[EMAIL PROTECTED]
ServletException}is thrown by the redirect,
* or if no [EMAIL PROTECTED] javax.servlet.RequestDispatcher}
can be found for local resource.
@@ -480,7 +482,7 @@
if (LOG.isDebugEnabled())
LOG.debug("Redirecting to: " + location);
-
+
_infrastructure.getRequest().forward(location);
}
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/RequestLocaleManager.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/RequestLocaleManager.java?view=diff&rev=565956&r1=565955&r2=565956
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/RequestLocaleManager.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/RequestLocaleManager.java
Tue Aug 14 15:44:17 2007
@@ -31,6 +31,8 @@
/**
* Determines the locale to use for processing the current request. The
* value is returned, but also stored as locale.
+ *
+ * @return The [EMAIL PROTECTED] Locale} to be used for this request.
*/
Locale extractLocaleForCurrentRequest();
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/InfrastructureImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/InfrastructureImpl.java?view=diff&rev=565956&r1=565955&r2=565956
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/InfrastructureImpl.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/InfrastructureImpl.java
Tue Aug 14 15:44:17 2007
@@ -77,9 +77,13 @@
private String _outputEncoding;
+ private RequestLocaleManager _localeManager;
+
public void setLocale(Locale locale)
{
_threadLocale.setLocale(locale);
+
+ _localeManager.persistLocale();
}
public String getApplicationId()
@@ -384,6 +388,11 @@
public void setOverrideContributions(List overrideContributions)
{
_overrideContributions = overrideContributions;
+ }
+
+ public void setLocaleManager(RequestLocaleManager manager)
+ {
+ _localeManager = manager;
}
public void setErrorLog(ErrorLog errorLog)
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/RequestCycleFactoryImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/RequestCycleFactoryImpl.java?view=diff&rev=565956&r1=565955&r2=565956
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/RequestCycleFactoryImpl.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/RequestCycleFactoryImpl.java
Tue Aug 14 15:44:17 2007
@@ -34,14 +34,14 @@
/**
* Service that creates instances of [EMAIL PROTECTED]
org.apache.tapestry.IRequestCycle}on behalf of an
* engine.
- *
+ *
* @author Howard M. Lewis Ship
* @since 4.0
*/
public class RequestCycleFactoryImpl implements RequestCycleFactory
{
private ServiceEncoder[] _encoders;
-
+
private PropertyPersistenceStrategySource _strategySource;
private ErrorHandler _errorHandler;
@@ -55,37 +55,37 @@
private RequestGlobals _requestGlobals;
private ResponseDelegateFactory _responseDelegateFactory;
-
+
public void initializeService()
{
_environment = new RequestCycleEnvironment(_errorHandler,
_infrastructure, _strategySource,
- _absoluteURLBuilder);
+ _absoluteURLBuilder);
}
public IRequestCycle newRequestCycle(IEngine engine)
{
WebRequest request = _infrastructure.getRequest();
-
+
QueryParameterMap parameters = extractParameters(request);
-
+
decodeParameters(request.getActivationPath(), request.getPathInfo(),
parameters);
-
+
String serviceName = findService(parameters);
-
+
IRequestCycle cycle = new RequestCycle(engine, parameters,
serviceName, _environment);
-
+
_requestGlobals.store(cycle);
-
+
try {
-
+
_requestGlobals.store(_responseDelegateFactory.getResponseBuilder(cycle));
-
+
cycle.setResponseBuilder(_requestGlobals.getResponseBuilder());
-
+
} catch (IOException e) {
throw new ApplicationRuntimeException("Error creating response
builder.", e);
}
-
+
return cycle;
}
@@ -165,7 +165,7 @@
{
_requestGlobals = requestGlobals;
}
-
+
/**
* For injection.
*/
Modified:
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/RequestLocaleManagerImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/RequestLocaleManagerImpl.java?view=diff&rev=565956&r1=565955&r2=565956
==============================================================================
---
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/RequestLocaleManagerImpl.java
(original)
+++
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/RequestLocaleManagerImpl.java
Tue Aug 14 15:44:17 2007
@@ -26,7 +26,7 @@
/**
* Service tapestry.request.RequestLocaleManager. Identifies the Locale
provided by the client
* (either in a Tapestry-specific cookie, or interpolated from the HTTP header.
- *
+ *
* @author Howard Lewis Ship
* @since 4.0
*/
@@ -69,6 +69,12 @@
private Map _localeCache = new HashMap();
+ /**
+ * Reference to last persisted locale, if any. Used to prevent
+ * duplicate cookie writes of the same locale.
+ */
+ private Locale _lastPersisted;
+
public void initializeService()
{
String[] names = TapestryUtils.split(_acceptedLocales);
@@ -79,7 +85,6 @@
_defaultLocale = getLocale(names[0]);
_acceptedLocaleNamesSet.addAll(Arrays.asList(names));
-
}
public Locale extractLocaleForCurrentRequest()
@@ -87,7 +92,7 @@
String localeName =
_cookieSource.readCookieValue(TapestryConstants.LOCALE_COOKIE_NAME);
String requestedLocale = (localeName != null) ? localeName :
_request.getLocale().toString();
-
+
_requestLocale = filterRequestedLocale(requestedLocale);
_threadLocale.setLocale(_requestLocale);
@@ -116,9 +121,10 @@
// now try "best match"
- for (Iterator it = _acceptedLocaleNamesSet.iterator(); it.hasNext();) {
-
+ for (Iterator it = _acceptedLocaleNamesSet.iterator(); it.hasNext();)
+ {
String locale = (String) it.next();
+
if (locale.startsWith(localeName))
return getLocale(locale);
}
@@ -137,10 +143,12 @@
{
Locale locale = _threadLocale.getLocale();
- if (locale.equals(_requestLocale))
+ if (locale.equals(_requestLocale)
+ || _lastPersisted != null && locale.equals(_lastPersisted))
return;
_cookieSource.writeCookieValue(TapestryConstants.LOCALE_COOKIE_NAME,
locale.toString());
+ _lastPersisted = locale;
}
Locale getLocale(String name)