Java 类freemarker.template.Version 实例源码

项目:alfresco-repository    文件:LocalFeedTaskProcessor.java   
@Override
protected Configuration getFreemarkerConfiguration(RepoCtx ctx)
{
    if (useRemoteCallbacks)
    {
        // as per 3.0, 3.1
        return super.getFreemarkerConfiguration(ctx);
    } 
    else
    {
        Configuration cfg = new Configuration();
        cfg.setObjectWrapper(new DefaultObjectWrapper());

        cfg.setTemplateLoader(new ClassPathRepoTemplateLoader(nodeService, contentService, defaultEncoding));

        // TODO review i18n
        cfg.setLocalizedLookup(false);
        cfg.setIncompatibleImprovements(new Version(2, 3, 20));
        cfg.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);

        return cfg;
    }
}
项目:tkcg    文件:Generator.java   
private FreemarkerHelper buildFreemarkerHelper(File templateBaseDir) {
    Configuration configuration = new Configuration(new Version(2, 3, 0));
    try {
        TemplateLoader templateLoader = new FileTemplateLoader(templateBaseDir);
        configuration.setTemplateLoader(templateLoader);
    } catch (IOException e) {
        throw new GeneratorException("构建模板助手出错:" + e.getMessage());
    }
    configuration.setNumberFormat("###############");
    configuration.setBooleanFormat("true,false");
    configuration.setDefaultEncoding("UTF-8");

    // 自动导入公共文件,用于支持灵活变量
    if (autoIncludeFile.exists()) {
        List<String> autoIncludeList = new ArrayList<>();
        autoIncludeList.add(FREEMARKER_AUTO_INCLUDE_SUFFIX);
        configuration.setAutoIncludes(autoIncludeList);
    }
    return new FreemarkerHelper(configuration);
}
项目:raml-module-builder    文件:SchemaMaker.java   
/**
 * @param onTable
 */
