1.1 restoration
[mir.git] / source / mir / generator / VelocityGenerator.java
index a6c0a77..1735701 100755 (executable)
@@ -31,6 +31,7 @@ package mir.generator;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.io.File;
 import java.util.AbstractList;
 import java.util.Date;
 import java.util.HashMap;
@@ -42,7 +43,6 @@ import java.util.Vector;
 import org.apache.commons.beanutils.MethodUtils;
 import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.velocity.Template;
-import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
 import org.apache.velocity.context.Context;
 import org.apache.velocity.exception.ParseErrorException;
@@ -105,37 +105,6 @@ public class VelocityGenerator implements Generator {
 
   /**
    *
-   * <p>Title: </p>
-   * <p>Description: </p>
-   * <p>Copyright: Copyright (c) 2003</p>
-   * <p>Company: </p>
-   * @author not attributable
-   * @version 1.0
-   */
-  private static class ContextAdapter implements Context {
-    public boolean containsKey(java.lang.Object key) {
-      return false;
-    }
-
-    public Object get(java.lang.String key) {
-      return null;
-    }
-
-    public Object[] getKeys() {
-      return new Object[] {};
-    }
-
-    public Object put(java.lang.String key, java.lang.Object value) {
-      return null;
-    }
-
-    public Object remove(java.lang.Object key) {
-      return null;
-    }
-  }
-
-  /**
-   *
    * @param aMap
    * @return
    */
@@ -166,7 +135,7 @@ public class VelocityGenerator implements Generator {
    * @param aFunction
    * @return
    */
-  private static Object makeFunctionAdapter(Generator.GeneratorFunction aFunction) {
+  private static Object makeFunctionAdapter(Generator.Function aFunction) {
     return new FunctionAdapter(aFunction);
   }
 
@@ -217,8 +186,8 @@ public class VelocityGenerator implements Generator {
     if (anObject instanceof Context)
       return anObject;
 
-    else if (anObject instanceof Generator.GeneratorFunction)
-      return makeFunctionAdapter((Generator.GeneratorFunction) anObject);
+    else if (anObject instanceof Generator.Function)
+      return makeFunctionAdapter((Generator.Function) anObject);
     else if (anObject instanceof Integer)
       return anObject;
     else if (anObject instanceof Boolean)
@@ -249,13 +218,13 @@ public class VelocityGenerator implements Generator {
    * @version 1.0
    */
   public static class FunctionAdapter implements VelocityAdapter {
-    private GeneratorFunction function;
+    private Function function;
 
     public Object getOriginal() {
       return function;
     }
 
-    private FunctionAdapter(GeneratorFunction aFunction) {
+    private FunctionAdapter(Function aFunction) {
       function = aFunction;
     }
 
@@ -364,14 +333,11 @@ public class VelocityGenerator implements Generator {
   private static class IteratorAdapter extends AbstractList implements VelocityAdapter  {
     private Iterator iterator;
     private List valuesCache;
-    private int position;
 
     private IteratorAdapter(Iterator anIterator) {
       iterator = anIterator;
 
       valuesCache = new Vector();
-      position=0;
-
 
       if (iterator instanceof RewindableIterator) {
         ((RewindableIterator) iterator).rewind();
@@ -423,13 +389,11 @@ public class VelocityGenerator implements Generator {
   private static class ListAdapter extends AbstractList implements VelocityAdapter  {
     private List list;
     private List valuesCache;
-    private int position;
 
     private ListAdapter(List aList) {
       list = aList;
 
       valuesCache = new Vector();
-      position=0;
     }
 
     private void getUntil(int anIndex) {
@@ -569,46 +533,22 @@ public class VelocityGenerator implements Generator {
    * @author not attributable
    * @version 1.0
    */
-  public static class VelocityGeneratorLibrary implements GeneratorLibrary {
+  public static class VelocityGeneratorLibrary implements Library {
     private VelocityEngine engine;
 
-    public VelocityGeneratorLibrary(String aTemplateRoot) throws GeneratorExc, GeneratorFailure {
+    public VelocityGeneratorLibrary(File aTemplateRoot) throws GeneratorExc, GeneratorFailure {
       try {
         engine = new VelocityEngine();
         try {
           engine.setProperty(VelocityEngine.RESOURCE_LOADER, "file");
-        }
-        catch (Throwable t) {
-          logger.error(VelocityEngine.RESOURCE_LOADER);
-        }
-
-        try {
           engine.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
-        }
-        catch (Throwable t) {
-          logger.error("file.resource.loader.class");
-        }
-
-        try {
-          engine.setProperty("file.resource.loader.path", aTemplateRoot);
-        }
-        catch (Throwable t) {
-          logger.error("file.resource.loader.path");
-
-        }
-        try {
+          engine.setProperty("file.resource.loader.path", aTemplateRoot.getAbsolutePath());
           engine.setProperty("file.resource.loader.cache", "true");
         }
         catch (Throwable t) {
-          logger.error("file.resource.loader.cache");
-
-        }
-        try {
-          engine.setProperty("file.resource.loader.modificationCheckInterval", "10");
-        }
-        catch (Throwable t) {
-          logger.error("file.resource.loader.modificationCheckInterval");
+          logger.error("Error while constructing library: " + t.toString());
 
+          throw new GeneratorFailure(t);
         }
 
         try {
@@ -642,15 +582,15 @@ public class VelocityGenerator implements Generator {
    * @author not attributable
    * @version 1.0
    */
-  public static class VelocityGeneratorLibraryFactory implements GeneratorLibraryFactory {
-    private String basePath;
+  public static class VelocityGeneratorLibraryFactory implements LibraryFactory {
+    private File basePath;
 
-    public VelocityGeneratorLibraryFactory(String aBasePath) {
+    public VelocityGeneratorLibraryFactory(File aBasePath) {
       basePath = aBasePath;
     }
 
-    public GeneratorLibrary makeLibrary(String anInitializationString) throws GeneratorExc, GeneratorFailure {
-      return new VelocityGeneratorLibrary(basePath+anInitializationString);
+    public Library makeLibrary(String anInitializationString) throws GeneratorExc, GeneratorFailure {
+      return new VelocityGeneratorLibrary(new File(basePath, anInitializationString));
     };
   }
 }