use of freemarker.template.DefaultObjectWrapper in project eweb4j-framework by laiweiwei.
the class PetControlTest method testFreeMarker.
@Test
public void testFreeMarker() throws Exception {
Configuration cfg = new Configuration();
// 指定模板从何处加载的数据源,这里设置成一个文件目录。
cfg.setDirectoryForTemplateLoading(new File("src/test/java/test/ftl"));
// 指定模板如何检索数据模型
cfg.setObjectWrapper(new DefaultObjectWrapper());
Map root = new HashMap();
root.put("user", "Big Joe");
Map latest = new HashMap();
root.put("latestProduct", latest);
latest.put("url", "produces/greenmouse.html");
latest.put("name", "green mouse");
Template template = cfg.getTemplate("hello.html");
Writer out = new OutputStreamWriter(System.out);
template.process(root, out);
out.flush();
}
use of freemarker.template.DefaultObjectWrapper in project ninja by ninjaframework.
the class TemplateEngineFreemarker method createBeansWrapperWithExposedFields.
private BeansWrapper createBeansWrapperWithExposedFields() {
DefaultObjectWrapperBuilder defaultObjectWrapperBuilder = new DefaultObjectWrapperBuilder(INCOMPATIBLE_IMPROVEMENTS_VERSION);
defaultObjectWrapperBuilder.setExposeFields(true);
DefaultObjectWrapper defaultObjectWrapper = defaultObjectWrapperBuilder.build();
return defaultObjectWrapper;
}
use of freemarker.template.DefaultObjectWrapper in project jangaroo-tools by CoreMedia.
the class ExmlComponentClassGenerator method generateClass.
public void generateClass(final ExmlModel model, final Writer output) throws IOException, TemplateException {
Configuration cfg = new Configuration();
cfg.setClassForTemplateLoading(ExmlComponentClassModel.class, "/");
cfg.setObjectWrapper(new DefaultObjectWrapper());
Template template = cfg.getTemplate("/net/jangaroo/exml/templates/exml_component_class.ftl");
ExmlComponentClassModel exmlComponentClassModel = new ExmlComponentClassModel(model);
Environment env = template.createProcessingEnvironment(exmlComponentClassModel, output);
env.setOutputEncoding(Exmlc.OUTPUT_CHARSET);
env.process();
}
use of freemarker.template.DefaultObjectWrapper in project jangaroo-tools by CoreMedia.
the class ExmlConfigClassGenerator method generateClass.
private static void generateClass(final ConfigClass configClass, final Writer output) throws IOException, TemplateException {
if (configClass.getSuperClassName() == null) {
throw new ExmlcException("Config class " + configClass.getFullName() + "'s super class name is null!");
}
Configuration cfg = new Configuration();
cfg.setClassForTemplateLoading(ConfigClass.class, "/");
cfg.setObjectWrapper(new DefaultObjectWrapper());
Template template = cfg.getTemplate("/net/jangaroo/exml/templates/exml_config_class.ftl");
Environment env = template.createProcessingEnvironment(configClass, output);
env.setOutputEncoding(Exmlc.OUTPUT_CHARSET);
env.process();
}
use of freemarker.template.DefaultObjectWrapper in project jangaroo-tools by CoreMedia.
the class ExmlConfigPackageXsdGenerator method generateXsdFile.
public void generateXsdFile(final Collection<ConfigClass> configClasses, String configClassPackage, final Writer output) throws IOException, TemplateException {
ExmlConfigPackage suite = new ExmlConfigPackage(configClasses, configClassPackage);
Configuration cfg = new Configuration();
cfg.setClassForTemplateLoading(ExmlConfigPackage.class, "/");
cfg.setObjectWrapper(new DefaultObjectWrapper());
Template template = cfg.getTemplate("/net/jangaroo/exml/templates/exml_config_package_xsd.ftl");
Environment env = template.createProcessingEnvironment(suite, output);
env.setOutputEncoding(Exmlc.OUTPUT_CHARSET);
env.process();
}
Aggregations