public SchemaMaker(String tenant, String module, TenantOperation mode, String previousVersion, String rmbVersion){
  if(SchemaMaker.cfg == null){
    //do this ONLY ONCE
    SchemaMaker.cfg = new Configuration(new Version(2, 3, 26));
    // Where do we load the templates from:
    cfg.setClassForTemplateLoading(SchemaMaker.class, "/templates/db_scripts");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setLocale(Locale.US);
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  }
  this.tenant = tenant;
  this.module = module;
  this.mode = mode;
  this.previousVersion = previousVersion;
  this.rmbVersion = rmbVersion;
}
项目:hawkular-alerts    文件:EmailTemplate.java   
public EmailTemplate() {
    ftlCfg = new Configuration(new Version(FREEMARKER_VERSION));
    try {
        // Check if templates are located from disk or if we are loading default ones.
        String templatesDir = System.getenv(EmailPlugin.HAWKULAR_ALERTS_TEMPLATES);
        templatesDir = templatesDir == null ? System.getProperty(EmailPlugin.HAWKULAR_ALERTS_TEMPLATES_PROPERY)
                : templatesDir;
        boolean templatesFromDir = false;
        if (templatesDir != null) {
            File fileDir = new File(templatesDir);
            if (fileDir.exists()) {
                ftlCfg.setDirectoryForTemplateLoading(fileDir);
                templatesFromDir = true;
            }
        }
        if (!templatesFromDir) {
            ftlCfg.setClassForTemplateLoading(this.getClass(), "/");
        }
        ftlTemplatePlain = ftlCfg.getTemplate(DEFAULT_TEMPLATE_PLAIN, DEFAULT_LOCALE);
        ftlTemplateHtml = ftlCfg.getTemplate(DEFAULT_TEMPLATE_HTML, DEFAULT_LOCALE);
    } catch (IOException e) {
        log.debug(e.getMessage(), e);
        throw new RuntimeException("Cannot initialize templates on email plugin: " + e.getMessage());
    }
}
项目:WebSphere-Deployment-Xml-Tool    文件:DeploymentXmlWriter.java   
public void save() throws Exception {
    genTime = new Date().getTime();
    deploymentXmlFile.getParentFile().mkdirs();

    Configuration cfg = new Configuration(new Version(2, 3, 22));
    cfg.setClassLoaderForTemplateLoading(this.getClass().getClassLoader(), "templates");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

    Template template = cfg.getTemplate("parent_last.ftl");

    FileOutputStream outputStream = new FileOutputStream(deploymentXmlFile);
    Writer out = new OutputStreamWriter(outputStream);
    template.process(this, out);
    outputStream.flush();
    outputStream.close();
}
项目:private-freemarker    文件:FreemarkerConfiguration.java   
public static Template getTemplate(String name) {
    Template template = null;
    try {
        Version version = new Version("2.3.0");
        Configuration cfg = new Configuration(version);
        // 读取ftl模板
        cfg.setClassForTemplateLoading(FreemarkerConfiguration.class, "/ftl");
        cfg.setClassicCompatible(true);
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
        cfg.setObjectWrapper(new SaicObjectWrapper(cfg.getIncompatibleImprovements()));
        template = cfg.getTemplate(name);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return template;
}
项目:community-edition-old    文件:LocalFeedTaskProcessor.java   
@Override
protected Configuration getFreemarkerConfiguration(RepoCtx ctx)
{
    if (useRemoteCallbacks)
    {
        // as per 3.0, 3.1
        return super.getFreemarkerConfiguration(ctx);
    } 
    else
    {
        Configuration cfg = new Configuration();
        cfg.setObjectWrapper(new DefaultObjectWrapper());

        cfg.setTemplateLoader(new ClassPathRepoTemplateLoader(nodeService, contentService, defaultEncoding));

        // TODO review i18n
        cfg.setLocalizedLookup(false);
        cfg.setIncompatibleImprovements(new Version(2, 3, 20));
        cfg.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);

        return cfg;
    }
}
项目:matsuo-core    文件:AbstractPrintGeneratingTest.java   
AbstractPrintGeneratingTest() {
  targetDirectory.mkdirs();

  try {
    freeMarkerConfiguration = new Configuration();
    freeMarkerConfiguration.setTemplateLoader(new ClassTemplateLoader(Class.class, "/"));
    //freeMarkerConfiguration.setDirectoryForTemplateLoading(new File(templateDirectory).getAbsoluteFile());
    freeMarkerConfiguration.setObjectWrapper(new DefaultObjectWrapper());
    freeMarkerConfiguration.setDefaultEncoding("UTF-8");
    freeMarkerConfiguration.setTemplateExceptionHandler(HTML_DEBUG_HANDLER);
    freeMarkerConfiguration.setIncompatibleImprovements(new Version(2, 3, 20));

    printsRendererService.setFreeMarkerConfiguration(freeMarkerConfiguration);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
项目:private-freemarker    文件:FreemarkerConfiguration.java   
public static Template getTemplate(String name) {
    Template template = null;
    try {
        Version version = new Version("2.3.0");
        Configuration cfg = new Configuration(version);
        // 读取ftl模板
        cfg.setClassForTemplateLoading(FreemarkerConfiguration.class, "/ftl");
        cfg.setClassicCompatible(true);
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
        cfg.setObjectWrapper(new SaicObjectWrapper(cfg.getIncompatibleImprovements()));
        template = cfg.getTemplate(name);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return template;
}
项目:GMM    文件:ApplicationConfiguration.java   
/**
 * FreeMarker (ftl) configuration
 */
@Bean
public FreeMarkerConfigurer freemarkerConfig() throws IOException, TemplateException {
    final FreeMarkerConfigurer result = new FreeMarkerConfigurer();

    // template path
    result.setTemplateLoaderPath("/WEB-INF/ftl/");
    result.setDefaultEncoding("UTF-8");

    // static access
    final Version version = freemarker.template.Configuration.getVersion();
    final BeansWrapper wrapper = new BeansWrapper(version);
    final TemplateHashModel statics = wrapper.getStaticModels();
    final Map<String, Object> shared = new HashMap<>();
    for (final Class<?> clazz : ElFunctions.staticClasses) {
        shared.put(clazz.getSimpleName(), statics.get(clazz.getName()));
    }
    result.setFreemarkerVariables(shared);

    return result;
}
项目:collect-earth    文件:FreemarkerTemplateUtils.java   
public static boolean applyTemplate(File sourceTemplate, File destinationFile, Map<?, ?> data) throws IOException, TemplateException{

        boolean success = true;

        // Process the template file using the data in the "data" Map
        final Configuration cfg = new Configuration( new Version("2.3.23"));
        cfg.setDirectoryForTemplateLoading(sourceTemplate.getParentFile());

        // Load template from source folder
        final Template template = cfg.getTemplate(sourceTemplate.getName());

        // Console output
        BufferedWriter fw = null;
        try {
            fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(destinationFile), Charset.forName("UTF-8")));
            template.process(data, fw);
        }finally {
            if (fw != null) {
                fw.close();
            }
        }

        return success;

    }
项目:alfresco-repository    文件:FeedTaskProcessor.java   
protected Configuration getFreemarkerConfiguration(RepoCtx ctx)
{
    Configuration cfg = new Configuration();
    cfg.setObjectWrapper(new DefaultObjectWrapper());

    // custom template loader
    cfg.setTemplateLoader(new TemplateWebScriptLoader(ctx.getRepoEndPoint(), ctx.getTicket()));

    // TODO review i18n
    cfg.setLocalizedLookup(false);
    cfg.setIncompatibleImprovements(new Version(2, 3, 20));
    cfg.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);

    return cfg;
}
项目:alfresco-repository    文件:FreeMarkerProcessor.java   
/**
 * FreeMarker configuration for loading the specified template directly from a String
 * 
 * @param path      Pseudo Path to the template
 * @param template  Template content
 * 
 * @return FreeMarker configuration
 */
