X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fgenerator%2FFreemarkerGenerator.java;h=c0ebb764cf7e6c0a77ea73c63c22a85696c79f5b;hb=29da699109ce8842d02b60abcdb0dfdc4aa4f0db;hp=11d86109b04dc8cd45d05f07202de0fd8e0e90a3;hpb=a459f111d85598df56c6ab711cec11632676b39c;p=mir.git diff --git a/source/mir/generator/FreemarkerGenerator.java b/source/mir/generator/FreemarkerGenerator.java index 11d86109..c0ebb764 100755 --- a/source/mir/generator/FreemarkerGenerator.java +++ b/source/mir/generator/FreemarkerGenerator.java @@ -18,18 +18,19 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. * If you do not wish to do so, delete this exception statement from your version. */ package mir.generator; import java.io.PrintWriter; +import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -37,8 +38,10 @@ import java.util.Map; import java.util.Vector; import mir.log.LoggerWrapper; +import mir.util.GeneratorFormatAdapters; import mir.util.RewindableIterator; +import org.apache.commons.beanutils.MethodUtils; import org.apache.commons.beanutils.PropertyUtils; import freemarker.template.FileTemplateCache; @@ -119,9 +122,12 @@ public class FreemarkerGenerator implements Generator { return makeIteratorAdapter((Iterator) anObject); else if (anObject instanceof List) return makeIteratorAdapter(((List) anObject).iterator()); + else if (anObject instanceof Number) + return makeAdapter(new GeneratorFormatAdapters.NumberFormatAdapter((Number) anObject)); + else if (anObject instanceof Date) + return makeAdapter(new GeneratorFormatAdapters.DateFormatAdapter((Date) anObject)); else return makeBeanAdapter(anObject); -// throw new TemplateModelException("Unadaptable class: " + anObject.getClass().getName()); } private static class MapAdapter implements TemplateModelRoot { @@ -138,7 +144,6 @@ public class FreemarkerGenerator implements Generator { } public void remove(String aKey) { - // ML: kinda tricky... } public boolean isEmpty() { @@ -336,7 +341,10 @@ public class FreemarkerGenerator implements Generator { public TemplateModel get(String aKey) throws TemplateModelException { try { - return makeAdapter(PropertyUtils.getSimpleProperty(object, aKey)); + if (PropertyUtils.isReadable(object, aKey)) + return makeAdapter(PropertyUtils.getSimpleProperty(object, aKey)); + else + return makeAdapter(MethodUtils.invokeExactMethod(object, "get", aKey)); } catch (Throwable t) { throw new TemplateModelException(t.getMessage()); @@ -356,7 +364,7 @@ public class FreemarkerGenerator implements Generator { Template template = (Template) templateCache.getItem(anIdentifier, "template"); if (template==null) { - throw new GeneratorExc("FreemarkerGeneratorLibrary: Can't find template "+templateCache.getDirectory()+anIdentifier); + throw new GeneratorExc("FreemarkerGeneratorLibrary: Can't find template "+templateCache.getDirectory()+"/"+anIdentifier); } return new FreemarkerGenerator(template);