* 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;
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;
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 {
}
public void remove(String aKey) {
- // ML: kinda tricky...
}
public boolean isEmpty() {
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());