org.thymeleaf.context.IContext Java Examples
The following examples show how to use
org.thymeleaf.context.IContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringStandaloneThymeleafContextConverter.java From ogham with Apache License 2.0 | 6 votes |
@Override public IContext convert(fr.sii.ogham.core.template.context.Context context) throws ContextException { IContext base = delegate.convert(context); // partially borrowed from org.thymeleaf.spring4.view.ThymeleafView final Map<String, Object> springModel = new HashMap<>(30); final Map<String, Object> templateStaticVariables = staticVariablesProvider.getStaticVariables(context); if (templateStaticVariables != null) { springModel.putAll(templateStaticVariables); } final EvaluationContext evaluationContext = thymeleafEvaluationContextProvider.getEvaluationContext(context); springModel.put(evaluationContextVariableName, evaluationContext); return contextMerger.mergeVariables(base, springModel); }
Example #2
Source File: SpringWebThymeleafContextConverter.java From ogham with Apache License 2.0 | 5 votes |
@Override public IContext convert(fr.sii.ogham.core.template.context.Context context) throws ContextException { IContext base = delegate.convert(context); // the web context may be lost due to @Async method call if (isAsyncCall()) { return base; } // partially borrowed from org.thymeleaf.spring5.view.ThymeleafView final Map<String, Object> springModel = new HashMap<>(30); HttpServletRequest request = webContextProvider.getRequest(context); HttpServletResponse response = webContextProvider.getResponse(context); ServletContext servletContext = webContextProvider.getServletContext(context); if (pathVariablesSelector != null) { @SuppressWarnings("unchecked") final Map<String, Object> pathVars = (Map<String, Object>) request.getAttribute(pathVariablesSelector); if (pathVars != null) { springModel.putAll(pathVars); } } final RequestContext requestContext = new RequestContext(request, response, servletContext, springModel); // For compatibility with ThymeleafView addRequestContextAsVariable(springModel, springRequestContextVariableName, requestContext); // For compatibility with AbstractTemplateView addRequestContextAsVariable(springModel, AbstractTemplateView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE, requestContext); thymeleafRequestContextWrapper.wrapAndRegister(requestContext, request, response, servletContext, springModel); return contextMerger.merge(thymeleafWebContextProvider.getWebContext(context, base, request, response, servletContext, applicationContext, springModel), base); }
Example #3
Source File: UpdateCurrentContextMerger.java From ogham with Apache License 2.0 | 5 votes |
@Override public IContext mergeVariables(IContext base, Map<String, Object> additionalVariables) { if (base instanceof AbstractContext) { ((AbstractContext) base).setVariables(additionalVariables); } else { LOG.debug("Not an AbstractContext => skip additional variables"); } return base; }
Example #4
Source File: UpdateCurrentContextMerger.java From ogham with Apache License 2.0 | 5 votes |
@Override public IContext merge(IContext base, IContext other) { for (String variableName : other.getVariableNames()) { if (base instanceof AbstractContext) { ((AbstractContext) base).setVariable(variableName, other.getVariable(variableName)); } else { LOG.debug("Not an AbstractContext => skip additional variables"); } } return base; }
Example #5
Source File: UpdateCurrentContextMerger.java From ogham with Apache License 2.0 | 5 votes |
@Override public IContext mergeVariables(IContext base, Map<String, Object> additionalVariables) { if (base instanceof AbstractContext) { ((AbstractContext) base).setVariables(additionalVariables); } else { LOG.debug("Not an AbstractContext => skip additional variables"); } return base; }
Example #6
Source File: UpdateCurrentContextMerger.java From ogham with Apache License 2.0 | 5 votes |
@Override public IContext merge(IContext base, IContext other) { for (Entry<String, Object> variable : other.getVariables().entrySet()) { if (base instanceof AbstractContext) { ((AbstractContext) base).setVariable(variable.getKey(), variable.getValue()); } else { LOG.debug("Not an AbstractContext => skip additional variables"); } } return base; }
Example #7
Source File: WebExpressionContextProvider.java From ogham with Apache License 2.0 | 4 votes |
@Override public IContext getWebContext(Context context, IContext base, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext, ApplicationContext applicationContext, Map<String, Object> springModel) { final IEngineConfiguration configuration = viewTemplateEngine.getConfiguration(); return new WebExpressionContext(configuration, request, response, servletContext, base.getLocale(), springModel); }
Example #8
Source File: SpringWebContextProvider.java From ogham with Apache License 2.0 | 4 votes |
@Override public IContext getWebContext(Context context, IContext base, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext, ApplicationContext applicationContext, Map<String, Object> springModel) { return new SpringWebContext(request, response, servletContext, base.getLocale(), springModel, applicationContext); }
Example #9
Source File: ThymeleafWebContextProvider.java From ogham with Apache License 2.0 | 2 votes |
/** * Generates the suitable context for a Web application. * * @param context * Ogham original context that may be used to retrieve extra * information * @param base * Thymeleaf context that has been converted from Ogham original * context. It contains the base variables extracted from Ogham * context. * @param request * the current HTTP request * @param response * the current HTTP response * @param servletContext * the servlet execution context * @param applicationContext * the application context * @param springModel * the model that contains both variables extracted from Ogham * context and Spring variables (static variables, evaluation * context, ...) * @return the suitable context for a Web application to provide access to * Spring extensions */ IContext getWebContext(Context context, IContext base, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext, ApplicationContext applicationContext, Map<String, Object> springModel);
Example #10
Source File: ContextMerger.java From ogham with Apache License 2.0 | 2 votes |
/** * Adds additional variables to base context. * * @param base * the context that contains the original variables and Thymeleaf * context data. It may be updated in place. * @param variables * the additional variables to apply to the original context * @return the resulting context (may be the same instance as base) */ IContext mergeVariables(IContext base, Map<String, Object> variables);
Example #11
Source File: ContextMerger.java From ogham with Apache License 2.0 | 2 votes |
/** * Merge two contexts into one context. * * @param a * first context * @param b * second context * @return the resulting context (may be the same instance as any of * provided context) */ IContext merge(IContext a, IContext b);
Example #12
Source File: ThymeleafContextConverter.java From ogham with Apache License 2.0 | 2 votes |
/** * Convert abstraction used for all template engines into a Thymeleaf * context. * * @param context * the context abstraction * @return the Thymeleaf context * @throws ContextException * when conversion couldn't be applied */ IContext convert(Context context) throws ContextException;