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