Browse Source

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
master
Costin Manolache 23 years ago
parent
commit
2d2fd6a3f6
1 changed files with 48 additions and 4 deletions
  1. +48
    -4
      proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/JXPath.java

+ 48
- 4
proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/JXPath.java View File

@@ -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.");
}
}
}

Loading…
Cancel
Save