From fc0edbb26994bd590ef14abe367f9ad1e61cda29 Mon Sep 17 00:00:00 2001 From: hns Date: Fri, 23 Dec 2005 16:04:14 +0000 Subject: [PATCH] * Implement HopObject.getResources() - returns a JS array containing all resources with the given name defined in the prototype chain. --- src/helma/scripting/rhino/HopObject.java | 27 +++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/helma/scripting/rhino/HopObject.java b/src/helma/scripting/rhino/HopObject.java index 086d2a4e..a75987de 100644 --- a/src/helma/scripting/rhino/HopObject.java +++ b/src/helma/scripting/rhino/HopObject.java @@ -297,7 +297,7 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco public Object jsFunction_getResource(String resourceName) { Context cx = Context.getCurrentContext(); RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine"); - Prototype prototype = engine.core.app.getPrototypeByName(this.node.getPrototype()); + Prototype prototype = engine.core.app.getPrototypeByName(className); while (prototype != null) { Resource[] resources = prototype.getResources(); for (int i = resources.length - 1; i >= 0; i--) { @@ -310,6 +310,31 @@ public class HopObject extends ScriptableObject implements Wrapper, PropertyReco 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 jsFunction_getResources(String resourceName) { + Context cx = Context.getCurrentContext(); + RhinoEngine engine = (RhinoEngine) cx.getThreadLocal("engine"); + Prototype prototype = engine.core.app.getPrototypeByName(className); + 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()); + } + /** * Render a skin and return its output as string. *