dmitri 2004/04/04 16:16:24 Modified: jxpath/src/java/org/apache/commons/jxpath PackageFunctions.java JXPathContext.java jxpath/src/java/org/apache/commons/jxpath/ri JXPathContextReferenceImpl.java jxpath/src/test/org/apache/commons/jxpath/ri/compiler ExtensionFunctionTest.java Log: setFunctions now completely overrides the default,
thus enabling a secure implementation of the Functions interface Revision Changes Path 1.14 +2 -2 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/PackageFunctions.java Index: PackageFunctions.java =================================================================== RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/PackageFunctions.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- PackageFunctions.java 25 Mar 2004 05:42:01 -0000 1.13 +++ PackageFunctions.java 4 Apr 2004 23:16:23 -0000 1.14 @@ -189,7 +189,7 @@ ex); } - if (methodName.endsWith("new")) { + if (methodName.equals("new")) { Constructor constructor = MethodLookupUtils.lookupConstructor(functionClass, parameters); if (constructor != null) { 1.24 +11 -2 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java Index: JXPathContext.java =================================================================== RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/JXPathContext.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- JXPathContext.java 1 Apr 2004 02:55:31 -0000 1.23 +++ JXPathContext.java 4 Apr 2004 23:16:23 -0000 1.24 @@ -389,6 +389,9 @@ private static JXPathContextFactory contextFactory; private static JXPathContext compilationContext; + + private static final PackageFunctions GENERIC_FUNCTIONS = + new PackageFunctions("", null); /** * Creates a new JXPathContext with the specified object as the root node. @@ -488,7 +491,13 @@ * Returns the set of functions installed on the context. */ public Functions getFunctions() { - return functions; + if (functions != null) { + return functions; + } + if (parentContext == null) { + return GENERIC_FUNCTIONS; + } + return null; } /** 1.43 +1 -8 jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java Index: JXPathContextReferenceImpl.java =================================================================== RCS file: /home/cvs/jakarta-commons/jxpath/src/java/org/apache/commons/jxpath/ri/JXPathContextReferenceImpl.java,v retrieving revision 1.42 retrieving revision 1.43 diff -u -r1.42 -r1.43 --- JXPathContextReferenceImpl.java 4 Apr 2004 22:06:36 -0000 1.42 +++ JXPathContextReferenceImpl.java 4 Apr 2004 23:16:23 -0000 1.43 @@ -32,7 +32,6 @@ import org.apache.commons.jxpath.Functions; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.JXPathException; -import org.apache.commons.jxpath.PackageFunctions; import org.apache.commons.jxpath.Pointer; import org.apache.commons.jxpath.Variables; import org.apache.commons.jxpath.ri.axes.InitialContext; @@ -66,8 +65,6 @@ private static final Compiler COMPILER = new TreeCompiler(); private static Map compiled = new HashMap(); - private static final PackageFunctions GENERIC_FUNCTIONS = - new PackageFunctions("", null); private static int cleanupCount = 0; private static Vector nodeFactories = new Vector(); @@ -644,10 +641,6 @@ } } funcCtx = funcCtx.getParentContext(); - } - func = GENERIC_FUNCTIONS.getFunction(namespace, name, parameters); - if (func != null) { - return func; } throw new JXPathException( "Undefined function: " + functionName.toString()); 1.16 +9 -2 jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java Index: ExtensionFunctionTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/jxpath/src/test/org/apache/commons/jxpath/ri/compiler/ExtensionFunctionTest.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- ExtensionFunctionTest.java 25 Mar 2004 05:42:01 -0000 1.15 +++ ExtensionFunctionTest.java 4 Apr 2004 23:16:24 -0000 1.16 @@ -20,6 +20,8 @@ import java.util.List; import java.util.Locale; +import junit.textui.TestRunner; + import org.apache.commons.jxpath.ClassFunctions; import org.apache.commons.jxpath.ExpressionContext; import org.apache.commons.jxpath.Function; @@ -44,6 +46,10 @@ private Functions functions; private JXPathContext context; + public static void main(String[] args) { + TestRunner.run(ExtensionFunctionTest.class); + } + /** * Construct a new instance of this test case. * @@ -67,6 +73,7 @@ new PackageFunctions( "org.apache.commons.jxpath.ri.compiler.", "jxpathtest")); + lib.addFunctions(new PackageFunctions("", null)); context.setFunctions(lib); } functions = new ClassFunctions(TestFunctions.class, "test"); @@ -146,7 +153,7 @@ } public void testAllocation() { - + // Allocate new object using the default constructor assertXPathValue(context, "string(test:new())", "foo=0; bar=null"); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]