当前位置: 首页>>代码示例>>Java>>正文


Java Configuration.setTemplateLoader方法代码示例

本文整理汇总了Java中freemarker.template.Configuration.setTemplateLoader方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setTemplateLoader方法的具体用法?Java Configuration.setTemplateLoader怎么用?Java Configuration.setTemplateLoader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在freemarker.template.Configuration的用法示例。


在下文中一共展示了Configuration.setTemplateLoader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFreemarkerConfiguration

import freemarker.template.Configuration; //导入方法依赖的package包/类
@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;
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:24,代码来源:LocalFeedTaskProcessor.java

示例2: main

import freemarker.template.Configuration; //导入方法依赖的package包/类
public static void main(String[] args) {
    Map<String,Object> tmp = new HashMap<>();
    tmp.put("user","邢天宇");
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
    StringTemplateLoader loader = new StringTemplateLoader();
    loader.putTemplate(NAME,"hello ${user}");
    cfg.setTemplateLoader(loader);
    cfg.setDefaultEncoding("UTF-8");
    try {
        Template template = cfg.getTemplate(NAME);
        StringWriter writer = new StringWriter();
        template.process(tmp,writer);
        System.out.println(writer.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
开发者ID:rpgmakervx,项目名称:slardar,代码行数:19,代码来源:TemplateParser.java

示例3: buildFreemarkerHelper

import freemarker.template.Configuration; //导入方法依赖的package包/类
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);
}
 
开发者ID:sgota,项目名称:tkcg,代码行数:21,代码来源:Generator.java

示例4: init

import freemarker.template.Configuration; //导入方法依赖的package包/类
public void init() throws IOException {
    ClassTemplateLoader ctl = new ClassTemplateLoader(Application.class, "/freemarker");
    MultiTemplateLoader mtl = new MultiTemplateLoader(new TemplateLoader[] {ctl});

    Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
    cfg.setTemplateLoader(mtl);
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);

    Pair<String, Template> clusterResourceQuota = new ImmutablePair<String, Template>("ClusterResourceQuota-ForUser", cfg.getTemplate("ClusterResourceQuota-ForUser.ftlh"));
    Pair<String, Template> bestEffortResourceLimits = new ImmutablePair<String, Template>("LimitRange-BestEffortResourceLimits", cfg.getTemplate("LimitRange-BestEffortResourceLimits.ftlh"));
    Pair<String, Template> burstableResourceLimits = new ImmutablePair<String, Template>("LimitRange-BurstableResourceLimits", cfg.getTemplate("LimitRange-BurstableResourceLimits.ftlh"));
    Pair<String, Template> maxImageCounts = new ImmutablePair<String, Template>("LimitRange-MaxImageCounts", cfg.getTemplate("LimitRange-MaxImageCounts.ftlh"));
    Pair<String, Template> bestEffort = new ImmutablePair<String, Template>("ResourceQuota-BestEffort", cfg.getTemplate("ResourceQuota-BestEffort.ftlh"));
    Pair<String, Template> notTerminatingAndNotBestEffort = new ImmutablePair<String, Template>("ResourceQuota-NotTerminating-And-NotBestEffort",
                                                                              cfg.getTemplate("ResourceQuota-NotTerminating-And-NotBestEffort.ftlh"));
    Pair<String, Template> terminating = new ImmutablePair<String, Template>("ResourceQuota-Terminating", cfg.getTemplate("ResourceQuota-Terminating.ftlh"));

    templates = Arrays.asList(clusterResourceQuota, bestEffortResourceLimits, burstableResourceLimits, maxImageCounts, bestEffort, notTerminatingAndNotBestEffort, terminating);
}
 
开发者ID:garethahealy,项目名称:quota-limits-generator,代码行数:22,代码来源:YamlTemplateProcessor.java

示例5: createRouteBuilder

