diff --git a/src/helma/framework/core/RequestPath.java b/src/helma/framework/core/RequestPath.java index 65cff8e1..86279422 100644 --- a/src/helma/framework/core/RequestPath.java +++ b/src/helma/framework/core/RequestPath.java @@ -131,5 +131,15 @@ public class RequestPath { return buffer.toString(); } + + /** + * Checks if the given object is contained in the request path + * + * @param obj the element to check + * @return the index of the element, or -1 if it isn't contained + */ + public int contains(Object obj) { + return objects.indexOf(obj); + } } \ No newline at end of file diff --git a/src/helma/scripting/rhino/PathWrapper.java b/src/helma/scripting/rhino/PathWrapper.java index 70aea325..78813920 100644 --- a/src/helma/scripting/rhino/PathWrapper.java +++ b/src/helma/scripting/rhino/PathWrapper.java @@ -43,7 +43,8 @@ public class PathWrapper extends ScriptableObject { setParentScope(core.getScope()); setPrototype(null); defineProperty("length", PathWrapper.class, attributes); - defineFunctionProperties(new String[] {"href"}, PathWrapper.class, attributes); + defineFunctionProperties(new String[] {"href", "contains"}, + PathWrapper.class, attributes); } /** @@ -125,6 +126,18 @@ public class PathWrapper extends ScriptableObject { return path.href(null); } + + /** + * Checks if the given object is contained in the request path + * + * @param obj the element to check + * @return the index of the element, or -1 if it isn't contained + */ + public int contains(Object obj) { + if (obj instanceof Wrapper) + obj = ((Wrapper) obj).unwrap(); + return path.contains(obj); + } public String getClassName() { return "[PathWrapper]";