protected Configuration getStringConfig(String path, String template)
{
    Configuration config = new Configuration();

    // setup template cache
    config.setCacheStorage(new MruCacheStorage(2, 0));

    // use our custom loader to load a template directly from a String
    StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
    stringTemplateLoader.putTemplate(path, template);
    config.setTemplateLoader(stringTemplateLoader);

    // use our custom object wrapper that can deal with QNameMap objects directly
    config.setObjectWrapper(qnameObjectWrapper);

    // rethrow any exception so we can deal with them
    config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

    // set default template encoding
    if (defaultEncoding != null)
    {
        config.setDefaultEncoding(defaultEncoding);
    }
    config.setIncompatibleImprovements(new Version(2, 3, 20));
    config.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);

    return config;
}
项目:bouncr    文件:I18nMiddleware.java   
@Override
public HttpResponse handle(HttpRequest request, MiddlewareChain chain) {
    ContentNegotiable negotiable = ContentNegotiable.class.cast(MixinUtils.mixin(request, ContentNegotiable.class));
    HttpResponse response = castToHttpResponse(chain.next(request));
    if (TemplatedHttpResponse.class.isInstance(response)) {
        TemplatedHttpResponse tres = TemplatedHttpResponse.class.cast(response);
        ResourceBundle bundle = config.getMessageResource().getBundle(negotiable.getLocale());
        tres.getContext().put("t", new ResourceBundleModel(bundle,
                new BeansWrapperBuilder(new Version(2,3,23)).build()));
    }
    return response;
}
项目:scipio-erp    文件:ScipioFtlWrappers.java   
public static ScipioBasicBeansWrapperImpl create(Version incompatibleImprovements, Boolean simpleMapWrapper) {
    ScipioBasicBeansWrapperImpl wrapper = new ScipioBasicBeansWrapperImpl(incompatibleImprovements, systemWrapperFactories);
    if (simpleMapWrapper != null) {
        wrapper.setSimpleMapWrapper(simpleMapWrapper);
    }
    return wrapper;
}
项目:scipio-erp    文件:ScipioFtlWrappers.java   
public static ScipioBasicDefaultObjectWrapperImpl create(Version incompatibleImprovements,
        Boolean simpleMapWrapper, Boolean useAdaptersForContainers) {
    ScipioBasicDefaultObjectWrapperImpl wrapper = new ScipioBasicDefaultObjectWrapperImpl(incompatibleImprovements, systemWrapperFactories);
    if (simpleMapWrapper != null) {
        wrapper.setSimpleMapWrapper(simpleMapWrapper);
    }
    if (useAdaptersForContainers != null) {
        wrapper.setUseAdaptersForContainers(useAdaptersForContainers);
    }
    return wrapper;
}
项目:scipio-erp    文件:ScipioFtlWrappers.java   
public static ScipioExtendedBeansWrapperImpl create(Version incompatibleImprovements, String encodeLang, Boolean simpleMapWrapper) {
    ScipioExtendedBeansWrapperImpl wrapper = new ScipioExtendedBeansWrapperImpl(incompatibleImprovements, systemWrapperFactories, encodeLang);
    if (simpleMapWrapper != null) {
        wrapper.setSimpleMapWrapper(simpleMapWrapper);
    }
    return wrapper;
}
项目:scipio-erp    文件:ScipioFtlWrappers.java   
public static ScipioExtendedDefaultObjectWrapperImpl create(Version incompatibleImprovements, String encodeLang, 
        Boolean simpleMapWrapper, Boolean useAdaptersForContainers) {
    ScipioExtendedDefaultObjectWrapperImpl wrapper = new ScipioExtendedDefaultObjectWrapperImpl(incompatibleImprovements, systemWrapperFactories, encodeLang);
    if (simpleMapWrapper != null) {
        wrapper.setSimpleMapWrapper(simpleMapWrapper);
    }
    if (useAdaptersForContainers != null) {
        wrapper.setUseAdaptersForContainers(useAdaptersForContainers);
    }
    return wrapper;
}
项目:service-rally    文件:RallyServiceApp.java   
@Bean
public TemplateEngine getTemplateEngine() {

    Version version = new Version(2, 3, 25);
    freemarker.template.Configuration cfg = new freemarker.template.Configuration(version);

    cfg.setClassForTemplateLoading(RallyServiceApp.class, "/");

    cfg.setIncompatibleImprovements(version);
    cfg.setDefaultEncoding(Charsets.UTF_8.toString());
    cfg.setLocale(Locale.US);
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    return new FreemarkerTemplateEngine(cfg);
}
项目:raml-module-builder    文件:FacetManager.java   
/**
 * indicate the table name to query + facet on
 * @param onTable
 */
