Index: Generator.java
===================================================================
RCS file: /home/cvspublic/jakarta-velocity/src/java/org/apache/velocity/texen/Generator.java,v
retrieving revision 1.17
diff -r1.17 Generator.java
57d56
< import java.io.BufferedInputStream;
59,60d57
< import java.io.FileWriter;
< import java.io.FileInputStream;
61a59,62
> import java.io.FileInputStream;
> import java.io.BufferedInputStream;
> import java.io.Writer;
> import java.io.FileWriter;
62a64,66
> import java.io.OutputStreamWriter;
> import java.io.BufferedWriter;
> import java.io.FileOutputStream;
117c121
<     private Hashtable fileWriters = new Hashtable();
---
>     private Hashtable writers = new Hashtable();
126a131,141
>      * This is the encoding for the output file(s).
>      */
>     protected String outputEncoding;
> 
>     /**
>      * This is the encoding for the input file(s)
>      * (templates).
>      */
>     protected String inputEncoding;
> 
>     /**
264a280,329
>      * Set the output encoding.
>      */
>     public void setOutputEncoding(String outputEncoding)
>     {
>         this.outputEncoding = outputEncoding;
>     }
> 
>     /**
>      * Set the input (template) encoding.
>      */
>     public void setInputEncoding(String inputEncoding)
>     {
>         this.inputEncoding = inputEncoding;
>     }
> 
>     /**
>      * Returns a writer, based on encoding and path.
>      *
>      * @param path      path to the output file
>      * @param encoding  output encoding
>      */
>     public Writer getWriter(String path, String encoding) throws Exception {
>         Writer writer;
>         if (encoding == null || encoding.length() == 0 || encoding.equals("8859-1") || encoding.equals("8859_1")) {
>             writer = new FileWriter(path);
>         }
>         else {
>             writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), encoding));
>         }
>         return writer;
>     }
> 
>     /**
>      * Returns a template, based on encoding and path.
>      *
>      * @param templateName  name of the template
>      * @param encoding      template encoding
>      */
>     public Template getTemplate(String templateName, String encoding) throws Exception {
>         Template template;
>         if (encoding == null || encoding.length() == 0 || encoding.equals("8859-1") || encoding.equals("8859_1")) {
>             template = Velocity.getTemplate(templateName);
>         }
>         else {
>             template = Velocity.getTemplate(templateName, encoding);
>         }
>         return template;
>     }
> 
>     /**
288a354,375
>      */
>     public String parse (String inputTemplate,
>                          String outputFile,
>                          String objectID,
>                          Object object)
>         throws Exception
>     {
>         return parse(inputTemplate, null, outputFile, null, objectID, object);
>     }
>     /**
>      * Parse an input and write the output to an output file.  If the
>      * output file parameter is null or an empty string the result is
>      * returned as a string object.  Otherwise an empty string is returned.
>      * You can add objects to the context with the objs Hashtable.
>      *
>      * @param String input template
>      * @param String inputEncoding template encoding
>      * @param String output file
>      * @param String outputEncoding encoding of output file
>      * @param String id for object to be placed in the control context
>      * @param String object to be placed in the context
>      * @return String generated output from velocity
291,292c378,381
<                          String outputFile, 
<                          String objectID, 
---
>                          String intputEncoding,
>                          String outputFile,
>                          String outputEncoding,
>                          String objectID,
301c390
<         Template template = Velocity.getTemplate(inputTemplate);
---
>         Template template = getTemplate(inputTemplate, inputEncoding != null ? inputEncoding : this.inputEncoding);
311c400
<             FileWriter fileWriter = null;
---
>             Writer writer = null;
313c402
<             if (fileWriters.get(outputFile) == null)
---
>             if (writers.get(outputFile) == null)
319,320c408,411
<                 fileWriter = new FileWriter(
<                     getOutputPath() + File.separator + outputFile);
---
>                 writer = getWriter(
>                             getOutputPath() + File.separator + outputFile,
>                             outputEncoding != null ? outputEncoding : this.outputEncoding
>                          );
326c417
<                 fileWriters.put(outputFile, fileWriter);                    
---
>                 writers.put(outputFile, writer);
330c421
<                 fileWriter = (FileWriter) fileWriters.get(outputFile);
---
>                 writer = (Writer) writers.get(outputFile);
334c425
<             template.merge (vc,fileWriter);
---
>             template.merge (vc,writer);
357,358c448,449
<         
<         Template template = Velocity.getTemplate(controlTemplate);
---
> 
>         Template template = getTemplate(controlTemplate, inputEncoding);
450c541
<         Iterator iterator = fileWriters.values().iterator();
---
>         Iterator iterator = writers.values().iterator();
454c545
<             FileWriter fileWriter = (FileWriter) iterator.next();
---
>             Writer writer = (Writer) iterator.next();
458,459c549,550
<                 fileWriter.flush();
<                 fileWriter.close();
---
>                 writer.flush();
>                 writer.close();
467c558
<         fileWriters.clear();
---
>         writers.clear();

