ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-ant/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional JXPath.java JXPathSet.java JexlProperties.java VelocityProperties.java
Date Sun, 29 Dec 2002 05:57:38 GMT
costin      2002/12/28 21:57:38

  Modified:    proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional
                        JXPath.java JXPathSet.java JexlProperties.java
                        VelocityProperties.java
  Log:
  Update to the new hook.
  
  It seems to work now :-)
  
  Revision  Changes    Path
  1.8       +19 -33    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JXPath.java	28 Dec 2002 23:01:56 -0000	1.7
  +++ JXPath.java	29 Dec 2002 05:57:38 -0000	1.8
  @@ -66,7 +66,7 @@
   // Experimental: need to add code to select the 'root', etc.
   
   /**
  - *  Enable JXPath dynamic properties
  + *  Enable JXPath dynamic properties.
    *
    * @author Costin Manolache
    * @author Nicola Ken Barozzi
  @@ -74,35 +74,24 @@
   public class JXPath extends Task {
   
       public static String PREFIX="jxpath:";
  -    JXPathContext jxpathCtx;
  +    JXPathPropertyHelper helper=new JXPathPropertyHelper();
   
       public JXPath() {
       }
   
       public JXPathContext getJXPathContext() {
  -        return jxpathCtx;
  -    }
  -
  -    // testing
  -    String foo;
  -    public void setFoo( String s ) {
  -        System.out.println("Set foo " + s );
  -        foo=s;
  -    }
  -
  -    public String getFoo() {
  -        return foo;
  +        return helper.jxpathCtx;
       }
   
       public void execute() {
           JXPathIntrospector.registerDynamicClass(Hashtable.class, JXPathHashtableHandler.class);
  -        jxpathCtx=JXPathContext.newContext( project );
  -        jxpathCtx.setVariables(new AntVariables());
  +        helper.jxpathCtx=JXPathContext.newContext( project );
  +        helper.jxpathCtx.setVariables(new AntVariables());
   
           PropertyHelper phelper=PropertyHelper.getPropertyHelper( project );
  -        JXPathPropertyHelper hook=new JXPathPropertyHelper(jxpathCtx);
  -        hook.setNext( phelper.getNext() );
  -        phelper.setNext( hook );
  +        helper.setProject( project );
  +        helper.setNext( phelper.getNext() );
  +        phelper.setNext( helper );
   
           project.addReference( "jxpathTask", this );
   
  @@ -112,15 +101,13 @@
       static class JXPathPropertyHelper extends PropertyHelper {
           JXPathContext jxpathCtx;
   
  -        public JXPathPropertyHelper( JXPathContext jxCtx ) {
  -            this.jxpathCtx=jxCtx;
  -        }
  -
  -        public boolean setProperty( String ns, String name, Object v, boolean inh,
  -                                    boolean user, boolean isNew)
  +        public boolean setPropertyHook( String ns, String name, Object v, boolean inh,
  +                                        boolean user, boolean isNew)
           {
  -            if( ! name.startsWith(PREFIX) )
  -                return false;
  +            if( ! name.startsWith(PREFIX) ) {
  +                // pass to next
  +                return super.setPropertyHook(ns, name, v, inh, user, isNew);
  +            }
               name=name.substring( PREFIX.length() );
   
               jxpathCtx.setValue( name, v );
  @@ -128,10 +115,12 @@
           }
   
           public Object getPropertyHook( String ns, String name , boolean user) {
  -            if( ! name.startsWith(PREFIX) )
  -                return null;
  -            name=name.substring( PREFIX.length() );
  +            if( ! name.startsWith(PREFIX) ) {
  +                // pass to next
  +                return super.getPropertyHook(ns, name, user);
  +            }
   
  +            name=name.substring( PREFIX.length() );
   
               //Object o=jxpathCtx.getValue( name );
               //System.out.println("JXPath: getProperty " + ns + " " + name + "=" + o + o.getClass());
  @@ -148,14 +137,11 @@
   
               while (iter.hasNext()) {
                   Object o = iter.next();
  -                //System.out.println("JXPath: getProperty " + ns + " " + name + "=" + o
+ o.getClass());
                   result += ", "+o;
               }
   
               return result;
           }
  -
  -
       }
   
   
  
  
  
  1.3       +1 -0      jakarta-ant/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/JXPathSet.java
  
  Index: JXPathSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/JXPathSet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JXPathSet.java	11 Oct 2002 18:07:08 -0000	1.2
  +++ JXPathSet.java	29 Dec 2002 05:57:38 -0000	1.3
  @@ -67,6 +67,7 @@
    *  Set a JXPath property
    *  
    *
  + * @deprecated A generic <property> should be used.
    * @author Costin Manolache
    */
   public class JXPathSet extends Task {
  
  
  
  1.4       +30 -25    jakarta-ant/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/JexlProperties.java
  
  Index: JexlProperties.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/JexlProperties.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JexlProperties.java	28 Dec 2002 05:33:21 -0000	1.3
  +++ JexlProperties.java	29 Dec 2002 05:57:38 -0000	1.4
  @@ -55,6 +55,7 @@
   package org.apache.tools.ant.taskdefs.optional;
   
   import org.apache.tools.ant.*;
  +import org.apache.tools.ant.PropertyHelper;
   import org.apache.tools.ant.types.*;
   import java.io.*;
   import java.util.*;
  @@ -67,43 +68,47 @@
    *
    * @author Costin Manolache
    */
  -public class JexlProperties extends Task implements PropertyInterceptor {
  -    JexlContext jc;
  +public class JexlProperties extends Task {
       public static String PREFIX="jexl:";
  -    
  +    JexlPropertyHelper helper=new JexlPropertyHelper();
  +
       public JexlProperties() {
       }
  -    
  -    public boolean setProperty( Object ctx, String ns, String name, Object value ) {
  -        return false;
  -    }
   
  -    public Object getProperty( Object p, String ns, String name ) {
  -        if( ! name.startsWith(PREFIX) )
  -            return null;
  -        try {
  -            name=name.substring( PREFIX.length() );
  -            Expression e = ExpressionFactory.createExpression(name);
  -            Object o = e.evaluate(jc);
  -
  -            return o;
  -        } catch( Exception ex ) {
  -            ex.printStackTrace();
  -            return null;
  +    static class JexlPropertyHelper extends PropertyHelper {
  +        JexlContext jc;
  +
  +        public Object getPropertyHook( String ns, String name, boolean user ) {
  +            if( ! name.startsWith(PREFIX) ) {
  +                return super.getPropertyHook(ns, name, user);
  +            }
  +            try {
  +                name=name.substring( PREFIX.length() );
  +                Expression e = ExpressionFactory.createExpression(name);
  +                Object o = e.evaluate(jc);
  +
  +                return o;
  +            } catch( Exception ex ) {
  +                ex.printStackTrace();
  +                return null;
  +            }
           }
       }
       
  -    
       public void execute() {
  -        PropertyHelper2 phelper=PropertyHelper2.getPropertyHelper( project );
  -        phelper.addPropertyInterceptor( this );
  -
           /*
            *  First make a jexlContext and put stuff in it
            */
  -        jc = JexlHelper.createContext();
  +        helper.jc = JexlHelper.createContext();
  +        helper.jc.getVars().put("ant", project);
  +
  +        // register it
  +        PropertyHelper phelper=PropertyHelper.getPropertyHelper( project );
  +        helper.setNext( phelper.getNext() );
  +        helper.setProject( project );
  +        phelper.setNext( helper );
  +
   
  -        jc.getVars().put("ant", project);
   
       }    
   }
  
  
  
  1.4       +38 -30    jakarta-ant/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/VelocityProperties.java
  
  Index: VelocityProperties.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/embed/src/java/org/apache/tools/ant/taskdefs/optional/VelocityProperties.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- VelocityProperties.java	28 Dec 2002 05:33:21 -0000	1.3
  +++ VelocityProperties.java	29 Dec 2002 05:57:38 -0000	1.4
  @@ -55,6 +55,7 @@
   package org.apache.tools.ant.taskdefs.optional;
   
   import org.apache.tools.ant.*;
  +import org.apache.tools.ant.PropertyHelper;
   import org.apache.tools.ant.types.*;
   import java.io.*;
   import java.util.*;
  @@ -69,49 +70,56 @@
    *
    * @author Costin Manolache
    */
  -public class VelocityProperties extends Task implements PropertyInterceptor {
  -    VelocityEngine engine;
  -    VelocityContext context;
  +public class VelocityProperties extends Task {
       public static final String PREFIX="vm:";
  -    
  +    VelocityPropertyHelper helper=new VelocityPropertyHelper();
  +
       public VelocityProperties() {
       }
   
  -    public boolean setProperty( Object c, String ns, String name, Object v ) {
  -        return false;
  -    }
  -    
  -    public Object getProperty( Object p, String ns, String name ) {
  -        if( ! name.startsWith(PREFIX) )
  -            return null;
  -        try {
  -            name=name.substring( PREFIX.length() );
  -            StringWriter sw=new StringWriter();
  -            
  -            engine.evaluate( context, sw, "antVM", name );
  -            
  -            System.out.println("VM: getProperty " + ns + " " + name + "=" + sw.toString());
  -            return sw.toString();
  -        } catch( Exception ex ) {
  -            ex.printStackTrace();
  -            return null;
  +    static class VelocityPropertyHelper extends PropertyHelper {
  +        VelocityEngine engine;
  +        VelocityContext context;
  +
  +        public Object getPropertyHook( String ns, String name, boolean user ) {
  +            if( ! name.startsWith(PREFIX) ) {
  +                // pass on to next
  +                return super.getPropertyHook(ns, name, user);
  +            }
  +            try {
  +                name=name.substring( PREFIX.length() );
  +                StringWriter sw=new StringWriter();
  +
  +                engine.evaluate( context, sw, "antVM", name );
  +
  +                System.out.println("VM: getProperty " + ns + " " + name + "=" + sw.toString());
  +                return sw.toString();
  +            } catch( Exception ex ) {
  +                ex.printStackTrace();
  +                return null;
  +            }
           }
       }
   
       public VelocityEngine getVelocityEngine() {
  -        return engine;
  +        return helper.engine;
       }
       
       public void execute() {
           try {
  -            PropertyHelper2 phelper=PropertyHelper2.getPropertyHelper( project );
  -            phelper.addPropertyInterceptor( this );
  -
  -            engine=new VelocityEngine();
  -            engine.init();
  +            // Prepare the engine
  +            helper.engine=new VelocityEngine();
  +            helper.engine.init();
               
  -            context=new VelocityContext();
  -            context.put( "ant", project );
  +            helper.context=new VelocityContext();
  +            helper.context.put( "ant", project );
  +
  +            // Register it
  +            PropertyHelper phelper=PropertyHelper.getPropertyHelper( project );
  +            helper.setNext( phelper.getNext() );
  +            helper.setProject( project );
  +            phelper.setNext( helper );
  +
           } catch( Exception ex ) {
               ex.printStackTrace();
           }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message