import freemarker.template.Configuration; //导入方法依赖的package包/类
protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {
        public void configure() throws Exception {
            FreemarkerEndpoint endpoint = new FreemarkerEndpoint();
            endpoint.setCamelContext(context);
            endpoint.setResourceUri("org/apache/camel/component/freemarker/example.ftl");

            Configuration configuraiton = new Configuration();
            configuraiton.setTemplateLoader(new ClassTemplateLoader(Resource.class, "/"));
            endpoint.setConfiguration(configuraiton);

            context.addEndpoint("free", endpoint);

            from("direct:a").to("free");
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:FreemarkerEndpointTest.java

示例6: getConfigurationByDirectory

import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
 * 根据模板的路径,获取一个配置文件
 * @author [email protected]
 * @param templateLoadingPath
 * @return
 */
public static Configuration getConfigurationByDirectory(File templateLoadingPath)
{
    try
    {
        Configuration configuration = new Configuration(Configuration.VERSION_2_3_25);
        
        //以下这两种设置方式是等价的
        //            configuration.setDirectoryForTemplateLoading(templateLoadingPath);
        configuration.setTemplateLoader(new FileTemplateLoader(templateLoadingPath));
        
        configuration.setObjectWrapper(new DefaultObjectWrapper(Configuration.VERSION_2_3_25));
        configuration.setDefaultEncoding(CharEncoding.UTF_8);
        configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
        configuration.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25).build());
        return configuration;
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:lnwazg,项目名称:kit,代码行数:29,代码来源:FreeMkKit.java

示例7: configuration

import freemarker.template.Configuration; //导入方法依赖的package包/类
@Singleton
@Provides
public static Configuration configuration(LinkHelper linkHelper, MultiTemplateLoader templateLoader) {
    try {
        freemarker.log.Logger.selectLoggerLibrary(Logger.LIBRARY_SLF4J);
        Configuration cfg = new freemarker.template.Configuration(Configuration.VERSION_2_3_25);
        cfg.setTagSyntax(freemarker.template.Configuration.SQUARE_BRACKET_TAG_SYNTAX);
        cfg.setLazyAutoImports(true);
        cfg.setLocale(Locale.GERMANY); // todo make configurable
        cfg.addAutoImport("saito", "saito.ftl");
        cfg.setSharedVariable("saitoLinkHelper", linkHelper);
        cfg.setDefaultEncoding("UTF-8");
        cfg.setLogTemplateExceptions(false);
        cfg.setTemplateLoader(templateLoader);
        return cfg;
    } catch (TemplateModelException | ClassNotFoundException e) {
        log.error("Error creating config", e);
        throw new IllegalStateException(e);
    }
}
 
开发者ID:marcobehler,项目名称:saito,代码行数:21,代码来源:FreemarkerModule.java

示例8: __processTemplate

import freemarker.template.Configuration; //导入方法依赖的package包/类
protected static String __processTemplate(TemplateLoader templateLoader, String templateName,
                                          Map<String, ?> parameterValues) {
    Map<String, Object> params = prepareParams(parameterValues);

    final StringWriter writer = new StringWriter();

    try {
        final Configuration configuration = new Configuration();
        configuration.setTemplateLoader(templateLoader);
        final Template template = configuration.getTemplate(templateName);
        template.process(params, writer);

        return writer.toString();
    } catch (Throwable e) {
        throw new RuntimeException("Unable to process template", e);
    }
}
 
开发者ID:cuba-platform,项目名称:cuba,代码行数:18,代码来源:TemplateHelper.java

示例9: simpleCfg

import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
 * 创建默认配置的{@link Configuration}实例
 * @return
 */
public static Configuration simpleCfg() throws TemplateException {
	Configuration cfg = new Configuration(Configuration.VERSION_2_3_24);
	cfg.setDefaultEncoding("UTF-8");
	cfg.setSetting("locale", "zh_CN");
	//cfg.setSetting("template_update_delay", "3600");
	cfg.setSetting("classic_compatible", "true");
	cfg.setSetting("number_format", "#.##");
	cfg.setSetting("tag_syntax", "auto_detect");
	cfg.setTemplateLoader(new ClassTemplateLoader(Freemarkers.class, "/"));
	
	//因classic_compatible=true且对象的Date类型属性为null时,表达式${obj.birth?datetime}会抛异常,所以自定义格式化
	Map<String, TemplateDateFormatFactory> customDateFormats = new HashMap<>();
	customDateFormats.put("date", JavaTemplateDateFormatFactory.INSTANCE);
	cfg.setCustomDateFormats(customDateFormats);
	
	cfg.setSetting("datetime_format", "@date yyyy-MM-dd HH:mm:ss");
	cfg.setSetting("date_format", "@date yyyy-MM-dd");
	cfg.setSetting("time_format", "@date HH:mm:ss");
	return cfg;
}
 
开发者ID:easycodebox,项目名称:easycode,代码行数:25,代码来源:Freemarkers.java

示例10: before

import freemarker.template.Configuration; //导入方法依赖的package包/类
public void before() {
	configuration = new Configuration(Configuration.VERSION_2_3_23);
	// configuration.setObjectWrapper(new
	// DefaultObjectWrapper(Configuration.VERSION_2_3_23));
	try {
		// File resource = ResourceUtils.getResourceAsFile("/");
		// logger.debug("path:" + resource.getAbsolutePath());
		StringTemplateLoader templateLoader = new StringTemplateLoader();
		configuration.setTemplateLoader(templateLoader);
		Resource[] resources = ResourceUtils.getResources("classpath*:/template/*.ftl");
		for (Resource resource : resources) {
			String fileName = resource.getFilename();
			String value = IOUtils.toString(resource.getInputStream());
			templateLoader.putTemplate(fileName, value);
		}
		// templateLoader.putTemplate();
		
		// configuration.setDirectoryForTemplateLoading(resource);
	} catch (IOException e) {
		logger.error(e.getMessage(), e);
	}
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:23,代码来源:GeneratorConfig.java

示例11: getFreemarkerConfiguration

import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
 * Creates freemarker configuration settings,
 * default output format to trigger auto-escaping policy
 * and template loaders.
 *
 * @param servletContext servlet context
 * @return freemarker configuration settings
 */
private Configuration getFreemarkerConfiguration(ServletContext servletContext) {
  Configuration configuration = new Configuration(Configuration.VERSION_2_3_26);
  configuration.setOutputFormat(HTMLOutputFormat.INSTANCE);

  List<TemplateLoader> loaders = new ArrayList<>();
  loaders.add(new WebappTemplateLoader(servletContext));
  loaders.add(new ClassTemplateLoader(DrillRestServer.class, "/"));
  try {
    loaders.add(new FileTemplateLoader(new File("/")));
  } catch (IOException e) {
    logger.error("Could not set up file template loader.", e);
  }
  configuration.setTemplateLoader(new MultiTemplateLoader(loaders.toArray(new TemplateLoader[loaders.size()])));
  return configuration;
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:24,代码来源:DrillRestServer.java

示例12: doRender

import freemarker.template.Configuration; //导入方法依赖的package包/类
private void doRender(@NotNull File outputRootPath,
                      @NotNull File moduleRootPath,
                      @NotNull Map<String, Object> args,
                      @Nullable Project project,
                      boolean gradleSyncIfNeeded) {
  myFilesToOpen.clear();
  if (project == null) {
    // Project creation: no current project to read code style settings from yet, so use defaults
    project = ProjectManagerEx.getInstanceEx().getDefaultProject();
  }
  myProject = project;

  Map<String, Object> paramMap = createParameterMap(args);
  enforceParameterTypes(getMetadata(), args);
  Configuration freemarker = new FreemarkerConfiguration();
  freemarker.setTemplateLoader(myLoader);

  processFile(freemarker, new File(TEMPLATE_XML_NAME), paramMap, outputRootPath, moduleRootPath, gradleSyncIfNeeded);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:Template.java

示例13: PluginStatusReportViewBuilder

import freemarker.template.Configuration; //导入方法依赖的package包/类
private PluginStatusReportViewBuilder() throws IOException {
    configuration = new Configuration(Configuration.VERSION_2_3_23);
    configuration.setTemplateLoader(new ClassTemplateLoader(getClass(), "/"));
    configuration.setDefaultEncoding("UTF-8");
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    configuration.setLogTemplateExceptions(false);
    configuration.setDateTimeFormat("iso");
}
 
开发者ID:gocd,项目名称:kubernetes-elastic-agents,代码行数:9,代码来源:PluginStatusReportViewBuilder.java

示例14: getFreemarkerConfiguration

import freemarker.template.Configuration; //导入方法依赖的package包/类
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;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:16,代码来源:FeedTaskProcessor.java

示例15: getStringConfig

import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:37,代码来源:FreeMarkerProcessor.java


注:本文中的freemarker.template.Configuration.setTemplateLoader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。