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


Java IContext类代码示例

本文整理汇总了Java中org.thymeleaf.context.IContext的典型用法代码示例。如果您正苦于以下问题:Java IContext类的具体用法?Java IContext怎么用?Java IContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: generateWithThymeleaf

import org.thymeleaf.context.IContext; //导入依赖的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

示例2: render

import org.thymeleaf.context.IContext; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked" })
@Override
public void render(final View view, final Context ctx) throws FileNotFoundException, Exception {
  String vname = view.name();

  Map<String, Object> vars = ctx.locals();
  vars.putIfAbsent("_vname", vname);

  // Locale:
  Locale locale = (Locale) vars.getOrDefault("locale", ctx.locale());

  Map model = view.model();
  vars.forEach(model::putIfAbsent);
  model.putIfAbsent("xss", new Thlxss(env));

  IContext thlctx = new org.thymeleaf.context.Context(locale, model);
  String output = this.engine.process(vname, thlctx);

  ctx.type(MediaType.html)
      .send(output);
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:22,代码来源:ThlEngine.java

示例3: getContext

import org.thymeleaf.context.IContext; //导入依赖的package包/类
@Override
public IContext getContext() {
	final Context ctx = new Context();
	ctx.setVariable("now", new Date());
	ctx.setVariable("name", "Name Surname");
	ctx.setVariable("hobbies", Arrays.asList("Cinema", "Sports", "Music"));

	return ctx;
}
 
开发者ID:mychalvlcek,项目名称:spring-rest-skeleton,代码行数:10,代码来源:ExampleMailPreparator.java

示例4: process

import org.thymeleaf.context.IContext; //导入依赖的package包/类
@Override
public String process(TemplateEngineModel data) {
    if (!configured) {
        throw new IllegalStateException("Engine not configured.  Did you call setViewResolverConfiguration()?");
    }
    Map<String, Object> variables = data.getVariables();
    Object inlineContentItem = data.getInlineContentItem();
    String contentType = getContentTypeFromModel(inlineContentItem);
    variables.put("model", inlineContentItem);
    IContext context = new Context(data.getLocale(), variables);
    return templateEngine.process(contentType, context);
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:13,代码来源:ThymeleafTemplateEngine.java

示例5: processTemplateCode

import org.thymeleaf.context.IContext; //导入依赖的package包/类
public String processTemplateCode(final String code, final IContext context) {

        Validate.notNull(code, "Code must be non-null");
        Validate.notNull(context, "Context must be non-null");
        String templateMode = StandardTemplateModeHandlers.HTML5.getTemplateModeName();
        IMessageResolver messageResolver = new StandardMessageResolver();
        ITemplateResolver templateResolver = new MemoryTemplateResolver(code, templateMode);
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
        templateEngine.setMessageResolver(messageResolver);
        templateEngine.setTemplateResolver(templateResolver);
        templateEngine.initialize();
        return templateEngine.process("template", context);
    }
 
开发者ID:PestaKit,项目名称:microservice-email,代码行数:14,代码来源:StaticTemplateService.java

示例6: resolvePageTemplate

import org.thymeleaf.context.IContext; //导入依赖的package包/类
@Override
public void resolvePageTemplate(String urlPrefix, @NotNull PageContext pageContext, @NotNull Writer writer) {
    IronContracts.notNull(pageContext, "context", writer, "writer");

    IContext thymeleafContext = new MainPageContext(pageContext, urlPrefix, env);
    templateEngine.process(pageContext.templatePath(), thymeleafContext, writer);
}
 
开发者ID:nyrkovalex,项目名称:iron-admin,代码行数:8,代码来源:ThymeleafTemplateResolver.java

示例7: ThymeleafCall

import org.thymeleaf.context.IContext; //导入依赖的package包/类
ThymeleafCall(TemplateEngine engine, IContext context, String name, final Timer calls, final Meter failures)
{
	this.engine = engine;
	this.context = context;
	this.name = name;
	this.calls = calls;
	this.failures = failures;
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:9,代码来源:ThymeleafCall.java

示例8: template

import org.thymeleaf.context.IContext; //导入依赖的package包/类
public ThymeleafCall template(final String name)
{
	final IContext ctx = makeContext();

	// Expose the service configuration
	ctx.getVariables().put("config", configuration);
	ctx.getVariables().putAll(data);

	return new ThymeleafCall(engine, ctx, name, calls, failures);
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:11,代码来源:ThymeleafTemplater.java

示例9: makeContext

import org.thymeleaf.context.IContext; //导入依赖的package包/类
/**
 * Build a new IContext (exposing the HttpCallContext, where possible)
 *
 * @return
 */
protected IContext makeContext()
{
	final HttpCallContext http = HttpCallContext.peek();

	if (http != null)
	{
		return new WebContext(http.getRequest(), http.getResponse(), http.getServletContext(), http.getRequest().getLocale());
	}
	else
	{
		return new Context();
	}
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:19,代码来源:ThymeleafTemplater.java

示例10: process

import org.thymeleaf.context.IContext; //导入依赖的package包/类
@Override
public String process(String template, IContext context) {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("locale", context.getLocale());
    return engine.process(new TemplateSpec(template, attributes), context);

}
 
开发者ID:resource4j,项目名称:resource4j,代码行数:8,代码来源:Resource4jTemplateEngine.java

示例11: getResourceAsStream

import org.thymeleaf.context.IContext; //导入依赖的package包/类
@Override
public InputStream getResourceAsStream(
		TemplateProcessingParameters templateProcessingParameters,
		String resourceName) {
	IContext context = templateProcessingParameters.getContext();
	Locale locale = context.getLocale();
	try {
		return resources.contentOf(resourceName, locale).asStream();
	} catch (MissingResourceObjectException e) {
		LOG.error("Resource {} not found.", resourceName, e);
		// According to contract for IResourceResolver
		return null;
	}
}
 
开发者ID:resource4j,项目名称:resource4j,代码行数:15,代码来源:Resource4jResourceResolver.java

示例12: process

import org.thymeleaf.context.IContext; //导入依赖的package包/类
public String process(String templateName, IContext context) {
    return this.templateEngine.process(templateName, context);
}
 
开发者ID:TulevaEE,项目名称:onboarding-service,代码行数:4,代码来源:TemplateEngineWrapper.java

示例13: getContext

import org.thymeleaf.context.IContext; //导入依赖的package包/类
public IContext getContext()
{
	return context;
}
 
开发者ID:petergeneric,项目名称:stdlib,代码行数:5,代码来源:ThymeleafCall.java

示例14: processThrottled

import org.thymeleaf.context.IContext; //导入依赖的package包/类
@Override
public IThrottledTemplateProcessor processThrottled(String template, IContext context) {
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("locale", context.getLocale());
    return engine.processThrottled(new TemplateSpec(template, attributes), context);
}
 
开发者ID:resource4j,项目名称:resource4j,代码行数:7,代码来源:Resource4jTemplateEngine.java

示例15: getContext

import org.thymeleaf.context.IContext; //导入依赖的package包/类
/**
 * Returns mail template context.
 * It represents all the data you want pass to an email template.
 */
public abstract IContext getContext();
 
开发者ID:mychalvlcek,项目名称:spring-rest-skeleton,代码行数:6,代码来源:TemplatableMailPreparator.java


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