import freemarker.template.*;
import mir.entity.*;
import mir.util.*;
+import mir.misc.*;
+import org.apache.struts.util.MessageResources;
public class FreemarkerGenerator implements Generator {
private Template template;
return null;
if (anObject instanceof TemplateModel)
return (TemplateModel) anObject;
- if (anObject instanceof String)
+// if (anObject instanceof Date)
+// return new DateAdapter((Date) anObject);
+ else if (anObject instanceof MessageResources)
+ return new MessageMethodModel((MessageResources) anObject);
+ else if (anObject instanceof String)
return makeStringAdapter((String) anObject);
else if (anObject instanceof Map)
return makeMapAdapter((Map) anObject);
else if (anObject instanceof Iterator)
return makeIteratorAdapter((Iterator) anObject);
+ else if (anObject instanceof List)
+ return makeIteratorAdapter(((List) anObject).iterator());
else
throw new TemplateModelException("Unadaptable class: " + anObject.getClass().getName());
}
if (!valuesCache.containsKey(aKey)) {
Object value = map.get(aKey);
- if (value == null)
- throw new TemplateModelException("MapAdapter: no key "+aKey+" available");
+// 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));
}
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));
+ }
+ }
+*/
}