Java Code Examples for freemarker.template.Configuration#setLocalizedLookup()

The following examples show how to use freemarker.template.Configuration#setLocalizedLookup() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenUtils.java    From camel-kafka-connector with Apache License 2.0 6 votes vote down vote up
public static Template getTemplate(File templateFile) throws IOException {
    Configuration cfg = new Configuration(Configuration.getVersion());

    cfg.setTemplateLoader(new URLTemplateLoader() {
        @Override
        protected URL getURL(String name) {
            try {
                return new URL(name);
            } catch (MalformedURLException e) {
                e.printStackTrace();
                return null;
            }
        }
    });

    cfg.setDefaultEncoding("UTF-8");
    cfg.setLocalizedLookup(false);
    Template template = cfg.getTemplate(templateFile.toURI().toURL().toExternalForm());
    return template;
}
 
Example 2
Source File: LocalFeedTaskProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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;
    }
}
 
Example 3
Source File: FeedTaskProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: Templates.java    From live-chat-engine with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 5
Source File: OutMsgXmlBuilder.java    From jfinal-weixin with Apache License 2.0 5 votes vote down vote up
private static Configuration initFreeMarkerConfiguration() {
	Configuration config = new Configuration();
	StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
	initStringTemplateLoader(stringTemplateLoader);
	config.setTemplateLoader(stringTemplateLoader);
	
	// 模板缓存更新时间,对于OutMsg xml 在类文件中的模板来说已有热加载保障了更新
       config.setTemplateUpdateDelay(999999);
       // - Set an error handler that prints errors so they are readable with
       //   a HTML browser.
       // config.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
       config.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
       
       // - Use beans wrapper (recommmended for most applications)
       config.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
       // - Set the default charset of the template files
       config.setDefaultEncoding(encoding);		// config.setDefaultEncoding("ISO-8859-1");
       // - Set the charset of the output. This is actually just a hint, that
       //   templates may require for URL encoding and for generating META element
       //   that uses http-equiv="Content-type".
       config.setOutputEncoding(encoding);			// config.setOutputEncoding("UTF-8");
       // - Set the default locale
       config.setLocale(Locale.getDefault() /* Locale.CHINA */ );		// config.setLocale(Locale.US);
       config.setLocalizedLookup(false);
       
       // 去掉int型输出时的逗号, 例如: 123,456
       // config.setNumberFormat("#");		// config.setNumberFormat("0"); 也可以
       config.setNumberFormat("#0.#####");
       config.setDateFormat("yyyy-MM-dd");
       config.setTimeFormat("HH:mm:ss");
       config.setDateTimeFormat("yyyy-MM-dd HH:mm:ss");
	return config;
}
 
Example 6
Source File: FreemarkerProcessor.java    From mxjc with MIT License 5 votes vote down vote up
/**
 * Get the freemarker configuration.
 *
 * @return the freemarker configuration.
 */
private Configuration getConfiguration() {
    Configuration configuration = new Configuration();
    configuration.setTemplateLoader(getTemplateLoader());
    configuration.setTemplateExceptionHandler(getTemplateExceptionHandler());
    configuration.setLocalizedLookup(false);
    configuration.setDefaultEncoding("UTF-8");
    return configuration;
}
 
Example 7
Source File: FreemarkerWebServiceDisplayEngine.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
public FreemarkerWebServiceDisplayEngine(JavaNameDisplayStrategy nameDisplayingStrategy) {
	super(nameDisplayingStrategy);
	configuration = new Configuration();
	configuration.setLocalizedLookup(false);
	configuration.setObjectWrapper(new DefaultObjectWrapper());
}
 
Example 8
Source File: FreemarkerTemplateEngine.java    From pippo with Apache License 2.0 4 votes vote down vote up
@Override
public void init(Application application) {
    super.init(application);

    Router router = getRouter();
    PippoSettings pippoSettings = getPippoSettings();

    configuration = new Configuration(Configuration.VERSION_2_3_21);
    configuration.setDefaultEncoding(PippoConstants.UTF8);
    configuration.setOutputEncoding(PippoConstants.UTF8);
    configuration.setLocalizedLookup(true);
    configuration.setClassForTemplateLoading(FreemarkerTemplateEngine.class, getTemplatePathPrefix());

    // We also do not want Freemarker to chose a platform dependent
    // number formatting. Eg "1000" could be printed out by FTL as "1,000"
    // on some platforms.
    // See also:
    // http://freemarker.sourceforge.net/docs/app_faq.html#faq_number_grouping
    configuration.setNumberFormat("0.######"); // now it will print 1000000

    if (pippoSettings.isDev()) {
        configuration.setTemplateUpdateDelayMilliseconds(0); // disable cache
    } else {
        // never update the templates in production or while testing...
        configuration.setTemplateUpdateDelayMilliseconds(Integer.MAX_VALUE);

        // Hold 20 templates as strong references as recommended by:
        // http://freemarker.sourceforge.net/docs/pgui_config_templateloading.html
        configuration.setCacheStorage(new freemarker.cache.MruCacheStorage(20, Integer.MAX_VALUE));
    }

    // set global template variables
    configuration.setSharedVariable("contextPath", new SimpleScalar(router.getContextPath()));
    configuration.setSharedVariable("appPath", new SimpleScalar(router.getApplicationPath()));

    webjarResourcesMethod = new WebjarsAtMethod(router);
    publicResourcesMethod = new PublicAtMethod(router);

    // allow custom initialization
    init(application, configuration);
}