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


Java Template.process方法代碼示例

本文整理匯總了Java中freemarker.template.Template.process方法的典型用法代碼示例。如果您正苦於以下問題:Java Template.process方法的具體用法?Java Template.process怎麽用?Java Template.process使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在freemarker.template.Template的用法示例。


在下文中一共展示了Template.process方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: service

import freemarker.template.Template; //導入方法依賴的package包/類
@Override
public void service(ServletRequest servletRequest, ServletResponse response) throws ServletException, IOException {
  ClientSettings settings = new ClientSettings(
      options.getOption(SupportService.SUPPORT_EMAIL_ADDR),
      options.getOption(SupportService.SUPPORT_EMAIL_SUBJECT),
      options.getOption(SupportService.OUTSIDE_COMMUNICATION_DISABLED),
      options.getOption(AccelerationOptions.ENABLE_SUBHOUR_POLICIES),
      options.getOption(UIOptions.ALLOW_LOWER_PROVISIONING_SETTINGS),
      options.getOption(UIOptions.TABLEAU_TDS_MIMETYPE));

  String environment = config.allowTestApis ? "DEVELOPMENT" : "PRODUCTION";
  final ServerData indexConfig = new ServerData(environment, serverHealthMonitor, config.getConfig(), settings, getVersionInfo(), supportService.getClusterId().getIdentity());

  Template tmp = templateCfg.getTemplate("/index.html");

  response.setContentType("text/html; charset=utf-8");
  OutputStreamWriter outputWriter = new OutputStreamWriter(response.getOutputStream());
  try {
    tmp.process(ImmutableMap.of("dremio", indexConfig), outputWriter);
    outputWriter.flush();
    outputWriter.close();
  } catch (TemplateException e) {
    throw new IOException("Error rendering index.html template", e);
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:26,代碼來源:IndexServlet.java

示例2: render

import freemarker.template.Template; //導入方法依賴的package包/類
@Override
public void render(final HttpServletRequest request, final HttpServletResponse response) {
	response.setContentType("text/html");
	response.setCharacterEncoding("UTF-8");

	try {
		final Template template = ConsoleRenderer.TEMPLATE_CFG.getTemplate("kill-browser.ftl");

		final PrintWriter writer = response.getWriter();

		final StringWriter stringWriter = new StringWriter();

		template.setOutputEncoding("UTF-8");
		template.process(getDataModel(), stringWriter);

		final String pageContent = stringWriter.toString();

		writer.write(pageContent);
		writer.flush();
		writer.close();
	} catch (final Exception e) {
		try {
			response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		} catch (final IOException ex) {
			logger.error("Can not sned error 500!", ex);
		}
	}
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:29,代碼來源:IndexProcessor.java

示例3: getText

import freemarker.template.Template; //導入方法依賴的package包/類
public String getText(String templateId, Map<Object, Object> parameters) {
	String templateFile = templateId + SUFFIX;
	try {
		Template template = TEMPLATE_CACHE.get(templateFile);
		if(template == null){
			template = configuration.getTemplate(templateFile);
			TEMPLATE_CACHE.put(templateFile, template);
		}
		StringWriter stringWriter = new StringWriter();
		template.process(parameters, stringWriter);
		return stringWriter.toString();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:wrayzheng,項目名稱:webpage-update-subscribe,代碼行數:16,代碼來源:FreemarkerEmailTemplateService.java

示例4: allSignatures

import freemarker.template.Template; //導入方法依賴的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

示例5: getViewContent

import freemarker.template.Template; //導入方法依賴的package包/類
/**
 * Gets view content of a plugin. The content is processed with the
 * specified data model by template engine.
 *
 * @param dataModel
 *            the specified data model
 * @return plugin view content
 */
private String getViewContent(final Map<String, Object> dataModel) {
	if (null == configuration) {
		initTemplateEngineCfg();
	}

	try {
		final Template template = configuration.getTemplate("plugin.ftl");
		final StringWriter sw = new StringWriter();

		template.process(dataModel, sw);

		return sw.toString();
	} catch (final Exception e) {
		// This plugin has no view

		return "";
	}
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:27,代碼來源:AbstractPlugin.java

示例6: generatorHtml

import freemarker.template.Template; //導入方法依賴的package包/類
public void generatorHtml(String dir, String htmlName, String templateFile, String attrName, Object attrValue) {
  try {
    if (StringUtils.isEmpty(htmlName)) htmlName = "index.html";
    fileUtil.mkdirs(dir);
    File staticFile = fileUtil.createFile(dir + "/" + htmlName);

    FileOutputStream outStream = new FileOutputStream(staticFile);
    OutputStreamWriter writer = new OutputStreamWriter(outStream, "UTF-8");
    BufferedWriter sw = new BufferedWriter(writer);

    Map rootMap = new HashMap();
    if (!StringUtils.isEmpty(attrName)) rootMap.put(attrName, attrValue);

    Template template = configuration.getTemplate(siteConfig.getTheme() + "/" + templateFile);
    template.process(rootMap, sw);
    sw.flush();
    sw.close();
    outStream.close();
  } catch (IOException | TemplateException e) {
    e.printStackTrace();
  }
}
 
開發者ID:tomoya92,項目名稱:pyblog,代碼行數:23,代碼來源:GeneratorHtml.java

示例7: getComments

import freemarker.template.Template; //導入方法依賴的package包/類
/**
 * 獲取評論
 * @param map 模板參數
 * @param node  節點ID
 * @return
 */
private String[] getComments(Map<String, Object> map, EnumNode node) {
    // 1. 模板引擎解析
    try {
        StringWriter stringWriter = new StringWriter();
        Template template = templates.get(node);
        if (template != null){
            template.process(map, stringWriter);

            String comment = stringWriter.toString();
            stringWriter.close();

            // 需要先清理字符串
            return comment.replaceFirst("^[\\s\\t\\r\\n]*", "").replaceFirst("[\\s\\t\\r\\n]*$", "").split("\n");
        }

    } catch (Exception e) {
        logger.error("freemarker 解析失敗!", e);
    }

    return null;
}
 
開發者ID:itfsw,項目名稱:mybatis-generator-plugin,代碼行數:28,代碼來源:TemplateCommentGenerator.java

示例8: renderStr

import freemarker.template.Template; //導入方法依賴的package包/類
/**
 * 獲取渲染之後的字符串
 * @param content 渲染的字符串
 * @param data 模板中渲染的參數
 * @return 返回結果
 */
public static String renderStr(String content,Map<String,Object> data){
    String result = null;
    try {
        Template t = new Template(null,new StringReader(content),null);
        StringWriter writer = new StringWriter();
        t.process(data,writer);
        result = writer.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
 
開發者ID:javahaohao,項目名稱:gen_code,代碼行數:19,代碼來源:FreeMarkerUtil.java

示例9: getPage

import freemarker.template.Template; //導入方法依賴的package包/類
String getPage(String filename, Map<String, Object> data) throws IOException {
    try (Writer stream = new StringWriter();) {
        Template template = configuration.getTemplate(filename);
        template.process(data, stream);
        return stream.toString();
    } catch (TemplateException e) {
        throw new IOException(e);
    }
}
 
開發者ID:vitaly-chibrikov,項目名稱:otus_java_2017_04,代碼行數:10,代碼來源:TemplateProcessor.java

示例10: testSpeedOfFreemarker

import freemarker.template.Template; //導入方法依賴的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

示例11: processIndexPageTemplate

import freemarker.template.Template; //導入方法依賴的package包/類
private void processIndexPageTemplate(ProjectDescriptor projectDescriptor, CustomData customData) throws IOException, URISyntaxException, TemplateException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
    cfg.setClassLoaderForTemplateLoading(getClass().getClassLoader(), "template");
    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
    cfg.setLogTemplateExceptions(false);
    Map<String, Object> root = new HashMap<String, Object>();
    root.put("project", projectDescriptor);
    root.put("customData", customData);
    Template template = cfg.getTemplate("index.ftl");
    template.process(root, new FileWriter(new File(outputDir, "index.html")));
}
 
開發者ID:gradle-guides,項目名稱:gradle-site-plugin,代碼行數:13,代碼來源:FreemarkerSiteGenerator.java

示例12: buildReport

import freemarker.template.Template; //導入方法依賴的package包/類
private String buildReport(ITestContext test) {
	try {
		InputStream is = HtmlReporter.class.getResourceAsStream(REPORT_TEMPLATE);
		Configuration cfg = new Configuration(Configuration.getVersion());
		Template template = new Template("Report", new InputStreamReader(is), cfg);
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("context", test);
		StringWriter writer = new StringWriter();
		template.process(parameters, writer);
		return writer.toString();
	} catch (Exception e) {
		log.error("Build Report error", e);
		return "Exception: " + e.getMessage();
	}
}
 
開發者ID:21ca,項目名稱:selenium-testng-template,代碼行數:16,代碼來源:HtmlReporter.java

示例13: processTemplate

import freemarker.template.Template; //導入方法依賴的package包/類
public static File processTemplate(File template) throws IOException, TemplateException {
    Configuration config = new Configuration();
    config.setDirectoryForTemplateLoading(template.getParentFile());
    config.setObjectWrapper(new DefaultObjectWrapper());
    config.setDefaultEncoding("UTF-8");
    Template temp = config.getTemplate(template.getName());
    String child = template.getName() + RandomStringUtils.randomAlphanumeric(8);
    File fileOutput = new File(template.getParentFile(), child);
    Writer fileWriter = new FileWriter(fileOutput);
    Map<Object, Object> currentSession = Thucydides.getCurrentSession();
    temp.process(currentSession, fileWriter);
    return fileOutput;
}
 
開發者ID:tapack,項目名稱:satisfy,代碼行數:14,代碼來源:TemplateUtils.java

示例14: processToFile

import freemarker.template.Template; //導入方法依賴的package包/類
/**
 * Process to file.
 *
 * @param model model
 * @param templateName templateName
 * @param targetFile targetFile
 * @param encoding encoding
 * @throws IOException io exception
 */
public void processToFile(Map model, String templateName, File targetFile, String encoding) throws IOException {
    Template template = configuration.getTemplate(templateName);
    Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(targetFile), encoding));
    try {
        template.process(model, out);
    } catch (TemplateException e) {
        throw new GeneratorException("處理文件模板出錯:" + e.getMessage());
    }
    out.close();
}
 
開發者ID:sgota,項目名稱:tkcg,代碼行數:20,代碼來源:FreemarkerHelper.java

示例15: writeImportableFile

import freemarker.template.Template; //導入方法依賴的package包/類
private void writeImportableFile(final HippoImportableItem importableItem,
                                        final String fileName,
                                        final Path targetDir) {

    try {

        Path targetFilePath = Paths.get(targetDir.toString(), fileName);

        final String itemTypeName = importableItem.getClass().getSimpleName().toLowerCase();

        final Template template = getFreemarkerConfiguration()
            .getTemplate(itemTypeName + ".json.ftl");

        final Writer writer = new StringWriter();

        template.process(new HashMap<String, Object>(){{
            put(itemTypeName, importableItem);
        }}, writer);

        final String importableFileContent = writer.toString();

        logger.debug("Writing file {}", fileName);

        Files.write(targetFilePath, importableFileContent.getBytes());

    } catch (final Exception e) {
        // If we fail with one file, make a note of the document that failed and carry on
        migrationReport.logError(e, "Failed to write out item:", "Item will not be imported", importableItem.toString());

        if (importableItem instanceof DataSet) {
            migrationReport.report(((DataSet) importableItem).getPCode(), DATASET_IMPORT_FILE_FAILURE);
        }
    }
}
 
開發者ID:NHS-digital-website,項目名稱:hippo,代碼行數:35,代碼來源:ImportableFileWriter.java


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