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


Java Template類代碼示例

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


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

示例1: main

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

示例2: 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

示例3: shouldBuildStatusReportView

import freemarker.template.Template; //導入依賴的package包/類
@Test
public void shouldBuildStatusReportView() throws Exception {
    NodeOperationsImpl nodes = mock(NodeOperationsImpl.class);
    PodOperationsImpl pods = mock(PodOperationsImpl.class);

    when(nodes.list()).thenReturn(new NodeList());
    when(kubernetesClient.nodes()).thenReturn(nodes);

    when(pods.inNamespace(Constants.KUBERNETES_NAMESPACE_KEY)).thenReturn(pods);
    when(pods.withLabel(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID)).thenReturn(pods);
    when(pods.list()).thenReturn(new PodList());
    when(kubernetesClient.pods()).thenReturn(pods);

    final PluginStatusReportViewBuilder builder = mock(PluginStatusReportViewBuilder.class);
    final Template template = mock(Template.class);

    when(builder.getTemplate("status-report.template.ftlh")).thenReturn(template);
    when(builder.build(eq(template), any(KubernetesCluster.class))).thenReturn("status-report");

    final GoPluginApiResponse response = new StatusReportExecutor(pluginRequest, kubernetesClientFactory, builder).execute();

    assertThat(response.responseCode(), is(200));
    assertThat(response.responseBody(), is("{\"view\":\"status-report\"}"));
}
 
開發者ID:gocd,項目名稱:kubernetes-elastic-agents,代碼行數:25,代碼來源:StatusReportExecutorTest.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: genHTML

import freemarker.template.Template; //導入依賴的package包/類
/**
	 * Processes the specified FreeMarker template with the specified request,
	 * data model.
	 *
	 * @param request
	 *            the specified request
	 * @param dataModel
	 *            the specified data model
	 * @param template
	 *            the specified FreeMarker template
	 * @return generated HTML
	 * @throws Exception
	 *             exception
	 */
	protected String genHTML(final HttpServletRequest request, final Map<String, Object> dataModel,
			final Template template) throws Exception {
		final StringWriter stringWriter = new StringWriter();

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

		final StringBuilder pageContentBuilder = new StringBuilder(stringWriter.toString());

		final long endimeMillis = System.currentTimeMillis();
		final String dateString = DateFormatUtils.format(endimeMillis, "yyyy/MM/dd HH:mm:ss");
//		final long startTimeMillis = (Long) request.getAttribute(Keys.HttpRequest.START_TIME_MILLIS);
		final long startTimeMillis = System.currentTimeMillis();
		final String msg = String.format("<!-- Generated by B3log Latke(%1$d ms), %2$s -->",
				endimeMillis - startTimeMillis, dateString);

		pageContentBuilder.append(msg);

		return pageContentBuilder.toString();
	}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:35,代碼來源:AbstractFreeMarkerRenderer.java

示例6: 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

示例7: 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

示例8: hasExpression

import freemarker.template.Template; //導入依賴的package包/類
/**
 * Determines whether the specified expression exists in the specified
 * element (includes its children) of the specified template.
 * 
 * @param template
 *            the specified template
 * @param expression
 *            the specified expression
 * @param templateElement
 *            the specified element
 * @return {@code true} if it exists, returns {@code false} otherwise
 */
