}
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) {
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)
}
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());
+ }
}
}
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));
- }
- }
-*/
}