r9619 - helma-ng/trunk/src/org/helma/jack
[email protected] Tue, 14 Apr 2009 01:50:19 +0200 (CEST)
| Newsgroups | gmane.comp.java.helma.cvs |
|---|---|
| Message-ID | <20090413235019.63BA43D0D6@mia> |
Author: hannes
Date: 2009-04-14 01:50:19 +0200 (Tue, 14 Apr 2009)
New Revision: 9619
Modified:
helma-ng/trunk/src/org/helma/jack/JackEnv.java
helma-ng/trunk/src/org/helma/jack/JackServlet.java
Log:
Fixes and enhancements in Jack servlet.
- Make sure env properties do not contain null
- Add JackServlet constructor that takes a RhinoEngine argument
Details at http://dev.helma.org/trac/helma/changeset/9619
Modified: helma-ng/trunk/src/org/helma/jack/JackEnv.java
===================================================================
--- helma-ng/trunk/src/org/helma/jack/JackEnv.java 2009-04-13 20:26:17 UTC (rev 9618)
+++ helma-ng/trunk/src/org/helma/jack/JackEnv.java 2009-04-13 23:50:19 UTC (rev 9619)
@@ -47,35 +47,35 @@
public String getScriptName() {
- return req.getServletPath();
+ return checkString(req.getServletPath());
}
public String getPathInfo() {
- return req.getPathInfo();
+ return checkString(req.getPathInfo());
}
public String getRequestMethod() {
- return req.getMethod();
+ return checkString(req.getMethod());
}
public String getServerName() {
- return req.getServerName();
+ return checkString(req.getServerName());
}
public String getServerPort() {
- return Integer.toString(req.getServerPort());
+ return checkString(Integer.toString(req.getServerPort()));
}
public String getQueryString() {
- return req.getQueryString();
+ return checkString(req.getQueryString());
}
public String getHttpVersion() {
- return req.getProtocol();
+ return checkString(req.getProtocol());
}
public String getRemoteHost() {
- return req.getRemoteHost();
+ return checkString(req.getRemoteHost());
}
public String getUrlScheme() {
@@ -121,6 +121,10 @@
return JackEnv.class.getDeclaredMethod(name);
}
+ private static String checkString(String str) {
+ return str == null ? "" : str;
+ }
+
@Override
public Object get(String name, Scriptable start) {
// FIXME: implement IO wrappers
Modified: helma-ng/trunk/src/org/helma/jack/JackServlet.java
===================================================================
--- helma-ng/trunk/src/org/helma/jack/JackServlet.java 2009-04-13 20:26:17 UTC (rev 9618)
+++ helma-ng/trunk/src/org/helma/jack/JackServlet.java 2009-04-13 23:50:19 UTC (rev 9619)
@@ -35,25 +35,37 @@
String module, function;
RhinoEngine engine;
+ public JackServlet(RhinoEngine engine) throws ServletException {
+ this.engine = engine;
+ try {
+ engine.defineHostClass(JackEnv.class);
+ } catch (Exception x) {
+ throw new ServletException(x);
+ }
+ }
+
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
module = getInitParam(config, "module", "app");
function = getInitParam(config, "function", "handler");
- String helmaHome = getInitParam(config, "home", "WEB-INF");
- String modulePath = getInitParam(config, "modulePath", "modules");
- Repository home = new WebappRepository(config.getServletContext(), helmaHome);
- if (!home.exists()) {
- home = new FileRepository(helmaHome);
+ if (engine == null) {
+ String helmaHome = getInitParam(config, "home", "WEB-INF");
+ String modulePath = getInitParam(config, "modulePath", "modules");
+
+ Repository home = new WebappRepository(config.getServletContext(), helmaHome);
+ if (!home.exists()) {
+ home = new FileRepository(helmaHome);
+ }
+ try {
+ HelmaConfiguration helmaConfig = new HelmaConfiguration(home, modulePath, "modules");
+ helmaConfig.setHostClasses(new Class[] { JackEnv.class });
+ engine = new RhinoEngine(helmaConfig, null);
+ } catch (FileNotFoundException x) {
+ throw new ServletException(x);
+ }
}
- try {
- HelmaConfiguration helmaConfig = new HelmaConfiguration(home, modulePath, "modules");
- helmaConfig.setHostClasses(new Class[] { JackEnv.class });
- engine = new RhinoEngine(helmaConfig, null);
- } catch (FileNotFoundException x) {
- throw new ServletException(x);
- }
}
@Override