diff --git a/src/helma/framework/core/Application.java b/src/helma/framework/core/Application.java index e6a8dce4..dd59e380 100644 --- a/src/helma/framework/core/Application.java +++ b/src/helma/framework/core/Application.java @@ -24,6 +24,7 @@ import helma.main.Server; import helma.objectmodel.*; import helma.objectmodel.db.*; import helma.util.*; +import helma.scripting.ScriptingEngine; import java.io.*; import java.lang.reflect.*; @@ -69,6 +70,9 @@ public final class Application implements Runnable { // otherwise this is managed by the NodeManager and not cached here. Object rootObject = null; String rootObjectClass; + // if defined this will cause us to get the root object straight + // from the scripting engine, circumventing all hopobject db fluff + String rootObjectPropertyName; // The session manager SessionManager sessionMgr; @@ -834,7 +838,7 @@ public final class Application implements Runnable { /** * This method returns the root object of this application's object tree. */ - public Object getDataRoot() { + public Object getDataRoot(ScriptingEngine scriptingEngine) { // check if we have a custom root object class if (rootObjectClass != null) { // create custom root element. @@ -861,9 +865,11 @@ public final class Application implements Runnable { } return rootObject; - } - // no custom root object is defined - use standard helma objectmodel - else { + } else if (rootObjectPropertyName != null) { + // get root object from a global scripting engine property + return scriptingEngine.getGlobalProperty(rootObjectPropertyName); + } else { + // no custom root object is defined - use standard helma objectmodel return nmgr.safe.getRootNode(); } } @@ -1167,7 +1173,7 @@ public final class Application implements Runnable { * Return the href to the root of this application. */ public String getRootHref() throws UnsupportedEncodingException { - return getNodeHref(getDataRoot(), null); + return getNodeHref(null, null); } /** @@ -1823,6 +1829,7 @@ public final class Application implements Runnable { } hrefRootPrototype = props.getProperty("hrefrootprototype"); + rootObjectPropertyName = props.getProperty("rootobjectpropertyname"); // update the XML-RPC access list, containting prototype.method // entries of functions that may be called via XML-RPC diff --git a/src/helma/framework/core/RequestEvaluator.java b/src/helma/framework/core/RequestEvaluator.java index bddf5c6f..5e725a8e 100644 --- a/src/helma/framework/core/RequestEvaluator.java +++ b/src/helma/framework/core/RequestEvaluator.java @@ -218,7 +218,7 @@ public final class RequestEvaluator implements Runnable { transactor = Transactor.getInstance(app.nmgr); transactor.begin(txname); - Object root = app.getDataRoot(); + Object root = app.getDataRoot(scriptingEngine); initGlobals(root, requestPath); String action = null; diff --git a/src/helma/scripting/ScriptingEngine.java b/src/helma/scripting/ScriptingEngine.java index 0895c127..20a9284f 100644 --- a/src/helma/scripting/ScriptingEngine.java +++ b/src/helma/scripting/ScriptingEngine.java @@ -116,11 +116,18 @@ public interface ScriptingEngine { */ public void abort(); + /** + * Get a global property + * @param propertyName the property name + * @return the property value, or null + */ + public Object getGlobalProperty(String propertyName); + /** * Get a property on an object * @param thisObject the object * @param propertyName the property name - * @return true the property value, or null + * @return the property value, or null */ public Object getProperty(Object thisObject, String propertyName); diff --git a/src/helma/scripting/rhino/RhinoEngine.java b/src/helma/scripting/rhino/RhinoEngine.java index 9bde274d..560cdee0 100644 --- a/src/helma/scripting/rhino/RhinoEngine.java +++ b/src/helma/scripting/rhino/RhinoEngine.java @@ -424,6 +424,34 @@ public class RhinoEngine implements ScriptingEngine { return wrapped.has(propname, wrapped); } + /** + * Get a property from the global object. + * @param propname the property name + * @return the property value if the property is defined, or null + */ + public Object getGlobalProperty(String propname) { + if (propname == null) { + return null; + } + try { + Object prop = core.global.get(propname, global); + if (prop == null + || prop == Undefined.instance + || prop == ScriptableObject.NOT_FOUND) { + return null; + } else if (prop instanceof Wrapper) { + return ((Wrapper) prop).unwrap(); + } else { + // Do not return functions as properties as this + // is a potential security problem + return (prop instanceof Function) ? null : prop; + } + } catch (Exception esx) { + app.logError("Error getting global property " + propname + ": " + esx); + return null; + } + } + /** * Check if an object has a defined property (public field if it * is a java object) with that name.