当前位置: 首页>>代码示例>>Java>>正文


Java TemplateEngine.process方法代码示例

本文整理汇总了Java中org.thymeleaf.TemplateEngine.process方法的典型用法代码示例。如果您正苦于以下问题:Java TemplateEngine.process方法的具体用法?Java TemplateEngine.process怎么用?Java TemplateEngine.process使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.thymeleaf.TemplateEngine的用法示例。


在下文中一共展示了TemplateEngine.process方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: renderNonWebAppTemplate

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
@Test
public void renderNonWebAppTemplate() throws Exception {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
			ThymeleafAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	assertThat(context.getBeanNamesForType(ViewResolver.class).length).isEqualTo(0);
	try {
		TemplateEngine engine = context.getBean(TemplateEngine.class);
		Context attrs = new Context(Locale.UK,
				Collections.singletonMap("greeting", "Hello World"));
		String result = engine.process("message", attrs);
		assertThat(result).contains("Hello World");
	}
	finally {
		context.close();
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:ThymeleafAutoConfigurationTests.java

示例2: buildIndex

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
/**
 * Builds index.html file. This file contains table with links to validation
 * results.
 */
private static void buildIndex() {
	try {
		Collections.sort(results);

		FileWriter writer = new FileWriter(new File("out", "index.html"));

		TemplateEngine templateEngine = new TemplateEngine();
		TemplateResolver templateResolver = new ClassLoaderTemplateResolver();
		templateResolver.setPrefix("resources/");
		templateResolver.setSuffix(".html");
		templateEngine.setTemplateResolver(templateResolver);

		Context ctx = new Context();
		ctx.setVariable("results", results);

		templateEngine.process("index-template", ctx, writer);

		writer.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:mariusj,项目名称:validator-sitemap,代码行数:27,代码来源:SitemapValidator.java

示例3: staticPage

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
public static void staticPage(GenParam genParam) throws Exception {

        // 构造模板引擎
        TemplateEngine templateEngine = new TemplateEngine();
        templateEngine.setTemplateResolver(genParam.getResolver());

        // 渲染模板
        Assert.notNull(genParam.getTemplateName(), "templateName must not be null!");
        String filePath = genParam.getOutputPath() + genParam.getTemplateName().split("_")[0] + "/";
        //LOGGER.warn("output file path: {}", filePath);
        File file = new File(filePath);
        if (!file.exists()) file.mkdirs();
        Assert.notNull(genParam.getHouseCode(), "HouseCode must not be null!");
        // 输出文件
        FileWriter write = new FileWriter(filePath + genParam.getHouseCode() + ".shtml");
        templateEngine.process(genParam.getTemplateName(), genParam.getContext(), write);
    }
 
开发者ID:lupindong,项目名称:xq_seckill_microservice,代码行数:18,代码来源:PageGenerator.java

示例4: main

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
public static void main(String[] args) {
    ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
    resolver.setTemplateMode("XHTML");
    resolver.setSuffix(".html");
    TemplateEngine engine = new TemplateEngine();
    engine.setTemplateResolver(resolver);


    Context context = new Context(Locale.FRANCE);
    context.setVariable("date", new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime()));
    context.setVariable("contact", new Contact("John", "Doe"));

    List<Contact> contacts = new ArrayList<Contact>();
    contacts.add(new Contact("John","Doe"));
    contacts.add(new Contact("Jane","Doe"));
    context.setVariable("contacts",contacts);

    StringWriter writer = new StringWriter();
    engine.process("org/n3r/sandbox/thymeleaf/home", context, writer);

    System.out.println(writer.toString());
}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:23,代码来源:ThymeleafDemo.java

示例5: createFromConfigClass

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
@Test
public void createFromConfigClass() throws Exception {
	EnvironmentTestUtils.addEnvironment(this.context, "spring.thymeleaf.mode:XHTML",
			"spring.thymeleaf.suffix:");
	this.context.register(ThymeleafAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	this.context.refresh();
	TemplateEngine engine = this.context.getBean(TemplateEngine.class);
	Context attrs = new Context(Locale.UK, Collections.singletonMap("foo", "bar"));
	String result = engine.process("template.txt", attrs);
	assertThat(result).isEqualTo("<html>bar</html>");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:ThymeleafAutoConfigurationTests.java

示例6: renderNonWebAppTemplate

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
@Test
public void renderNonWebAppTemplate() throws Exception {
	AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
			ThymeleafAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	assertEquals(0, context.getBeanNamesForType(ViewResolver.class).length);
	try {
		TemplateEngine engine = context.getBean(TemplateEngine.class);
		Context attrs = new Context(Locale.UK,
				Collections.singletonMap("greeting", "Hello World"));
		String result = engine.process("message", attrs);
		assertThat(result, containsString("Hello World"));
	}
	finally {
		context.close();
	}
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:18,代码来源:ThymeleafAutoConfigurationTests.java

示例7: generateWithThymeleaf

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
/**
 * Generates output file with release notes using Thymeleaf.
 * @param variables the map which represents template variables.
 * @param outputFile output file.
 * @param templateFilename template name.
 * @throws IOException if I/O error occurs.
 */
public static void generateWithThymeleaf(Map<String, Object> variables, String outputFile,
        String templateFilename) throws IOException {

    final TemplateEngine engine = new TemplateEngine();
    final AbstractConfigurableTemplateResolver resolver = new ClassLoaderTemplateResolver();
    resolver.setPrefix(TEMPLATE_FOLDER_PATH);
    engine.setTemplateResolver(resolver);

    final IContext ctx = new Context(Locale.US, variables);

    try (Writer fileWriter = new OutputStreamWriter(
            new FileOutputStream(outputFile), StandardCharsets.UTF_8)) {
        engine.process(templateFilename, ctx, fileWriter);
    }
}
 
开发者ID:checkstyle,项目名称:contribution,代码行数:23,代码来源:TemplateProcessor.java

示例8: generate

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
/**
 * Generates site report using thymeleaf template engine.
 *
 * @param diffReport
 *        container with parsed data.
 * @param diffConfiguration
 *        merged configurations from both reports.
 * @param paths
 *        CLI paths.
 * @throws IOException
 *         on failure to write site to disc.
 */
public static void generate(DiffReport diffReport, MergedConfigurationModule diffConfiguration,
        CliPaths paths) throws IOException {
    // setup thymeleaf engine
    final TemplateEngine tplEngine = getTemplateEngine();
    // setup xreference generator
    final XrefGenerator xrefGenerator = new XrefGenerator(paths.getRefFilesPath(),
            paths.getOutputPath().resolve(Main.XREF_FILEPATH), paths.getOutputPath());
    // html generation
    final Path sitepath = paths.getOutputPath().resolve(SITEPATH);
    final FileWriter writer = new FileWriter(sitepath.toString());
    try {
        // write statistics
        generateHeader(tplEngine, writer, diffReport.getStatistics(), diffConfiguration);
        // write parsed content
        generateBody(tplEngine, writer, diffReport, paths, xrefGenerator);
        // write html footer
        tplEngine.process("footer", new Context(), writer);
    }
    finally {
        writer.close();
    }
}
 
开发者ID:checkstyle,项目名称:contribution,代码行数:35,代码来源:SiteGenerator.java

示例9: generate

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
/**
 * Generates the index page.
 *
 * @param _records
 *            the list of records.
 * @throws IOException
 */
public void generate(Map<RecordKey, BenchRecord> _records) throws IOException {
	final TemplateEngine templateEngine = new TemplateEngine();
	final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();

	// XHTML is the default mode, but we set it anyway for better
	// understanding of code
	templateResolver.setTemplateMode("HTML5");
	templateResolver.setCacheable(true);
	templateResolver.setPrefix("templates/");
	templateResolver.setSuffix(".html");
	templateEngine.setTemplateResolver(templateResolver);
	try (final FileWriter fw = new FileWriter(new File(reportFolder, "index.html"))) {
		templateEngine.process("index", new BenchContext(_records), fw);
	}
}
 
开发者ID:sleroy,项目名称:bench4j,代码行数:23,代码来源:HtmlIndexPage.java

示例10: render

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
@Override
public String render(TemplateContext context)
        throws Exception
{
    TemplateEngine templateEngine = getTemplateEngine(context);

    Map<String, Object> variables = new HashMap<>(3);
    variables.put("site", context.site);
    variables.put("page", context.page);
    variables.put("contents", context.contents);

    SiteContext thymeleafContext = new SiteContext();
    thymeleafContext.setSiteKey(context.site.key);

    thymeleafContext.setVariables(variables);

    return templateEngine.process(context.page.getMasterTemplate(), thymeleafContext);
}
 
开发者ID:dmmikkel,项目名称:Brisk,代码行数:19,代码来源:ThymeleafTemplateRenderer.java

示例11: testJavaScript

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
@Test
public void testJavaScript() {
    TemplateEngine engine = createWisdomEngine();
    engine.initialize();
    Context context = new Context();
    context.setVariable("test", "test");

    FakeRouter router = new FakeRouter();
    Controller controller = new FakeController();
    router.addController(controller);

    Assets assets = mock(Assets.class);

    context.setVariable(Routes.ROUTES_VAR, new Routes(router, assets, controller));

    String processed = engine.process("templates/javascript.thl.html", context);
    assertThat(processed).containsIgnoringCase("var t = 'test';");
    assertThat(processed).containsIgnoringCase("var url = '/';");
    assertThat(processed).containsIgnoringCase("$(document).ready(function () {");
}
 
开发者ID:wisdom-framework,项目名称:wisdom,代码行数:21,代码来源:WisdomTemplateEngineTest.java

示例12: testThymeleafTemplate

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
@Test
@Ignore
public void testThymeleafTemplate() throws IOException, MessagingException {

    ClassLoaderTemplateResolver templateResolver =
            new ClassLoaderTemplateResolver();

    templateResolver.setTemplateMode(TemplateMode.HTML);
    templateResolver.setPrefix("/templates/");
    templateResolver.setSuffix(".html");
    templateResolver.setCacheTTLMs(Long.valueOf(3600000L));

    templateResolver.setCharacterEncoding("UTF-8");
    templateResolver.setCacheable(true);

    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);

    Context ctx = new Context();
    ctx.setLocale(Locale.ENGLISH);
    ctx.setVariable("username", "ricky");
    ctx.setVariable("url", "http://www.thymeleaf.org");
    ctx.setVariable("email", "[email protected]");

    StringWriter sw = new StringWriter(1024);
    templateEngine.process("registry", ctx, sw);

    String output = sw.toString();
    System.out.println(output);

    Mail mail = Mail.newBuilder().from(from,"ricky fung")
            .to(to)
            .subject("测试邮件[模板邮件-Thymeleaf]")
            .html(output)
            .build();

    client.send(mail);
}
 
开发者ID:TFdream,项目名称:okmail,代码行数:39,代码来源:OkMailClientTest.java

示例13: testApp

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
@Test
@Ignore
public void testApp() throws IOException {

    //use thymeleaf
    ClassLoaderTemplateResolver templateResolver =
            new ClassLoaderTemplateResolver();

    templateResolver.setTemplateMode(TemplateMode.HTML);
    templateResolver.setPrefix("/templates/");
    templateResolver.setSuffix(".html");
    templateResolver.setCacheTTLMs(Long.valueOf(3600000L));

    templateResolver.setCharacterEncoding("UTF-8");
    templateResolver.setCacheable(true);

    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);

    Context ctx = new Context();
    ctx.setLocale(Locale.ENGLISH);
    ctx.setVariable("username", "ricky");
    ctx.setVariable("url", "http://www.thymeleaf.org");
    ctx.setVariable("email", "[email protected]");

    StringWriter sw = new StringWriter(1024);
    templateEngine.process("registry", ctx, sw);

    String output = sw.toString();
    System.out.println(output);
}
 
开发者ID:TFdream,项目名称:okmail,代码行数:32,代码来源:ThymeleafTest.java

示例14: renderTemplate

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
@Override
public String renderTemplate() {
    TemplateEngine templateEngine = new TemplateEngine();
    AbstractConfigurableTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setTemplateMode(this.templateMode);

    templateEngine.setTemplateResolver(templateResolver);

    return templateEngine.process(template, new Context(Locale.SIMPLIFIED_CHINESE, context));
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:11,代码来源:ThymeleafTemplateResource.java

示例15: renderReport

import org.thymeleaf.TemplateEngine; //导入方法依赖的package包/类
String renderReport(String template, List<ScreenshotComparisonResult> screenshotComparisonResults) throws FileNotFoundException {

        ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
        templateResolver.setTemplateMode("HTML");
        templateResolver.setPrefix("templates/");
        templateResolver.setSuffix(".html");
        TemplateEngine templateEngine = new TemplateEngine();
        templateEngine.setTemplateResolver(templateResolver);

        final Map<String, Object> variables = prepareVariablesForReportTemplate(screenshotComparisonResults);

        return templateEngine.process(template, new Context(Locale.US, variables));
    }
 
开发者ID:otto-de,项目名称:jlineup,代码行数:14,代码来源:HTMLReportWriter.java


注:本文中的org.thymeleaf.TemplateEngine.process方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。