當前位置: 首頁>>代碼示例>>Java>>正文


Java Configuration.getTemplate方法代碼示例

本文整理匯總了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);
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:22,代碼來源:ThriftFileBuilder.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: 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");
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:DaoGenerator.java

示例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");
}
 
開發者ID:wolfboys,項目名稱:opencron,代碼行數:9,代碼來源:NoticeService.java

示例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");
}
 
開發者ID:xsingHu,項目名稱:xs-android-architecture,代碼行數:20,代碼來源:DaoGenerator.java

示例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;
}
 
開發者ID:chenshuiluke,項目名稱:jresume,代碼行數:21,代碼來源:ResumeGenerator.java

示例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
}
 
開發者ID:blackarbiter,項目名稱:Android_Code_Arbiter,代碼行數:10,代碼來源:FreemarkerUsage.java

示例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();
    }
}
 
開發者ID:lnwazg,項目名稱:kit,代碼行數:19,代碼來源:TestFreemarker.java

示例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;
}
 
開發者ID:bill1012,項目名稱:AdminEAP,代碼行數:28,代碼來源:FreeMarkerUtil.java

示例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);
}
 
開發者ID:garethahealy,項目名稱:quota-limits-generator,代碼行數:22,代碼來源:YamlTemplateProcessor.java

示例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;
}
 
開發者ID:xiaomoinfo,項目名稱:SpringBootUnity,代碼行數:29,代碼來源:MailUtil.java

示例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);
     }
 }
 
開發者ID:broadinstitute,項目名稱:barclay,代碼行數:28,代碼來源:HelpDoclet.java

示例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);
    }
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:18,代碼來源:TemplateHelper.java

示例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();
}
 
開發者ID:davetcc,項目名稱:hugojoomla,代碼行數:23,代碼來源:JoomlaHugoConverter.java

示例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();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:13,代碼來源:SpeedTest.java


注:本文中的freemarker.template.Configuration.getTemplate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。