public FacetManager(String onTable){
  this.table = onTable;
  if(FacetManager.cfg == null){
    //do this ONLY ONCE
    FacetManager.cfg = new Configuration(new Version(2, 3, 26));
    // Where do we load the templates from:
    cfg.setClassForTemplateLoading(FacetManager.class, "/templates/facets");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setLocale(Locale.US);
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  }
}
项目:jwebrobot    文件:FreemarkerExpressionEvaluator.java   
private Configuration createConfig(){
    Configuration config = new Configuration(new Version(2, 3, 23));
    config.setDefaultEncoding("UTF-8");
    config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    config.setCacheStorage(NullCacheStorage.INSTANCE);
    return config;
}
项目:Iron    文件:StoreProcessor.java   
private Configuration getFreemarkerConfiguration() {
    if (mFreemarkerConfiguration == null) {
        mFreemarkerConfiguration = new Configuration(new Version(2, 3, 22));
        mFreemarkerConfiguration.setClassForTemplateLoading(getClass(), "");
    }
    return mFreemarkerConfiguration;
}
项目:android-prefs    文件:PrefsProcessor.java   
private Configuration getFreemarkerConfiguration() {
    if (mFreemarkerConfiguration == null) {
        mFreemarkerConfiguration = new Configuration(new Version(2, 3, 26));
        mFreemarkerConfiguration.setClassForTemplateLoading(getClass(), "");
    }
    return mFreemarkerConfiguration;
}
项目:live-chat-engine    文件:Templates.java   
public Templates(String dirPath) throws IOException {
    this.dirPath = dirPath;

    cfg = new Configuration();
    cfg.setLocalizedLookup(false);
       cfg.setDirectoryForTemplateLoading(new File(this.dirPath));
       cfg.setObjectWrapper(new DefaultObjectWrapper());
       cfg.setDefaultEncoding("UTF-8");
       cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
       cfg.setIncompatibleImprovements(new Version(2, 3, 20));
}
项目:ACME-Generator    文件:Covert2AcmeGenerator.java   
private static Configuration getConfigurationInstance(String destDir) throws IOException {
    if (cfg == null) {
        try {
            cfg = new Configuration();
        } catch (Exception e) {
            e.printStackTrace();
        }
        cfg.setDirectoryForTemplateLoading(new File(destDir));
        cfg.setObjectWrapper(new DefaultObjectWrapper());
        cfg.setDefaultEncoding("UTF-8");
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
        cfg.setIncompatibleImprovements(new Version(2, 3, 20));
    }
    return cfg;
}
项目:taxii-log-adapter    文件:HttpBodyWriter.java   
public HttpBodyWriter(TaxiiStatusDao taxiiStatusDao) throws IOException {
    this.taxiiStatusDao = taxiiStatusDao;
    cfg = new Configuration(new Version(2, 3, 21));
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateLoader(new ClassTemplateLoader(HttpBodyWriter.class, "templates"));
    template = cfg.getTemplate("poll-request.ftl");
    templateFulfillment = cfg.getTemplate("poll-fulfillment-request.ftl");
}
项目:MortarLib    文件:ScreenGenerator.java   
private Configuration getFreemarkerConfig() {
  Configuration config = new Configuration();
  config.setClassForTemplateLoading(ScreenGenerator.class, "template");
  config.setIncompatibleImprovements(new Version(2, 3, 20));
  config.setDefaultEncoding("UTF-8");
  config.setLocale(Locale.US);
  config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  return config;
}
项目:jee    文件:WlpPomBuilder.java   
public WlpPomBuilder() throws IOException {
    cfg = new Configuration();

    //URL template = Thread.currentThread().getContextClassLoader().getResource(".");
    //cfg.setDirectoryForTemplateLoading(new File(template.toString().substring(5)));
    cfg.setClassForTemplateLoading(this.getClass(), "/templates");
    cfg.setObjectWrapper(new DefaultObjectWrapper());
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setIncompatibleImprovements(new Version(2, 3, 20));
}
项目:community-edition-old    文件:FeedTaskProcessor.java   
protected Configuration getFreemarkerConfiguration(RepoCtx ctx)
{
    Configuration cfg = new Configuration();
    cfg.setObjectWrapper(new DefaultObjectWrapper());

    // custom template loader
    cfg.setTemplateLoader(new TemplateWebScriptLoader(ctx.getRepoEndPoint(), ctx.getTicket()));

    // TODO review i18n
    cfg.setLocalizedLookup(false);
    cfg.setIncompatibleImprovements(new Version(2, 3, 20));
    cfg.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);

    return cfg;
}
项目:community-edition-old    文件:FreeMarkerProcessor.java   
/**
 * Get the FreeMarker configuration for this instance
 * 
 * @return FreeMarker configuration
 */
