本文整理匯總了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;
}
}
示例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();
}
}
示例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);
}
示例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);
}
示例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");
}
};
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例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");
}
示例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;
}
示例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;
}