本文整理汇总了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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
}
示例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);
}
示例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;
}
}
示例12: process
import org.thymeleaf.context.IContext; //导入依赖的package包/类
public String process(String templateName, IContext context) {
return this.templateEngine.process(templateName, context);
}
示例13: getContext
import org.thymeleaf.context.IContext; //导入依赖的package包/类
public IContext getContext()
{
return context;
}
示例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);
}
示例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();