From 6a96d0c7a0cfd1afaad6cd600710ed656233f0e1 Mon Sep 17 00:00:00 2001 From: hns Date: Mon, 19 Jun 2006 13:56:57 +0000 Subject: [PATCH] * Implement getResource() and getResources() for scripted java objects. --- src/helma/scripting/rhino/JavaObject.java | 54 ++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/helma/scripting/rhino/JavaObject.java b/src/helma/scripting/rhino/JavaObject.java index de7f3078..8cfd4933 100644 --- a/src/helma/scripting/rhino/JavaObject.java +++ b/src/helma/scripting/rhino/JavaObject.java @@ -18,10 +18,12 @@ package helma.scripting.rhino; import helma.framework.core.*; import helma.framework.ResponseTrans; +import helma.framework.repository.Resource; import org.mozilla.javascript.*; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; +import java.util.ArrayList; import java.io.UnsupportedEncodingException; import java.io.IOException; @@ -42,7 +44,9 @@ public class JavaObject extends NativeJavaObject { for (int i=0; i= 0; i--) { + Resource resource = resources[i]; + if (resource.exists() && resource.getShortName().equals(resourceName)) + return Context.toObject(resource, core.global); + } + prototype = prototype.getParentPrototype(); + } + return null; + } + + + /** + * Returns an array containing the prototype's resource with a given name. + * + * @param resourceName the name of the resource, e.g. "type.properties", + * "messages.properties", "script.js", etc. + * @return an array of resources with the given name + */ + public Object getResources(String resourceName) { + Context cx = Context.getCurrentContext(); + RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine"); + Prototype prototype = engine.core.app.getPrototypeByName(protoName); + ArrayList a = new ArrayList(); + while (prototype != null) { + Resource[] resources = prototype.getResources(); + for (int i = resources.length - 1; i >= 0; i--) { + Resource resource = resources[i]; + if (resource.exists() && resource.getShortName().equals(resourceName)) + a.add(Context.toObject(resource, core.global)); + } + prototype = prototype.getParentPrototype(); + } + return Context.getCurrentContext().newArray(core.global, a.toArray()); + } }