protected synchronized Configuration getConfig()
{
    if (config == null)
    {
        config = new Configuration();

        // setup template cache
        config.setCacheStorage(new MruCacheStorage(512, 1024));

        // use our custom loader to find templates on the ClassPath
        config.setTemplateLoader(new ClassPathRepoTemplateLoader(
                this.services.getNodeService(), this.services.getContentService(), defaultEncoding));

        // use our custom object wrapper that can deal with QNameMap objects directly
        config.setObjectWrapper(qnameObjectWrapper);

        // rethrow any exception so we can deal with them
        config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

        // localized template lookups off by default - as they create strange noderef lookups
        // such as workspace://SpacesStore/01234_en_GB - causes problems for ns.exists() on DB2
        config.setLocalizedLookup(localizedLookup);

        // set default template encoding
        if (defaultEncoding != null)
        {
            config.setDefaultEncoding(defaultEncoding);
        }
        config.setIncompatibleImprovements(new Version(2, 3, 20));
        config.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);
    }

    return config;
}
项目:community-edition-old    文件:FreeMarkerProcessor.java   
/**
 * FreeMarker configuration for loading the specified template directly from a String
 * 
 * @param path      Pseudo Path to the template
 * @param template  Template content
 * 
 * @return FreeMarker configuration
 */
protected Configuration getStringConfig(String path, String template)
{
    Configuration config = new Configuration();

    // setup template cache
    config.setCacheStorage(new MruCacheStorage(2, 0));

    // use our custom loader to load a template directly from a String
    StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
    stringTemplateLoader.putTemplate(path, template);
    config.setTemplateLoader(stringTemplateLoader);

    // use our custom object wrapper that can deal with QNameMap objects directly
    config.setObjectWrapper(qnameObjectWrapper);

    // rethrow any exception so we can deal with them
    config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

    // set default template encoding
    if (defaultEncoding != null)
    {
        config.setDefaultEncoding(defaultEncoding);
    }
    config.setIncompatibleImprovements(new Version(2, 3, 20));
    config.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);

    return config;
}
项目:easydao    文件:Engine.java   
/**
 * @see http://freemarker.org/docs/pgui_quickstart_createconfiguration.html
 * @return Freemarker configuration
 */
