From 2d2fd6a3f6814202a311d90d8ba6a5c9a947b3f3 Mon Sep 17 00:00:00 2001 From: Costin Manolache Date: Fri, 30 Aug 2002 23:27:36 +0000 Subject: [PATCH] Patch from Nicola. It adds support for multiple values. ( I am not sure if this is the right place - I would try to return a vector/enumeration/[] - and then have a generic solution that would turn this into a string. Until I find a better solution I'll leave the code unchanged ) Bug 11789 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273269 13f79535-47bb-0310-9956-ffa450edef68 --- .../tools/ant/taskdefs/optional/JXPath.java | 52 +++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/JXPath.java b/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/JXPath.java index ef70ae5d8..1ece4a273 100644 --- a/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/JXPath.java +++ b/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/JXPath.java @@ -66,9 +66,9 @@ import org.apache.commons.jxpath.*; /** * Enable JXPath dynamic properties - * * * @author Costin Manolache + * @author Nicola Ken Barozzi */ public class JXPath extends Task implements PropertyInterceptor { @@ -82,9 +82,28 @@ public class JXPath extends Task implements PropertyInterceptor { if( ! name.startsWith(PREFIX) ) return null; name=name.substring( PREFIX.length() ); - Object o=jxpathCtx.getValue( name ); - if( o==null ) return "null"; - return o; + + + //Object o=jxpathCtx.getValue( name ); + //System.out.println("JXPath: getProperty " + ns + " " + name + "=" + o + o.getClass()); + + String result = ""; + + Iterator iter = jxpathCtx.iterate(name); + + if(iter==null){ + return "null"; + } + + result += iter.next(); + + while (iter.hasNext()) { + Object o = iter.next(); + //System.out.println("JXPath: getProperty " + ns + " " + name + "=" + o + o.getClass()); + result += ", "+o; + } + + return result; } @@ -95,6 +114,8 @@ public class JXPath extends Task implements PropertyInterceptor { phelper.addPropertyInterceptor( this ); jxpathCtx=JXPathContext.newContext( project ); + + jxpathCtx.setVariables(new AntVariables()); } public static class JXPathHashtableHandler implements DynamicPropertyHandler { @@ -131,4 +152,27 @@ public class JXPath extends Task implements PropertyInterceptor { } } + public class AntVariables implements Variables { + + protected AntVariables(){ + } + + public void declareVariable(String varName, Object value){ + project.setNewProperty(varName, value.toString()); + } + + public Object getVariable(String varName){ + return project.getProperty(varName); + } + + public boolean isDeclaredVariable(String varName){ + return project.getProperty(varName) == null ? false : true ; + } + + public void undeclareVariable(String varName){ + throw new UnsupportedOperationException("Cannot undeclare variables in Ant."); + } + + } + }