Search in sources :

Example 1 with DefaultObjectWrapper

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();
}
Also used : Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Template(freemarker.template.Template) Test(org.junit.Test)

Example 2 with DefaultObjectWrapper

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;
}
Also used : DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) DefaultObjectWrapperBuilder(freemarker.template.DefaultObjectWrapperBuilder)

Example 3 with 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();
}
Also used : ExmlConfiguration(net.jangaroo.exml.config.ExmlConfiguration) Configuration(freemarker.template.Configuration) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) Environment(freemarker.core.Environment) Template(freemarker.template.Template)

Example 4 with DefaultObjectWrapper

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();
}
Also used : Configuration(freemarker.template.Configuration) ExmlcException(net.jangaroo.exml.api.ExmlcException) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) Environment(freemarker.core.Environment) Template(freemarker.template.Template)

Example 5 with DefaultObjectWrapper

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();
}
Also used : Configuration(freemarker.template.Configuration) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) Environment(freemarker.core.Environment) Template(freemarker.template.Template)

Aggregations

DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)10 Configuration (freemarker.template.Configuration)8 Template (freemarker.template.Template)5 Environment (freemarker.core.Environment)3 IOException (java.io.IOException)3 TemplateException (freemarker.template.TemplateException)2 Writer (java.io.Writer)2 HashMap (java.util.HashMap)2 AuthorizerImpl (com.openmeap.AuthorizerImpl)1 ModelManager (com.openmeap.model.ModelManager)1 ModelServiceImpl (com.openmeap.model.ModelServiceImpl)1 GlobalSettings (com.openmeap.model.dto.GlobalSettings)1 DocumentProcessor (com.openmeap.web.DocumentProcessor)1 UnexpectedServerException (com.pratilipi.common.exception.UnexpectedServerException)1 ClassTemplateLoader (freemarker.cache.ClassTemplateLoader)1 BeanModel (freemarker.ext.beans.BeanModel)1 DefaultObjectWrapperBuilder (freemarker.template.DefaultObjectWrapperBuilder)1 File (java.io.File)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringReader (java.io.StringReader)1