You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by co...@apache.org on 2002/08/31 01:27:36 UTC

cvs commit: jakarta-ant/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional JXPath.java

costin      2002/08/30 16:27:36

  Modified:    proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional
                        JXPath.java
  Log:
  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
  
  Revision  Changes    Path
  1.3       +48 -4     jakarta-ant/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/JXPath.java
  
  Index: JXPath.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/JXPath.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JXPath.java	30 Aug 2002 23:11:02 -0000	1.2
  +++ JXPath.java	30 Aug 2002 23:27:36 -0000	1.3
  @@ -66,9 +66,9 @@
   
   /**
    *  Enable JXPath dynamic properties
  - *  
    *
    * @author Costin Manolache
  + * @author Nicola Ken Barozzi
    */
   public class JXPath extends Task implements PropertyInterceptor {
   
  @@ -82,9 +82,28 @@
           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 @@
           phelper.addPropertyInterceptor( this );
           
           jxpathCtx=JXPathContext.newContext( project );
  +        
  +        jxpathCtx.setVariables(new AntVariables());
       }
   
       public static class JXPathHashtableHandler implements DynamicPropertyHandler {
  @@ -129,6 +150,29 @@
           public void setProperty(Object object, String propertyName, Object value){
               ((Hashtable)object).put(propertyName, value);
           }
  +    }
  +    
  +    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.");
  +         }
  +    
       }
       
   }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>