private void initFreemarkerConfiguration() {
    freemarkerConfig = new Configuration();
    freemarkerConfig.setClassForTemplateLoading(Engine.class, "/hu/vanio/easydao/templates");
    freemarkerConfig.setObjectWrapper(new DefaultObjectWrapper());
    freemarkerConfig.setDefaultEncoding("UTF-8");
    freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    freemarkerConfig.setIncompatibleImprovements(new Version(2, 3, 23));
}
项目:deeplearning4j    文件:StaticPageUtil.java   
public static String renderHTMLContent(Component... components) throws Exception {

        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
        mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
        mapper.enable(SerializationFeature.INDENT_OUTPUT);

        Configuration cfg = new Configuration(new Version(2, 3, 23));

        // Where do we load the templates from:
        cfg.setClassForTemplateLoading(StaticPageUtil.class, "");

        // Some other recommended settings:
        cfg.setIncompatibleImprovements(new Version(2, 3, 23));
        cfg.setDefaultEncoding("UTF-8");
        cfg.setLocale(Locale.US);
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);

        ClassPathResource cpr = new ClassPathResource("assets/dl4j-ui.js");
        String scriptContents = IOUtils.toString(cpr.getInputStream(), "UTF-8");

        Map<String, Object> pageElements = new HashMap<>();
        List<ComponentObject> list = new ArrayList<>();
        int i = 0;
        for (Component c : components) {
            list.add(new ComponentObject(String.valueOf(i), mapper.writeValueAsString(c)));
            i++;
        }
        pageElements.put("components", list);
        pageElements.put("scriptcontent", scriptContents);


        Template template = cfg.getTemplate("staticpage.ftl");
        Writer stringWriter = new StringWriter();
        template.process(pageElements, stringWriter);

        return stringWriter.toString();
    }
项目:chesspresso    文件:HTMLGameBrowser.java   
private Configuration makeConfiguration(boolean debugMode) {
  final Configuration config = new Configuration();

  config.setIncompatibleImprovements(new Version(2, 3, 20));
  config.setClassForTemplateLoading(HTMLGameBrowser.class, "freemarker");
  config.setDefaultEncoding("UTF-8");

  if (debugMode) {
    config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
  } else {
    config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  }

  return config;
}
项目:restlight    文件:RestServlet.java   
private void initTemplateEngine(ServletConfig config) throws ServletException {

        cfg = new Configuration();

        // Specify the data source where the template files come from. Here I
        // set a
        // plain directory for it, but non-file-system are possible too:
        cfg.setServletContextForTemplateLoading(config.getServletContext(), "/");

        // Specify how templates will see the data-model. This is an advanced
        // topic...
        // for now just use this:
        cfg.setObjectWrapper(new DefaultObjectWrapper());

        // Set your preferred charset template files are stored in. UTF-8 is
        // a good choice in most applications:
        cfg.setDefaultEncoding("UTF-8");

        // Sets how errors will appear. Here we assume we are developing HTML
        // pages.
        // For production systems TemplateExceptionHandler.RETHROW_HANDLER is
        // better.
        cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);

        // At least in new projects, specify that you want the fixes that aren't
        // 100% backward compatible too (these are very low-risk changes as far
        // as the
        // 1st and 2nd version number remains):
        cfg.setIncompatibleImprovements(new Version(2, 3, 20)); // FreeMarker
                                                                // 2.3.20
    }
项目:scipio-erp    文件:ScipioFtlWrappers.java   
public ScipioBasicBeansWrapperImpl(Version incompatibleImprovements, Collection<? extends ScipioModelFactory> customWrapperFactories) {
    super(incompatibleImprovements);
    this.customWrapperFactories = makeCleanFactoryList(customWrapperFactories);
}
项目:scipio-erp    文件:ScipioFtlWrappers.java   
public static ScipioBasicBeansWrapperImpl create(Version incompatibleImprovements) {
    return new ScipioBasicBeansWrapperImpl(incompatibleImprovements, systemWrapperFactories);
}
项目:scipio-erp    文件:ScipioFtlWrappers.java   
public ScipioBasicDefaultObjectWrapperImpl(Version incompatibleImprovements, Collection<? extends ScipioModelFactory> customWrapperFactories) {
    super(incompatibleImprovements);
    this.customWrapperFactories = makeCleanFactoryList(customWrapperFactories);
}
项目:scipio-erp    文件:ScipioFtlWrappers.java   
public static ScipioBasicDefaultObjectWrapperImpl create(Version incompatibleImprovements) {
    return new ScipioBasicDefaultObjectWrapperImpl(incompatibleImprovements, systemWrapperFactories);
}
项目:scipio-erp    文件:ScipioFtlWrappers.java   
public ScipioExtendedBeansWrapperImpl(Version incompatibleImprovements, Collection<? extends ScipioModelFactory> customWrapperFactories, String encodeLang) {
    super(incompatibleImprovements);
    this.customWrapperFactories = makeCleanFactoryList(customWrapperFactories);
    this.encodeLang = encodeLang;
    this.encoder = UtilCodec.getEncoder(this.encodeLang);
}