geirm       01/01/13 08:50:00

  Modified:    src/java/org/apache/velocity/runtime VelocimacroFactory.java
                        VelocimacroManager.java
  Log:
  Small fixes to support the changes for the new VMs.  Changes should be
  only related to removing things no longer needed.
  
  Revision  Changes    Path
  1.8       +6 -11     
jakarta-velocity/src/java/org/apache/velocity/runtime/VelocimacroFactory.java
  
  Index: VelocimacroFactory.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/VelocimacroFactory.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- VelocimacroFactory.java   2000/12/20 05:59:31     1.7
  +++ VelocimacroFactory.java   2001/01/13 16:49:59     1.8
  @@ -54,11 +54,10 @@
    * <http://www.apache.org/>.
    */
   
  -import java.util.TreeMap;
  -
   import org.apache.velocity.Template;
   import org.apache.velocity.runtime.directive.Directive;
   import org.apache.velocity.runtime.directive.VelocimacroProxy;
  +import org.apache.velocity.runtime.parser.node.SimpleNode;
   
   /**
    *  VelocimacroFactory.java
  @@ -66,7 +65,7 @@
    *   manages the set of VMs in a running Velocity engine.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  - * @version $Id: VelocimacroFactory.java,v 1.7 2000/12/20 05:59:31 jvanzyl Exp $ 
  + * @version $Id: VelocimacroFactory.java,v 1.8 2001/01/13 16:49:59 geirm Exp $ 
    *
    */
   public class VelocimacroFactory
  @@ -247,9 +246,7 @@
       /**
        *  adds a macro to the factory. 
        */
  -    public boolean addVelocimacro( String name, String macroBody, 
  -                                   String argArray[], String macroArray[],
  -                                   TreeMap argIndexMap, String sourceTemplate )
  +    public boolean addVelocimacro( String name, String macroBody,  String 
argArray[], String sourceTemplate )
       {
           /*
            * maybe we should throw an exception, maybe just tell 
  @@ -258,8 +255,7 @@
            * I hate this : maybe exceptions are in order here...
            */
           
  -        if (       name == null ||   macroBody == null || argArray == null || 
  -             macroArray == null || argIndexMap == null )
  +        if ( name == null ||   macroBody == null || argArray == null || 
sourceTemplate == null )
           {
               logVMMessage("Velocimacro : VM addition rejected : " +
                   "programmer error : arg null"  );
  @@ -310,8 +306,7 @@
   
           synchronized( this ) 
           {
  -            vmManager.addVM( name, macroBody, argArray, macroArray, 
  -                argIndexMap, sourceTemplate );
  +            vmManager.addVM( name, macroBody, argArray, sourceTemplate );
           }
   
           /*
  @@ -345,7 +340,7 @@
           if (blather)
               Runtime.info( s );
       }
  -
  +      
       /**
        *  Tells the world if a given directive string is a Velocimacro
        */
  
  
  
  1.7       +48 -17    
jakarta-velocity/src/java/org/apache/velocity/runtime/VelocimacroManager.java
  
  Index: VelocimacroManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/VelocimacroManager.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- VelocimacroManager.java   2000/12/20 06:10:46     1.6
  +++ VelocimacroManager.java   2001/01/13 16:49:59     1.7
  @@ -56,11 +56,17 @@
   
   import java.util.Hashtable;
   import java.util.TreeMap;
  +import java.io.ByteArrayInputStream;
   
   import org.apache.velocity.Template;
   import org.apache.velocity.runtime.directive.Directive;
   import org.apache.velocity.runtime.directive.VelocimacroProxy;
  +import org.apache.velocity.runtime.parser.node.SimpleNode;
  +import org.apache.velocity.util.StringUtils;
  +import org.apache.velocity.runtime.Runtime;
   
  +import org.apache.velocity.context.InternalContextAdapter;
  +
   /**
    *  VelocimacroManager.java
    *
  @@ -76,7 +82,7 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Jose Alberto Fernandez</a>
  - * @version $Id: VelocimacroManager.java,v 1.6 2000/12/20 06:10:46 jvanzyl Exp $ 
  + * @version $Id: VelocimacroManager.java,v 1.7 2001/01/13 16:49:59 geirm Exp $ 
    */
   public class VelocimacroManager
   {
  @@ -108,12 +114,10 @@
        *  adds a VM definition to the cache
        * @return boolean if all went ok
        */
  -    public boolean addVM(String vmName, String macroBody, String argArray[],
  -                         String macroArray[], TreeMap argIndexMap, 
  -                         String namespace )
  +    public boolean addVM(String vmName, String macroBody, String argArray[], String 
namespace )
       {
  -        MacroEntry me = new MacroEntry( vmName,  macroBody,  argArray, macroArray, 
  -            argIndexMap, namespace );
  +
  +        MacroEntry me = new MacroEntry( this, vmName,  macroBody,  argArray,  
namespace );
   
           if ( usingNamespaces( namespace ) )
           {
  @@ -124,7 +128,7 @@
   
               Hashtable local = getNamespace( namespace, true );
               local.put( (String) vmName, me );
  -            
  +         
               return true;
           }
           else
  @@ -312,33 +316,60 @@
       {
           String macroname;
           String[] argarray;
  -        String[] macroarray;
  -        TreeMap indexmap;
           String macrobody;
           String sourcetemplate;
  +        SimpleNode nodeTree = null;
  +        VelocimacroManager manager = null;
   
  -        MacroEntry(String vmName, String macroBody, String argArray[], 
  -              String macroArray[], TreeMap argIndexMap, 
  -              String sourceTemplate)
  +        MacroEntry(VelocimacroManager vmm, String vmName, String macroBody, String 
argArray[],  String sourceTemplate)
           {
               this.macroname = vmName;
               this.argarray = argArray;
  -            this.macroarray = macroArray;
  -            this.indexmap = argIndexMap;
               this.macrobody = macroBody;
               this.sourcetemplate = sourceTemplate;
  +            this.manager = vmm;
           }
   
  +        public SimpleNode getNodeTree()
  +        {
  +            return nodeTree;
  +        }
  +
           VelocimacroProxy createVelocimacro()
           {
               VelocimacroProxy vp = new VelocimacroProxy();
               vp.setName( this.macroname );
               vp.setArgArray(  this.argarray ); 
  -            vp.setMacroArray( this.macroarray );
  -            vp.setArgIndexMap( this.indexmap );
               vp.setMacrobody( this.macrobody );
  -            
  +            vp.setNodeTree( this.nodeTree);
  +
               return vp;
  +        }
  +
  +        void setup( InternalContextAdapter ica)
  +        {
  +            /*
  +             *  if not parsed yet, parse!
  +             */
  +            
  +            if( nodeTree == null)
  +                parseTree( ica );
  +        }
  +
  +        void parseTree( InternalContextAdapter ica)
  +        {
  +            try 
  +            {
  +
  +                ByteArrayInputStream  inStream = new ByteArrayInputStream( 
macrobody.getBytes() );
  +                nodeTree = Runtime.parse( inStream, "VM:" + macroname );
  +                nodeTree.init(ica,null);
  +            } 
  +            catch ( Exception e ) 
  +            {
  +                Runtime.error("VelocimacroManager.parseTree() : exception " + 
macroname + 
  +                              " : "  + StringUtils.stackTrace(e));
  +            }
           }
       }
   }
  
  
  

Reply via email to