jvanzyl     00/11/15 17:50:43

  Modified:    src/java/org/apache/velocity/texen Generator.java
               src/java/org/apache/velocity/texen/ant TexenTask.java
  Log:
  - had to make a change to texen to make it compile while the changes
    are going on in the loading mechanism. texen doesn't work right
    now, so don't try to build torque with it! once this big round
    of commits are done and the review is done i will get texen working
    with the new loading mechanism.
  
  Revision  Changes    Path
  1.5       +19 -20    
jakarta-velocity/src/java/org/apache/velocity/texen/Generator.java
  
  Index: Generator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/texen/Generator.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Generator.java    2000/11/04 02:42:12     1.4
  +++ Generator.java    2000/11/16 01:50:42     1.5
  @@ -17,15 +17,15 @@
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Leon Messerschmidt</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @version $Id: Generator.java,v 1.4 2000/11/04 02:42:12 jvanzyl Exp $ 
  + * @version $Id: Generator.java,v 1.5 2000/11/16 01:50:42 jvanzyl Exp $ 
    */
   public class Generator
   {
  -    public static final String PATH_INPUT = "path.input";
  -    public static final String PATH_OUTPUT = "path.output";
  -    public static final String CONTEXT_STRINGS = "context.objects.strings";
  -    public static final String CONTEXT_FILES = "context.objects.files";
  +    public  static final String PATH_OUTPUT = "path.output";
       
  +    private static final String DEFAULT_TEXEN_PROPERTIES =
  +        "org/apache/velocity/texen/defaults/texen.properties";
  +
       private Properties props = new Properties();
       private Context controlContext;
       
  @@ -87,10 +87,18 @@
        */
       protected void setDefaultProps()
       {
  -        props.setProperty (PATH_INPUT,".");
  -        props.setProperty (PATH_OUTPUT,"output/");
  -        props.setProperty 
(CONTEXT_STRINGS,"org.apache.velocity.texen.util.StringUtil");
  -        props.setProperty (CONTEXT_FILES,"org.apache.velocity.texen.util.FileUtil");
  +        ClassLoader classLoader = Runtime.class.getClassLoader();
  +        try
  +        {
  +            InputStream inputStream = classLoader.getResourceAsStream(
  +                DEFAULT_TEXEN_PROPERTIES);
  +            
  +            props.load( inputStream );
  +        }
  +        catch (Exception ioe)
  +        {
  +            System.err.println("Cannot get default properties!");
  +        }
       }
           
       /**
  @@ -155,8 +163,7 @@
           else
           {
               FileWriter fw = new FileWriter (props.getProperty (PATH_OUTPUT)+
  -                                            File.separator +
  -                                            output);
  +                File.separator + output);
               template.merge (controlContext,fw);
               fw.close();
               
  @@ -186,14 +193,7 @@
        */ 
       protected Context getContext (Hashtable objs)
       {
  -        //Context context = new Context();
  -        
           fillContextHash (controlContext,objs);
  -        
  -        //fillContextHash (context,objs);
  -        //fillContextDefaults (context);
  -        //fillContextProperties (context);
  -        
           return controlContext;
       }
   
  @@ -217,6 +217,7 @@
       protected void fillContextDefaults (Context context)
       {
           context.put ("generator", instance);
  +        context.put ("outputDirectory", props.getProperty(PATH_OUTPUT));
       }
       
       /**
  @@ -249,8 +250,6 @@
                       //TO DO: Log Something Here
                   }
               }
  -            
           }
  -        
       }
   }
  
  
  
  1.3       +40 -18    
jakarta-velocity/src/java/org/apache/velocity/texen/ant/TexenTask.java
  
  Index: TexenTask.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-velocity/src/java/org/apache/velocity/texen/ant/TexenTask.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TexenTask.java    2000/11/03 15:28:39     1.2
  +++ TexenTask.java    2000/11/16 01:50:43     1.3
  @@ -59,6 +59,10 @@
   import java.util.Map;
   import java.util.Hashtable;
   
  +import java.io.File;
  +import java.io.FileWriter;
  +import java.io.FileOutputStream;
  +
   // Ant Stuff
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Task;
  @@ -72,7 +76,7 @@
    * An ant task for generating output by using Velocity
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
  - * @version $Id: TexenTask.java,v 1.2 2000/11/03 15:28:39 jvanzyl Exp $
  + * @version $Id: TexenTask.java,v 1.3 2000/11/16 01:50:43 jvanzyl Exp $
    */
   
   public abstract class TexenTask extends Task
  @@ -80,6 +84,7 @@
       protected String controlTemplate;
       protected String templatePath;
       protected String outputDirectory;
  +    protected String outputFile;
   
       protected Hashtable options = new Hashtable();
   
  @@ -116,18 +121,15 @@
           return outputDirectory;
       }        
   
  -    public void setOption(String option)
  +    public void setOutputFile(String outputFile)
       {
  -        String optionName = option.substring(0, option.indexOf(":") - 1);
  -        String optionValue = option.substring(option.indexOf(":"));
  -        
  -        options.put(optionName, optionValue);
  +        this.outputFile = outputFile;
       }
  -
  -    public String getOption(String optionName)
  +    
  +    public String getOutputFile()
       {
  -        return (String) options.get(optionName);
  -    }
  +        return outputFile;
  +    }        
   
       public abstract Context initControlContext();
       
  @@ -138,25 +140,45 @@
       {
           // Make sure the template path is set.
           if (templatePath == null)
  -            throw new BuildException("The template path needs to be " +
  -                                     "defined! Texen can't run.");
  +            throw new BuildException("The template path needs to be defined!");
   
           if (controlTemplate == null)
  -            throw new BuildException("The control template needs to be " +
  -                                     "defined! Texen can't run.");
  +            throw new BuildException("The control template needs to be defined!");
   
  +        if (outputDirectory == null)
  +            throw new BuildException("The output directory needs to be defined!");
  +
  +        if (outputFile == null)
  +            throw new BuildException("The output file needs to be defined!");
  +
           try
           {
               // Setup the Velocity Runtime.
               Runtime.setDefaultProperties();
  -            Runtime.setProperty(Runtime.TEMPLATE_PATH, templatePath);
  +            
  +            // This is strictly to allow vel to compile for now.
  +            // I need a new way to set what was the template path
  +            // now that templates streams can come from anywhere.
  +            //!!!Runtime.setProperty(Runtime.TEMPLATE_PATH, templatePath);
               Runtime.init();
  -        
  +
               // Create the text generator.
               Generator generator = Generator.getInstance();
  -            generator.setProperty(Generator.PATH_INPUT,templatePath);
  +            generator.setProperty(Generator.PATH_OUTPUT,outputDirectory);
  +            
  +            // Make sure the output directory exists, if it doesn't
  +            // then create it.
  +            File file = new File(outputDirectory);
  +            if (! file.exists())
  +                file.mkdirs();
               
  -            System.out.println(generator.parse(controlTemplate, 
initControlContext()));
  +            String path = outputDirectory + File.separator + outputFile;
  +            System.out.println(path);
  +            FileWriter writer = new FileWriter(path);
  +                
  +            writer.write(generator.parse(controlTemplate, initControlContext()));
  +            writer.flush();
  +            writer.close();
           }
           catch (Exception e)
           {
  
  
  

Reply via email to