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); }
variables.put(variableName, context.getVariable(variableName));
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); }
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; }
@Override public Object getVariable(final String name) { if (this.dataDriverVariableName.equals(name)) { return this.dataDrivenTemplateIterator; } return this.context.getVariable(name); }
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); }
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(); }
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(); }
public Object get(final Object key) { if (this.context == null) { throw new TemplateProcessingException("Cannot read property on null target"); } /* * 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 context should just be used as a map, without exposure of its more-internal methods... */ // 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1 if ("execInfo".equals(key)) { // Quick check to avoid deprecated method call final Object execInfoResult = SPELContextPropertyAccessor.checkExecInfo(key.toString(), this.evaluationContext); if (execInfoResult != null) { return execInfoResult; } } return this.context.getVariable(key == null? null : key.toString()); }
public Object get(final Object key) { if (this.context == null) { throw new TemplateProcessingException("Cannot read property on null target"); } /* * 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 context should just be used as a map, without exposure of its more-internal methods... */ // 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1 if ("execInfo".equals(key)) { // Quick check to avoid deprecated method call final Object execInfoResult = SPELContextPropertyAccessor.checkExecInfo(key.toString(), this.evaluationContext); if (execInfoResult != null) { return execInfoResult; } } return this.context.getVariable(key == null? null : key.toString()); }
public Object get(final Object key) { if (this.context == null) { throw new TemplateProcessingException("Cannot read property on null target"); } /* * 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 context should just be used as a map, without exposure of its more-internal methods... */ // 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1 if ("execInfo".equals(key)) { // Quick check to avoid deprecated method call final Object execInfoResult = SPELContextPropertyAccessor.checkExecInfo(key.toString(), this.evaluationContext); if (execInfoResult != null) { return execInfoResult; } } return this.context.getVariable(key == null? null : key.toString()); }
public Object get(final Object key) { if (this.context == null) { throw new TemplateProcessingException("Cannot read property on null target"); } /* * 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 context should just be used as a map, without exposure of its more-internal methods... */ // 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1 if ("execInfo".equals(key)) { // Quick check to avoid deprecated method call final Object execInfoResult = SPELContextPropertyAccessor.checkExecInfo(key.toString(), this.evaluationContext); if (execInfoResult != null) { return execInfoResult; } } return this.context.getVariable(key == null? null : key.toString()); }
public Object get(final Object key) { if (this.context == null) { throw new TemplateProcessingException("Cannot read property on null target"); } /* * 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 context should just be used as a map, without exposure of its more-internal methods... */ // 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1 if ("execInfo".equals(key)) { // Quick check to avoid deprecated method call final Object execInfoResult = SPELContextPropertyAccessor.checkExecInfo(key.toString(), this.evaluationContext); if (execInfoResult != null) { return execInfoResult; } } return this.context.getVariable(key == null? null : key.toString()); }
public TypedValue read(final EvaluationContext evaluationContext, final Object target, final String name) throws AccessException { if (target == null) { throw new AccessException("Cannot read property of null target"); } try { /* * 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 context should just be used as a map, without exposure of its more-internal methods... */ // 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1 if ("execInfo".equals(name)) { // Quick check to avoid deprecated method call final Object execInfoResult = checkExecInfo(name, evaluationContext); if (execInfoResult != null) { return new TypedValue(execInfoResult); } } final IContext context = (IContext) target; return new TypedValue(context.getVariable(name)); } catch (final ClassCastException e) { // This can happen simply because we're applying the same // AST tree on a different class (Spring internally caches property accessors). // So this exception might be considered "normal" by Spring AST evaluator and // just use it to refresh the property accessor cache. throw new AccessException("Cannot read target of class " + target.getClass().getName()); } }
public TypedValue read(final EvaluationContext evaluationContext, final Object target, final String name) throws AccessException { if (target == null) { throw new AccessException("Cannot read property of null target"); } try { /* * 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 context should just be used as a map, without exposure of its more-internal methods... */ // 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1 if ("execInfo".equals(name)) { // Quick check to avoid deprecated method call final Object execInfoResult = checkExecInfo(name, evaluationContext); if (execInfoResult != null) { return new TypedValue(execInfoResult); } } final IContext context = (IContext) target; return new TypedValue(context.getVariable(name)); } catch (final ClassCastException e) { // This can happen simply because we're applying the same // AST tree on a different class (Spring internally caches property accessors). // So this exception might be considered "normal" by Spring AST evaluator and // just use it to refresh the property accessor cache. throw new AccessException("Cannot read target of class " + target.getClass().getName()); } }
public TypedValue read(final EvaluationContext evaluationContext, final Object target, final String name) throws AccessException { if (target == null) { throw new AccessException("Cannot read property of null target"); } try { /* * 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 context should just be used as a map, without exposure of its more-internal methods... */ // 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1 if ("execInfo".equals(name)) { // Quick check to avoid deprecated method call final Object execInfoResult = checkExecInfo(name, evaluationContext); if (execInfoResult != null) { return new TypedValue(execInfoResult); } } final IContext context = (IContext) target; return new TypedValue(context.getVariable(name)); } catch (final ClassCastException e) { // This can happen simply because we're applying the same // AST tree on a different class (Spring internally caches property accessors). // So this exception might be considered "normal" by Spring AST evaluator and // just use it to refresh the property accessor cache. throw new AccessException("Cannot read target of class " + target.getClass().getName()); } }
public TypedValue read(final EvaluationContext evaluationContext, final Object target, final String name) throws AccessException { if (target == null) { throw new AccessException("Cannot read property of null target"); } try { /* * 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 context should just be used as a map, without exposure of its more-internal methods... */ // 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1 if ("execInfo".equals(name)) { // Quick check to avoid deprecated method call final Object execInfoResult = checkExecInfo(name, evaluationContext); if (execInfoResult != null) { return new TypedValue(execInfoResult); } } final IContext context = (IContext) target; return new TypedValue(context.getVariable(name)); } catch (final ClassCastException e) { // This can happen simply because we're applying the same // AST tree on a different class (Spring internally caches property accessors). // So this exception might be considered "normal" by Spring AST evaluator and // just use it to refresh the property accessor cache. throw new AccessException("Cannot read target of class " + target.getClass().getName()); } }
public TypedValue read(final EvaluationContext evaluationContext, final Object target, final String name) throws AccessException { if (target == null) { throw new AccessException("Cannot read property of null target"); } try { /* * 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 context should just be used as a map, without exposure of its more-internal methods... */ // 'execInfo' translation from context variable to expression object - deprecated and to be removed in 3.1 if ("execInfo".equals(name)) { // Quick check to avoid deprecated method call final Object execInfoResult = checkExecInfo(name, evaluationContext); if (execInfoResult != null) { return new TypedValue(execInfoResult); } } final IContext context = (IContext) target; return new TypedValue(context.getVariable(name)); } catch (final ClassCastException e) { // This can happen simply because we're applying the same // AST tree on a different class (Spring internally caches property accessors). // So this exception might be considered "normal" by Spring AST evaluator and // just use it to refresh the property accessor cache. throw new AccessException("Cannot read target of class " + target.getClass().getName()); } }
(IReactiveDataDriverContextVariable) context.getVariable(dataDriverVariableName); final int bufferSizeElements = dataDriver.getBufferSizeElements(); final String sseEventsPrefix =