jvanzyl     00/11/15 17:57:28

  Modified:    src/java/org/apache/velocity/runtime/directive Parse.java
  Log:
  - made the parse directive work with the new loader mechanism. now
    template that are to be parsed may come from any source. the template
    to be #parsed will be searched for in all the sources. so that a template
    that is loaded from disc can #parse a template that is pulled a database,
    and that template can #parse a template that is pulled from your toaster!
    :-)
  
  Revision  Changes    Path
  1.2       +26 -34    
jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Parse.java
  
  Index: Parse.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/directive/Parse.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Parse.java        2000/11/12 06:39:50     1.1
  +++ Parse.java        2000/11/16 01:57:28     1.2
  @@ -58,6 +58,7 @@
   
   import org.apache.velocity.runtime.parser.*;
   import org.apache.velocity.Context;
  +import org.apache.velocity.Template;
   import org.apache.velocity.runtime.Runtime;
   import org.apache.velocity.runtime.parser.node.Node;
   import org.apache.velocity.runtime.parser.node.SimpleNode;
  @@ -80,7 +81,8 @@
    *    safety in the event that the parameter isn't set.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Geir Magnusson Jr.</a>
  - * @version $Id: Parse.java,v 1.1 2000/11/12 06:39:50 geirm Exp $
  + * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  + * @version $Id: Parse.java,v 1.2 2000/11/16 01:57:28 jvanzyl Exp $
    */
   public class Parse extends Directive
   {
  @@ -142,7 +144,7 @@
            *  everything must be under the template root TEMPLATE_PATH
            */
           
  -        String strTemplatePath = Runtime.getString(Runtime.TEMPLATE_PATH);
  +        //String strTemplatePath = Runtime.getString(Runtime.TEMPLATE_PATH);
           
           /*
            *  for security, we will not accept anything with .. in the path
  @@ -165,40 +167,30 @@
            *  we will put caching here in the future...
            */
   
  -        File file = new File(strTemplatePath, strArg);
  -                
  -        try {
  -            BufferedInputStream inStream = new BufferedInputStream( new 
FileInputStream( file ));
  -            
  -            /*
  -             *  parse the stream.  This will create other parse directive nodes, 
but not #parse down...
  -             */
  -
  -            nodeTree_ = Runtime.parse( inStream );
  -
  -            /*
  -             *  Now visit all and set the parse depth.  Then init().  That will 
parse down
  -             */
  -
  -            ParseDirectiveVisitor v = new ParseDirectiveVisitor();
  -            v.setDepth( iParseDepth_ );
  -            v.setContext( null );
  -            v.setWriter( null );
  -            nodeTree_.jjtAccept( v, null );
  -            nodeTree_.init( context, null );   
  -         
  -        } 
  -        catch ( FileNotFoundException e ) 
  -        {
  -            Runtime.error( new String("#parse() : " + e ));
  -            throw e;
  -        }
  -        catch ( ParseDirectiveException pde )
  +        Template t = Runtime.getTemplate(strArg);
  +        
  +        if (t != null)
           {
  -            pde.addFile( strArg );
  -            throw pde;
  +            try
  +            {
  +                nodeTree_ = t.getDocument();
  +
  +                ParseDirectiveVisitor v = new ParseDirectiveVisitor();
  +                v.setDepth( iParseDepth_ );
  +                v.setContext( null );
  +                v.setWriter( null );
  +                nodeTree_.jjtAccept( v, null );
  +                nodeTree_.init( context, null );
  +            }
  +            catch ( ParseDirectiveException pde )
  +            {
  +                pde.addFile( strArg );
  +                throw pde;
  +            }
           }
  -      
  +        else
  +            throw new Exception("#parse : cannot find " + strArg + " template!");
  +
           bReady_ = true;
       }
   
  
  
  

Reply via email to