本文整理汇总了Java中freemarker.template.Configuration.getTemplate方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.getTemplate方法的具体用法?Java Configuration.getTemplate怎么用?Java Configuration.getTemplate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类freemarker.template.Configuration
的用法示例。
在下文中一共展示了Configuration.getTemplate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildToOutputStream
import freemarker.template.Configuration; //导入方法依赖的package包/类
public void buildToOutputStream(Class<?> commonServiceClass, OutputStream os) throws Exception {
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
cfg.setClassForTemplateLoading(ThriftFileBuilder.class, "/");
Template template = cfg.getTemplate("templates/thrift/thrift.ftl");
Writer out = new OutputStreamWriter(os);
ThriftServiceBuilder serviceBuilder = new ThriftServiceBuilder(commonServiceClass);
ThriftService service = serviceBuilder.buildThriftService();
Map<String, Object> rootMap = new HashMap<String, Object>();
rootMap.put("thriftServicePackage", this.getPackageName(commonServiceClass));
List<ThriftStruct> structs = serviceBuilder.getStructs();
List<ThriftEnum> enums = serviceBuilder.getEnums();
CommonUtils.removeRepeat(structs);
rootMap.put("structList", structs);
rootMap.put("enumList", enums);
CommonUtils.removeRepeat(enums);
rootMap.put("serviceList", Arrays.asList(service));
template.process(rootMap, out);
}
示例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: DaoGenerator
import freemarker.template.Configuration; //导入方法依赖的package包/类
public DaoGenerator() throws IOException {
System.out.println("greenDAO Generator");
System.out.println("Copyright 2011-2016 Markus Junginger, greenrobot.de. Licensed under GPL V3.");
System.out.println("This program comes with ABSOLUTELY NO WARRANTY");
patternKeepIncludes = compilePattern("INCLUDES");
patternKeepFields = compilePattern("FIELDS");
patternKeepMethods = compilePattern("METHODS");
Configuration config = getConfiguration("dao.ftl");
templateDao = config.getTemplate("dao.ftl");
templateDaoMaster = config.getTemplate("dao-master.ftl");
templateDaoSession = config.getTemplate("dao-session.ftl");
templateEntity = config.getTemplate("entity.ftl");
templateDaoUnitTest = config.getTemplate("dao-unit-test.ftl");
templateContentProvider = config.getTemplate("content-provider.ftl");
}
示例4: initConfig
import freemarker.template.Configuration; //导入方法依赖的package包/类
@PostConstruct
public void initConfig() throws Exception {
Configuration configuration = new Configuration();
File file = new File(servletContext.getRealPath("/WEB-INF/layouts"));
configuration.setDirectoryForTemplateLoading(file);
configuration.setDefaultEncoding("UTF-8");
this.template = configuration.getTemplate("email.template");
}
示例5: DaoGenerator
import freemarker.template.Configuration; //导入方法依赖的package包/类
public DaoGenerator() throws IOException {
System.out.println("greenDAO Generator");
System.out.println("Copyright 2011-2016 Markus Junginger, greenrobot.de. Licensed under GPL V3.");
System.out.println("This program comes with ABSOLUTELY NO WARRANTY");
patternKeepIncludes = compilePattern("INCLUDES");
patternKeepFields = compilePattern("FIELDS");
patternKeepMethods = compilePattern("METHODS");
Configuration config = new Configuration(Configuration.VERSION_2_3_23);
config.setClassForTemplateLoading(this.getClass(), "/");
templateDao = config.getTemplate("dao.ftl");
templateDaoMaster = config.getTemplate("dao-master.ftl");
templateDaoSession = config.getTemplate("dao-session.ftl");
templateEntity = config.getTemplate("entity.ftl");
templateDaoUnitTest = config.getTemplate("dao-unit-test.ftl");
templateContentProvider = config.getTemplate("content-provider.ftl");
}
示例6: generateResumeHTML
import freemarker.template.Configuration; //导入方法依赖的package包/类
private String generateResumeHTML(String json, String theme) throws Exception {
if (!isValidJSON(json)) {
throw new InvalidJSONException();
}
Gson gson = new GsonBuilder().setPrettyPrinting().create();
Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
cfg.setDirectoryForTemplateLoading(new File("themes"));
cfg.setDefaultEncoding("UTF-8");
Template temp = cfg.getTemplate(theme + ".html");
//System.out.println(json);
Resume resume = gson.fromJson(json, Resume.class);
resume.getRidOfArraysWithEmptyElements();
resume.setConfig(config);
StringWriter htmlStringWriter = new StringWriter();
temp.process(resume, htmlStringWriter);
String html = htmlStringWriter.toString();
return html;
}
示例7: allSignatures
import freemarker.template.Configuration; //导入方法依赖的package包/类
public void allSignatures(String inputFile) throws IOException, TemplateException {
Configuration cfg = new Configuration();
Template template = cfg.getTemplate(inputFile);
Map<String, Object> data = new HashMap<String, Object>();
template.process(data, new OutputStreamWriter(System.out)); //TP
template.process(data, new OutputStreamWriter(System.out), null); //TP
template.process(data, new OutputStreamWriter(System.out), null, null); //TP
}
示例8: testClassTemplateLoader
import freemarker.template.Configuration; //导入方法依赖的package包/类
@TestCase
void testClassTemplateLoader()
{
try
{
//创建一个合适的Configration对象
Configuration configuration = FreeMkKit.getConfigurationByClass(TestFreemarker.class, "");
Template template = configuration.getTemplate("1.ftl");
String result = FreeMkKit.format(template, "student", Maps.asMap("studentName", "张三丰2", "studentSex", "男"), "description", "这是老子的描述信息", "nameList", Lists.asList("陈靖仇", "bbb", "ccc"), "weaponMap", Maps.asMap("ttt", "ttt", "sss", "sss"));
System.out.println(result);
//template.process(m, new OutputStreamWriter(new FileOutputStream("success.html"), "UTF-8"));
//System.out.println("恭喜,生成成功~~");
}
catch (Exception e)
{
e.printStackTrace();
}
}
示例9: getTemplate
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
* 获取模板
*
* @param templateName
* 模板名称(含后缀名)
* @return Template
* @throws IOException
*/
public static Template getTemplate(String templateName) throws IOException {
Configuration cfg = new Configuration();
Template temp = null;
File tmpRootFile = getResource(templateName).getFile().getParentFile();
if (tmpRootFile == null) {
throw new RuntimeException("无法取得模板根路径!");
}
try {
cfg.setDefaultEncoding("utf-8");
cfg.setOutputEncoding("utf-8");
cfg.setDirectoryForTemplateLoading(tmpRootFile);
/* cfg.setDirectoryForTemplateLoading(getResourceURL()); */
cfg.setObjectWrapper(new DefaultObjectWrapper());
temp = cfg.getTemplate(templateName);
} catch (IOException e) {
e.printStackTrace();
}
return temp;
}
示例10: 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);
}
示例11: getContent
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
* 返回激活链接
*
* @param email email
* @return 有3个参数 email password
*/
public static String getContent(String email, String password, Configuration configuration) {
Long now = TimeUtil.getNowOfMills();
Map<String, Object> data = new HashMap<>(10);
StringBuilder sb = new StringBuilder("http://localhost:8080/user/validate?email=");
sb.append(email);
sb.append("&password=");
sb.append(password);
sb.append("&time=");
sb.append(now);
data.put("email", email);
data.put("url", sb.toString());
data.put("now", TimeUtil.getFormatDate(now, TimeUtil.DEFAULT_FORMAT));
Template template;
String readyParsedTemplate = null;
try {
template = configuration.getTemplate("email.ftl");
readyParsedTemplate = FreeMarkerTemplateUtils.processTemplateIntoString(template, data);
} catch (Exception e) {
e.printStackTrace();
}
return readyParsedTemplate;
}
示例12: processIndexTemplate
import freemarker.template.Configuration; //导入方法依赖的package包/类
/**
* Create the php index listing all of the Docs features
*
* @param cfg
* @param workUnitList
* @param groupMaps
* @throws IOException
*/
protected void processIndexTemplate(
final Configuration cfg,
final List<DocWorkUnit> workUnitList,
final List<Map<String, String>> groupMaps
) throws IOException {
// Get or create a template and merge in the data
final Template template = cfg.getTemplate(getIndexTemplateName());
final File indexFile = new File(getDestinationDir(),
getIndexBaseFileName() + '.' + getIndexFileExtension()
);
try (final FileOutputStream fileOutStream = new FileOutputStream(indexFile);
final OutputStreamWriter outWriter = new OutputStreamWriter(fileOutStream)) {
template.process(groupIndexMap(workUnitList, groupMaps), outWriter);
} catch (TemplateException e) {
throw new DocException("Freemarker Template Exception during documentation index creation", e);
}
}
示例13: __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);
}
}
示例14: JoomlaHugoConverter
import freemarker.template.Configuration; //导入方法依赖的package包/类
public JoomlaHugoConverter(NastyContentChecker nastyContentChecker,
JdbcTemplate template, String pathToOutput, String dbExtension,
boolean buildTags) throws IOException {
this.dbExtension = dbExtension;
this.nastyContentChecker = nastyContentChecker;
this.template = template;
this.pathToOutput = pathToOutput;
this.buildTags = buildTags;
Configuration cfg = new Configuration(Configuration.getVersion());
cfg.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(), "/");
cfg.setDefaultEncoding("UTF-8");
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
cfg.setLogTemplateExceptions(false);
categoryTemplate = cfg.getTemplate("categoryPage.toml.ftl");
contentTemplate = cfg.getTemplate("defaultPage.toml.ftl");
buildTags();
}
示例15: testSpeedOfFreemarker
import freemarker.template.Configuration; //导入方法依赖的package包/类
public void testSpeedOfFreemarker() throws Exception {
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(getWorkDir());
cfg.setObjectWrapper(new BeansWrapper());
Template templ = cfg.getTemplate("template.txt");
for(int i = 0; i < whereTo.length; i++) {
Writer out = new BufferedWriter(new FileWriter(whereTo[i]));
templ.process(parameters, out);
out.close();
}
}