private static boolean hasExpression(final Template template, final String expression,
		final TemplateElement templateElement) {
	final String canonicalForm = templateElement.getCanonicalForm();

	if (canonicalForm.startsWith(expression)) {
		logger.trace("Template has expression[nodeName={}, expression={}]",
				new Object[] { templateElement.getNodeName(), expression });

		return true;
	}

	@SuppressWarnings("unchecked")
	final Enumeration<TemplateElement> children = templateElement.children();

	while (children.hasMoreElements()) {
		final TemplateElement nextElement = children.nextElement();

		if (hasExpression(template, expression, nextElement)) {
			return true;
		}
	}

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

示例9: process

import freemarker.template.Template; //導入依賴的package包/類
/**
 * @param templateString
 *            模板字符串
 * @param args
 *            參數
 * @return
 */
public static String process(String templateString, Map<String, Object> args) {
    try {
        if (templateString == null) {
            return null;
        }
        String key = "template_" + templateString.hashCode();
        if (stringTemplateLoader.findTemplateSource(key) == null) {
            stringTemplateLoader.putTemplate(key, templateString);
        }
        Template mytpl = configuration.getTemplate(key, chareSet);
        return process(mytpl, args);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:lftao,項目名稱:restclient,代碼行數:23,代碼來源:FkUtils.java

示例10: 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

示例11: createDroolRule

import freemarker.template.Template; //導入依賴的package包/類
public String createDroolRule(Rule rule) throws TemplateException, IOException {
  try {
    Template temp = cfg.getTemplate(templateName);
    Writer out = new StringWriter();
    temp.process(createMap(rule), out);
    return out.toString();
  } catch (IOException iE) {
    logger.error("Problem getting rule template file." + iE.getMessage());
    throw iE;
  } catch (TemplateException tE) {
    logger.error("Problem writing Drool rule." + tE.getMessage());
    throw tE;
  } catch (Exception e) {
    logger.error("Problem creating rule: " + e.getMessage());
    throw e;
  }
}
 
開發者ID:edgexfoundry,項目名稱:support-rulesengine,代碼行數:18,代碼來源:RuleCreator.java

示例12: getRenderedContent

import freemarker.template.Template; //導入依賴的package包/類
public String getRenderedContent(final DetailPageCollection detailPageCollection, final Template template)
        throws CluecumberPluginException {

    ReportDetails reportDetails = new ReportDetails();
    addChartJsonToReportDetails(detailPageCollection.getElement(), reportDetails);
    addCurrentDateToReportDetails(reportDetails);
    detailPageCollection.setReportDetails(reportDetails);

    Writer stringWriter = new StringWriter();
    try {
        template.process(detailPageCollection, stringWriter);
    } catch (TemplateException | IOException e) {
        throw new CluecumberPluginException(e.getMessage());
    }
    return stringWriter.toString();
}
 
開發者ID:trivago,項目名稱:cluecumber-report-plugin,代碼行數:17,代碼來源:DetailPageRenderer.java

示例13: process

import freemarker.template.Template; //導入依賴的package包/類
/**
 * 執行模板渲染
 * @param temp 模板文件或者字符串
 * @param data 數據
 * @param writer 輸出方式
 */
public static void process(String temp, Map<String,Object> data, Writer writer){
    try {
        config.setDirectoryForTemplateLoading(new File(System .getProperty("user.dir")+File.separator+CoreConfig.getTemplatePath()));
        Template template = config.getTemplate(temp,CoreConfig.getEncoding());
        template.process(data, writer);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        // 關閉write
        try {
            if (writer != null) {
                writer.flush();
                writer.close();
            }
        } catch (Exception ex) {
        }
    }
}
 
開發者ID:javahaohao,項目名稱:gen_code,代碼行數:25,代碼來源:FreeMarkerUtil.java

示例14: createRssPostContent

import freemarker.template.Template; //導入依賴的package包/類
@Override
public String createRssPostContent(Post post) {
    String html = null;

    Map<String, Object> model = new Hashtable<>();

    model.put("post", post);
    model.put("baseurl", applicationSettings.getBaseUrl());

    try {
        Template template = fm.getTemplate("posts/rss_post.ftl");
        html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
    } catch (IOException | TemplateException e) {
        logger.error("Problem merging post template : " + e.getMessage());
    }
    return html;
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:18,代碼來源:FmServiceImpl.java

示例15: createPostHtml

import freemarker.template.Template; //導入依賴的package包/類
@Override
public String createPostHtml(Post post, String templateName) {
    String html = null;
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy");
    String postCreated = post.getPostDate().format(formatter);

    Map<String, Object> model = new Hashtable<>();

    model.put("post", post);
    model.put("postCreated", postCreated);
    model.put("shareSiteName",
            StringUtils.deleteWhitespace(applicationSettings.getSiteName()));
    model.put("shareUrl",
            String.format("%s/post/%s", applicationSettings.getBaseUrl(), post.getPostName()));

    String displayType = templateName == null ? post.getDisplayType().name().toLowerCase() : templateName;
    String ftl = String.format("posts/%s.ftl", displayType);

    try {
        Template template = fm.getTemplate(ftl);
        html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
    } catch (IOException | TemplateException e) {
        logger.error("Problem merging post template : " + e.getMessage());
    }
    return html;
}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:27,代碼來源:FmServiceImpl.java


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