private static Object getContextProperty( final String propertyName, final Map<String, Object> context, final Object target) throws OgnlException { if (OGNLContextPropertyAccessor.REQUEST_PARAMETERS_RESTRICTED_VARIABLE_NAME.equals(propertyName) && context != null && context.containsKey(OGNLContextPropertyAccessor.RESTRICT_REQUEST_PARAMETERS)) { throw new OgnlException( "Access to variable \"" + propertyName + "\" is forbidden in this context. Note some restrictions apply to " + "variable access. For example, accessing request parameters is forbidden in preprocessing and " + "unescaped expressions, and also in fragment inclusion specifications."); } // 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1 if ("execInfo".equals(propertyName)) { // Quick check to avoid deprecated method call final Object execInfoResult = checkExecInfo(propertyName, context); if (execInfoResult != null) { return execInfoResult; } } return ((IContext) target).getVariable(propertyName); }
final Set<String> variableNames = context.getVariableNames(); context.getLocale(), Collections.EMPTY_MAP); variables.put(variableName, context.getVariable(variableName)); context.getLocale(), variables);
new Object[]{TemplateEngine.threadIndex(), templateSpec, context.getLocale()}); new Object[]{TemplateEngine.threadIndex(), templateSpec, context.getLocale()}); new Object[]{ TemplateEngine.threadIndex(), LoggingUtils.loggifyTemplateName(templateSpec.getTemplate()), context.getLocale(), elapsed, elapsedMs, templateSpec, context.getLocale(), elapsed, elapsedMs});
/** * Sets a variable which is then exposed to the view layer * * @param name * @param value * * @return */ public ThymeleafCall set(String name, Object value) { context.getVariables().put(name, value); return this; }
(IReactiveDataDriverContextVariable) context.getVariable(dataDriverVariableName); final int bufferSizeElements = dataDriver.getBufferSizeElements(); final String sseEventsPrefix = TemplateEngine.threadIndex(), throttledProcessor.getProcessorIdentifier(), throttledProcessor.getProcessorIdentifier(), Integer.valueOf(throttledProcessor.getChunkCount()), LoggingUtils.loggifyTemplateName(templateName), context.getLocale()}); TemplateEngine.threadIndex(), throttledProcessor.getProcessorIdentifier(), throttledProcessor.getProcessorIdentifier(), Integer.valueOf(throttledProcessor.getChunkCount()), LoggingUtils.loggifyTemplateName(templateName), context.getLocale(), Integer.valueOf(bytesProduced)}); TemplateEngine.threadIndex(), throttledProcessor.getProcessorIdentifier(), throttledProcessor.getProcessorIdentifier(), LoggingUtils.loggifyTemplateName(templateName), context.getLocale(), Long.valueOf(throttledProcessor.getTotalBytesProduced()), Integer.valueOf(throttledProcessor.getChunkCount() + 1)});
private static String findDataDriverInModel(final IContext context) { // In SpringWebFluxContext (used most of the times), variables are backed by a // Map<String,Object>. So this iteration on all the names and many "getVariable()" calls // shouldn't be an issue perf-wise. String dataDriverVariableName = null; final Set<String> contextVariableNames = context.getVariableNames(); for (final String contextVariableName : contextVariableNames) { final Object contextVariableValue = context.getVariable(contextVariableName); if (contextVariableValue instanceof IReactiveDataDriverContextVariable) { if (dataDriverVariableName != null) { throw new TemplateProcessingException( "Only one data-driver variable is allowed to be specified as a model attribute, but " + "at least two have been identified: '" + dataDriverVariableName + "' " + "and '" + contextVariableName + "'"); } dataDriverVariableName = contextVariableName; } } return dataDriverVariableName; }
logger.debug("[THYMELEAF][{}] STARTING PROCESS OF TEMPLATE \"{}\" WITH LOCALE {}", new Object[] {TemplateEngine.threadIndex(), templateName, context.getLocale()}); context.addContextExecutionInfo(templateName); logger.debug("[THYMELEAF][{}] FINISHED PROCESS AND OUTPUT OF TEMPLATE \"{}\" WITH LOCALE {}", new Object[] {TemplateEngine.threadIndex(), templateName, context.getLocale()}); "[THYMELEAF][{}][{}][{}][{}][{}] TEMPLATE \"{}\" WITH LOCALE {} PROCESSED IN {} nanoseconds (approx. {}ms)", new Object[] {TemplateEngine.threadIndex(), templateName, context.getLocale(), elapsed, elapsedMs, templateName, context.getLocale(), elapsed, elapsedMs});
@Override public Set<String> getVariableNames() { return this.context.getVariableNames(); }
@Override public boolean containsVariable(final String name) { return this.context.containsVariable(name); }
new Object[]{TemplateEngine.threadIndex(), templateSpec, context.getLocale()}); new Object[]{TemplateEngine.threadIndex(), templateSpec, context.getLocale()}); new Object[]{ TemplateEngine.threadIndex(), LoggingUtils.loggifyTemplateName(templateSpec.getTemplate()), context.getLocale(), elapsed, elapsedMs, templateSpec, context.getLocale(), elapsed, elapsedMs});
/** * Sets a variable which is then exposed to the view layer * * @param name * @param value * * @return */ public ThymeleafCall set(String name, Object value) { context.getVariables().put(name, value); return this; }
public Object getProperty(final Map ognlContext, final Object target, final Object name) throws OgnlException { if (!(target instanceof IContext)) { throw new IllegalStateException( "Wrong target type. This property accessor is only usable for " + IContext.class.getName() + " implementations, and " + "in this case the target object is " + (target == null? "null" : ("of class " + target.getClass().getName()))); } if (REQUEST_PARAMETERS_RESTRICTED_VARIABLE_NAME.equals(name) && ognlContext != null && ognlContext.containsKey(RESTRICT_REQUEST_PARAMETERS)) { throw new OgnlException( "Access to variable \"" + name + "\" is forbidden in this context. Note some restrictions apply to " + "variable access. For example, direct access to request parameters is forbidden in preprocessing and " + "unescaped expressions, in TEXT template mode, in fragment insertion specifications and " + "in some specific attribute processors."); } final String propertyName = (name == null? null : name.toString()); // 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1 final Object execInfoResult = checkExecInfo(propertyName, ognlContext); if (execInfoResult != null) { return execInfoResult; } /* * NOTE we do not check here whether we are being asked for the 'locale', 'request', 'response', etc. * because there already are specific expression objects for the most important of them, which should * be used instead: #locale, #httpServletRequest, #httpSession, etc. * The variables maps should just be used as a map, without exposure of its more-internal methods... */ final IContext context = (IContext) target; return context.getVariable(propertyName); }
public IEngineContext createEngineContext( final IEngineConfiguration configuration, final TemplateData templateData, final Map<String, Object> templateResolutionAttributes, final IContext context) { Validate.notNull(context, "Context object cannot be null"); final Set<String> variableNames = context.getVariableNames(); if (variableNames == null || variableNames.isEmpty()) { if (context instanceof ISpringWebFluxContext) { final ISpringWebFluxContext srContext = (ISpringWebFluxContext)context; return new SpringWebFluxEngineContext( configuration, templateData, templateResolutionAttributes, srContext.getExchange(), srContext.getLocale(), Collections.EMPTY_MAP); } return new EngineContext( configuration, templateData, templateResolutionAttributes, context.getLocale(), Collections.EMPTY_MAP); } final Map<String,Object> variables = new LinkedHashMap<>(variableNames.size() + 1, 1.0f); for (final String variableName : variableNames) { variables.put(variableName, context.getVariable(variableName)); } if (context instanceof ISpringWebFluxContext) { final ISpringWebFluxContext srContext = (ISpringWebFluxContext)context; return new SpringWebFluxEngineContext( configuration, templateData, templateResolutionAttributes, srContext.getExchange(), srContext.getLocale(), variables); } return new EngineContext( configuration, templateData, templateResolutionAttributes, context.getLocale(), variables); }
@Override public Locale getLocale() { return this.context.getLocale(); }
private Object createEvaluationRoot() { final VariablesMap<String, Object> contextVariables = this.context.getVariables(); // We create a new VariablesMap instance using its constructor instead of cloning the existing one // because we want to avoid undesirable interactions like, for example, those that could happen // if we executed putAll on a WebVariablesMap object (which would add those variables to the HttpServletRequest // and therefore make them available to the whole page and not just the local variable scope). final VariablesMap<String,Object> newEvaluationRoot = new VariablesMap<String, Object>(contextVariables); if (this.localVariables != null) { newEvaluationRoot.putAll(this.localVariables); } return newEvaluationRoot; }
@Override public Object getVariable(final String name) { if (this.dataDriverVariableName.equals(name)) { return this.dataDrivenTemplateIterator; } return this.context.getVariable(name); }
/** {@inheritDoc} */ public MessageResolution resolveMessage(Arguments args, String key, Object[] msgParams) { final Locale locale = args.getContext().getLocale(); String targetMsg = resolveProperties(locale).getProperty(key); if (targetMsg == null) { targetMsg = "<span style=\"color:red\">" + key + " not found</span>"; } else if (msgParams != null && msgParams.length > 0) { targetMsg = new MessageFormat(targetMsg, args.getContext().getLocale()).format(msgParams); } return new MessageResolution(targetMsg); }
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); }
static Authentication getAuthenticationObject(final IContext context) { final SecurityContext securityContext = (SecurityContext) context.getVariable(SECURITY_CONTEXT_MODEL_ATTRIBUTE_NAME); if (securityContext == null) { if (logger.isTraceEnabled()) { logger.trace("[THYMELEAF][{}] No security context found, no authentication object returned.", new Object[] {TemplateEngine.threadIndex()}); } return null; } return securityContext.getAuthentication(); }
/** {@inheritDoc} */ public MessageResolution resolveMessage(Arguments args, String key, Object[] msgParams) { final Locale locale = args.getContext().getLocale(); String targetMsg = resolveProperties(locale).getProperty(key); if (targetMsg == null) { targetMsg = key; } else if (msgParams != null && msgParams.length > 0) { targetMsg = new MessageFormat(targetMsg, args.getContext().getLocale()).format(msgParams); } return new MessageResolution(targetMsg); }