You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by jk...@apache.org on 2015/12/11 11:36:29 UTC
tapestry-5 git commit: TAP5-2238: don't redirect to a stack in the
wrong locale
Repository: tapestry-5
Updated Branches:
refs/heads/master 2f81c8735 -> 8365e4823
TAP5-2238: don't redirect to a stack in the wrong locale
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/8365e482
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/8365e482
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/8365e482
Branch: refs/heads/master
Commit: 8365e48232c2a32c686904865658b303e9e3d3ba
Parents: 2f81c87
Author: Jochen Kemnade <jo...@eddyson.de>
Authored: Fri Dec 11 11:35:51 2015 +0100
Committer: Jochen Kemnade <jo...@eddyson.de>
Committed: Fri Dec 11 11:35:51 2015 +0100
----------------------------------------------------------------------
.../services/javascript/ModuleDispatcher.java | 14 +++++++++++---
.../apache/tapestry5/modules/JavaScriptModule.java | 7 +++++--
.../services/javascript/ModuleDispatcherTests.groovy | 14 +++++++++++---
3 files changed, 27 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8365e482/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java
index 4050b39..d011a8d 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleDispatcher.java
@@ -22,6 +22,7 @@ import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.services.Dispatcher;
+import org.apache.tapestry5.services.LocalizationSetter;
import org.apache.tapestry5.services.PathConstructor;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.Response;
@@ -32,6 +33,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.EnumSet;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -54,6 +56,8 @@ public class ModuleDispatcher implements Dispatcher
private final JavaScriptStackPathConstructor javaScriptStackPathConstructor;
+ private final LocalizationSetter localizationSetter;
+
private final String requestPrefix;
private final String stackPathPrefix;
@@ -64,13 +68,13 @@ public class ModuleDispatcher implements Dispatcher
private Map<String, String> moduleNameToStackName;
-
public ModuleDispatcher(ModuleManager moduleManager,
ResourceStreamer streamer,
OperationTracker tracker,
PathConstructor pathConstructor,
JavaScriptStackSource javaScriptStackSource,
JavaScriptStackPathConstructor javaScriptStackPathConstructor,
+ LocalizationSetter localizationSetter,
String prefix,
@Symbol(SymbolConstants.ASSET_PATH_PREFIX)
String assetPrefix,
@@ -81,6 +85,7 @@ public class ModuleDispatcher implements Dispatcher
this.tracker = tracker;
this.javaScriptStackSource = javaScriptStackSource;
this.javaScriptStackPathConstructor = javaScriptStackPathConstructor;
+ this.localizationSetter = localizationSetter;
this.compress = compress;
requestPrefix = pathConstructor.constructDispatchPath(compress ? prefix + ".gz" : prefix) + "/";
@@ -95,7 +100,9 @@ public class ModuleDispatcher implements Dispatcher
{
String extraPath = path.substring(requestPrefix.length());
- if (!handleModuleRequest(extraPath, response))
+ Locale locale = request.getLocale();
+
+ if (!handleModuleRequest(locale, extraPath, response))
{
response.sendError(HttpServletResponse.SC_NOT_FOUND, String.format("No module for path '%s'.", extraPath));
}
@@ -107,7 +114,7 @@ public class ModuleDispatcher implements Dispatcher
}
- private boolean handleModuleRequest(String extraPath, Response response) throws IOException
+ private boolean handleModuleRequest(Locale locale, String extraPath, Response response) throws IOException
{
// Ensure request ends with '.js'. That's the extension tacked on by RequireJS because it expects there
// to be a hierarchy of static JavaScript files here. In reality, we may be cross-compiling CoffeeScript to
@@ -132,6 +139,7 @@ public class ModuleDispatcher implements Dispatcher
if (stackName != null)
{
+ localizationSetter.setNonPersistentLocaleFromLocaleName(locale.toString());
List<String> libraryUrls = javaScriptStackPathConstructor.constructPathsForJavaScriptStack(stackName);
if (libraryUrls.size() == 1)
{
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8365e482/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
index 1bdcc4e..432992d 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/modules/JavaScriptModule.java
@@ -216,6 +216,7 @@ public class JavaScriptModule
PathConstructor pathConstructor,
JavaScriptStackSource javaScriptStackSource,
JavaScriptStackPathConstructor javaScriptStackPathConstructor,
+ LocalizationSetter localizationSetter,
@Symbol(SymbolConstants.MODULE_PATH_PREFIX)
String modulePathPrefix,
@Symbol(SymbolConstants.ASSET_PATH_PREFIX)
@@ -223,12 +224,14 @@ public class JavaScriptModule
{
configuration.add("Modules",
new ModuleDispatcher(moduleManager, resourceStreamer, tracker, pathConstructor,
- javaScriptStackSource, javaScriptStackPathConstructor, modulePathPrefix, assetPathPrefix, false),
+ javaScriptStackSource, javaScriptStackPathConstructor, localizationSetter, modulePathPrefix,
+ assetPathPrefix, false),
"after:Asset", "before:ComponentEvent");
configuration.add("ComnpressedModules",
new ModuleDispatcher(moduleManager, resourceStreamer, tracker, pathConstructor,
- javaScriptStackSource, javaScriptStackPathConstructor, modulePathPrefix, assetPathPrefix, true),
+ javaScriptStackSource, javaScriptStackPathConstructor, localizationSetter, modulePathPrefix,
+ assetPathPrefix, true),
"after:Modules", "before:ComponentEvent");
}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/8365e482/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy
index 691469e..86e555f 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/services/javascript/ModuleDispatcherTests.groovy
@@ -4,6 +4,7 @@ import org.apache.tapestry5.internal.services.javascript.JavaScriptStackPathCons
import org.apache.tapestry5.internal.services.javascript.ModuleDispatcher
import org.apache.tapestry5.ioc.internal.QuietOperationTracker
import org.apache.tapestry5.ioc.test.TestBase
+import org.apache.tapestry5.services.LocalizationSetter;
import org.apache.tapestry5.services.PathConstructor
import org.apache.tapestry5.services.Request
import org.apache.tapestry5.services.Response
@@ -22,19 +23,21 @@ class ModuleDispatcherTests extends TestBase {
def pc = newMock PathConstructor
def javaScriptStackSource = newMock JavaScriptStackSource
def javaScriptStackPathConstructor = newMock JavaScriptStackPathConstructor
+ def localizationSetter = newMock LocalizationSetter
expect(pc.constructDispatchPath("modules")).andReturn("/modules")
expect(pc.constructDispatchPath("assets", "stack")).andReturn("/assets/stack")
expect(request.path).andReturn(path)
+ expect(request.locale).andReturn(Locale.US)
expect(response.sendError(EasyMock.eq(HttpServletResponse.SC_NOT_FOUND), EasyMock.notNull()))
replay()
def handler = new ModuleDispatcher(null, null, new QuietOperationTracker(), pc,
- javaScriptStackSource, javaScriptStackPathConstructor, "modules", "assets", false)
+ javaScriptStackSource, javaScriptStackPathConstructor, localizationSetter, "modules", "assets", false)
assert handler.dispatch(request, response) == true
@@ -60,12 +63,14 @@ class ModuleDispatcherTests extends TestBase {
def pc = newMock PathConstructor
def javaScriptStackSource = newMock JavaScriptStackSource
def javaScriptStackPathConstructor = newMock JavaScriptStackPathConstructor
+ def localizationSetter = newMock LocalizationSetter
expect(pc.constructDispatchPath("modules")).andReturn("/modules")
expect(pc.constructDispatchPath("assets", "stack")).andReturn("/assets/stack")
expect(request.path).andReturn("/modules/foo/bar.js")
+ expect(request.locale).andReturn(Locale.US)
expect(manager.findResourceForModule("foo/bar")).andReturn null
@@ -76,7 +81,7 @@ class ModuleDispatcherTests extends TestBase {
replay()
def handler = new ModuleDispatcher(manager, null, new QuietOperationTracker(), pc,
- javaScriptStackSource, javaScriptStackPathConstructor, "modules", "assets", false)
+ javaScriptStackSource, javaScriptStackPathConstructor, localizationSetter, "modules", "assets", false)
assert handler.dispatch(request, response) == true
@@ -94,23 +99,26 @@ class ModuleDispatcherTests extends TestBase {
def stack = newMock JavaScriptStack
def javaScriptStackSource = newMock JavaScriptStackSource
def javaScriptStackPathConstructor = newMock JavaScriptStackPathConstructor
+ def localizationSetter = newMock LocalizationSetter
expect(pc.constructDispatchPath("modules")).andReturn("/modules")
expect(pc.constructDispatchPath("assets", "stack")).andReturn("/assets/stack")
expect(request.path).andReturn("/modules/foo/bar.js")
+ expect(request.locale).andReturn(Locale.US)
expect(javaScriptStackSource.getStackNames()).andReturn(["default"])
expect(javaScriptStackSource.getStack("default")).andReturn(stack)
expect(stack.getModules()).andReturn(["foo/bar"])
+ expect(localizationSetter.setNonPersistentLocaleFromLocaleName("en_US"))
expect(javaScriptStackPathConstructor.constructPathsForJavaScriptStack("default")).andReturn(["/assets/stack/default.js"])
expect(response.sendRedirect("/assets/stack/default.js"))
replay()
def handler = new ModuleDispatcher(manager, null, new QuietOperationTracker(), pc,
- javaScriptStackSource, javaScriptStackPathConstructor, "modules", "assets", false)
+ javaScriptStackSource, javaScriptStackPathConstructor, localizationSetter, "modules", "assets", false)
assert handler.dispatch(request, response) == true