Skip to content
Browse files

Added support for user-specified environments like jackup supports.

  • Loading branch information...
1 parent cc7c92b commit acdab2b629932d76474391cfbddfbf49f293d6a0 tlrobinson committed May 5, 2009
Showing with 19 additions and 2 deletions.
  1. +5 −1 README.md
  2. +14 −1 src/org/jackjs/JackServlet.java
  3. BIN war/WEB-INF/classes/org/jackjs/JackServlet.class
View
6 README.md
@@ -19,7 +19,7 @@ Coming soon.
Notes
-----
-* You can change the default modules path, module name, and application name using the "modulesPath", "module", and "app" init-params in web.xml, i.e.:
+* You can change the default modules path, module name, application name, environment name using the "modulesPath", "module", "app", and "environment" init-params in web.xml, i.e.:
<servlet>
<servlet-name>jack</servlet-name>
@@ -36,6 +36,10 @@ Notes
<param-name>app</param-name>
<param-value>app</param-value>
</init-param>
+ <init-param>
+ <param-name>environment</param-name>
+ <param-value>production</param-value>
+ </init-param>
</servlet>
* In addition to the "war/WEB-INF/narwhal" symlink, there are relative symlinks to Rhino in "war/WEB-INF/lib/js.jar" and an example application at "war/WEB-INF/jackconfig.js"
View
15 src/org/jackjs/JackServlet.java
@@ -19,6 +19,7 @@ public void init(ServletConfig config) throws ServletException {
final String modulesPath = getServletContext().getRealPath(getInitParam(config, "modulesPath", "WEB-INF"));
final String moduleName = getInitParam(config, "module", "jackconfig.js");
final String appName = getInitParam(config, "app", "app");
+ final String environmentName = getInitParam(config, "environment", null);
final String narwhalHome = getServletContext().getRealPath("WEB-INF/narwhal");
final String narwhalFilename = "platforms/rhino/bootstrap.js";
@@ -38,7 +39,19 @@ public void init(ServletConfig config) throws ServletException {
handler = (Function)context.evaluateString(scope, "require('jack/handler/servlet').Servlet.process;", null, 1, null);
// load the app
- app = (Function)context.evaluateString(scope, "require('"+modulesPath+"/"+moduleName+"')['"+appName+"'];", null, 1, null);
+ Scriptable module = (Scriptable)context.evaluateString(scope, "require('"+modulesPath+"/"+moduleName+"');", null, 1, null);
+
+ app = (Function)module.get(appName, module);
+
+ if (environmentName != null) {
+ Object environment = module.get(environmentName, module);
+ if (environment instanceof Function) {
+ Object args[] = {app};
+ app = (Function)((Function)environment).call(context, scope, module, args);
+ } else {
+ System.err.println("Warning: environment named \"" + environmentName + "\" not found or not a function.");
+ }
+ }
} catch (IOException e) {
e.printStackTrace();
View
BIN war/WEB-INF/classes/org/jackjs/JackServlet.class
Binary file not shown.

0 comments on commit acdab2b

Please sign in to comment.
Something went wrong with that request. Please try again.