indy.nl updates
[mir.git] / source / mir / generator / FreemarkerGenerator.java
index 4329ee0..15147c8 100755 (executable)
@@ -16,9 +16,13 @@ public class FreemarkerGenerator implements Generator {
   }
 
   public void generate(PrintWriter anOutputWriter, Map aValues, PrintWriter aLogger) throws GeneratorException {
-    aLogger.println("processing...<br/>");
-               template.process((TemplateModelRoot) makeMapAdapter(aValues), anOutputWriter);
-    aLogger.println("processed...<br/>");
+    try {
+                 template.process((TemplateModelRoot) makeMapAdapter(aValues), anOutputWriter);
+    }
+    catch (Throwable t) {
+      aLogger.println("Exception occurred: "+t.getMessage());
+      t.printStackTrace(aLogger);
+    }
        }
 
   private static TemplateScalarModel makeStringAdapter(String aString) {
@@ -38,8 +42,6 @@ public class FreemarkerGenerator implements Generator {
            return null;
          if (anObject instanceof TemplateModel)
            return (TemplateModel) anObject;
-//       if (anObject instanceof Date)
-//         return new DateAdapter((Date) anObject);
          else if (anObject instanceof MessageResources)
            return new MessageMethodModel((MessageResources) anObject);
          else if (anObject instanceof String)
@@ -76,18 +78,24 @@ public class FreemarkerGenerator implements Generator {
          }
 
          public TemplateModel get(String aKey) throws TemplateModelException {
-           if (!valuesCache.containsKey(aKey)) {
-             Object value = map.get(aKey);
-
-//    ML: this unfortunately doesn't work, because the entity doesn't seem to store
-//        fields with null values
-//    if (value == null && !map.containsKey(aKey))
-//          throw new TemplateModelException("MapAdapter: no key "+aKey+" available");
-
-             valuesCache.put(aKey, makeAdapter(value));
-           }
-
-           return (TemplateModel) valuesCache.get(aKey);
+           try {
+           if (!valuesCache.containsKey(aKey)) {
+             Object value = map.get(aKey);
+
+        if (value == null && !map.containsKey(aKey))
+            throw new TemplateModelException("MapAdapter: no key "+aKey+" available");
+
+             valuesCache.put(aKey, makeAdapter(value));
+           }
+
+           return (TemplateModel) valuesCache.get(aKey);
+         }
+         catch (TemplateModelException e) {
+           throw e;
+         }
+         catch (Throwable t) {
+           throw new TemplateModelException(t.getMessage());
+         }
          }
        }
 
@@ -214,21 +222,4 @@ public class FreemarkerGenerator implements Generator {
       position=0;
     }
        }
-
-/*     private static class DateAdapter implements TemplateHashModel {
-         Date date;
-
-         private DateAdapter(Date aDate) {
-           date = aDate;
-         }
-
-         public boolean isEmpty() {
-           return false;
-         }
-
-         public TemplateModel get(String aKey) throws TemplateModelException {
-           return makeAdapter(new SimpleDateFormat(aKey).format(date));
-         }
-       }
-*/
 }