private static ComputedOGNLExpression obtainComputedOGNLExpression( final IEngineConfiguration configuration, final IStandardVariableExpression expression, final String exp, final boolean applyOGNLShortcuts) throws OgnlException { if (expression instanceof VariableExpression) { final VariableExpression vexpression = (VariableExpression) expression; Object cachedExpression = vexpression.getCachedExpression(); if (cachedExpression != null && cachedExpression instanceof ComputedOGNLExpression) { return (ComputedOGNLExpression) cachedExpression; } cachedExpression = parseComputedOGNLExpression(configuration, exp, applyOGNLShortcuts); if (cachedExpression != null) { vexpression.setCachedExpression(cachedExpression); } return (ComputedOGNLExpression) cachedExpression; } if (expression instanceof SelectionVariableExpression) { final SelectionVariableExpression vexpression = (SelectionVariableExpression) expression; Object cachedExpression = vexpression.getCachedExpression(); if (cachedExpression != null && cachedExpression instanceof ComputedOGNLExpression) { return (ComputedOGNLExpression) cachedExpression; } cachedExpression = parseComputedOGNLExpression(configuration, exp, applyOGNLShortcuts); if (cachedExpression != null) { vexpression.setCachedExpression(cachedExpression); } return (ComputedOGNLExpression) cachedExpression; } return parseComputedOGNLExpression(configuration, exp, applyOGNLShortcuts); }
static VariableExpression parseVariableExpression(final String input) { final Matcher matcher = VAR_PATTERN.matcher(input); if (!matcher.matches()) { return null; } final String expression = matcher.group(1); final int expressionLen = expression.length(); if (expressionLen > 2 && expression.charAt(0) == SimpleExpression.EXPRESSION_START_CHAR && expression.charAt(expressionLen - 1) == SimpleExpression.EXPRESSION_END_CHAR) { // Double brackets = enable to-String conversion return new VariableExpression(expression.substring(1, expressionLen - 1), true); } return new VariableExpression(expression, false); }
static Object executeVariableExpression( final IExpressionContext context, final VariableExpression expression, final IStandardVariableExpressionEvaluator expressionEvaluator, final StandardExpressionExecutionContext expContext) { if (logger.isTraceEnabled()) { logger.trace("[THYMELEAF][{}] Evaluating variable expression: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); } final StandardExpressionExecutionContext evalExpContext = (expression.getConvertToString()? expContext.withTypeConversion() : expContext.withoutTypeConversion()); final Object result = expressionEvaluator.evaluate(context, expression, evalExpContext); if (!expContext.getForbidUnsafeExpressionResults()) { return result; } // We are only allowing results of type Number and Boolean, and cosidering the rest of data types "unsafe", // as they could be rendered into a non-trustable String. This is mainly useful for helping prevent code // injection in th:on* event handlers. if (result == null || result instanceof Number || result instanceof Boolean) { return result; } throw new TemplateProcessingException( "Only variable expressions returning numbers or booleans are allowed in this context, any other data" + "types are not trusted in the context of this expression, including Strings or any other " + "object that could be rendered as a text literal. A typical case is HTML attributes for event handlers (e.g. " + "\"onload\"), in which textual data from variables should better be output to \"data-*\" attributes and then " + "read from the event handler."); }
(boundObjectValue == null? null : boundObjectValue.getExpression());
static Object executeVariable( final Configuration configuration, final IProcessingContext processingContext, final VariableExpression expression, final IStandardVariableExpressionEvaluator expressionEvaluator, final StandardExpressionExecutionContext expContext) { if (logger.isTraceEnabled()) { logger.trace("[THYMELEAF][{}] Evaluating variable expression: \"{}\"", TemplateEngine.threadIndex(), expression.getStringRepresentation()); } final String exp = expression.getExpression(); if (exp == null) { throw new TemplateProcessingException( "Variable expression is null, which is not allowed"); } final StandardExpressionExecutionContext evalExpContext = (expression.getConvertToString()? expContext.withTypeConversion() : expContext.withoutTypeConversion()); return expressionEvaluator.evaluate(configuration, processingContext, exp, evalExpContext, false); }
private static void invalidateComputedOGNLExpression( final IEngineConfiguration configuration, final IStandardVariableExpression expression, final String exp) { if (expression instanceof VariableExpression) { final VariableExpression vexpression = (VariableExpression) expression; vexpression.setCachedExpression(null); } else if (expression instanceof SelectionVariableExpression) { final SelectionVariableExpression vexpression = (SelectionVariableExpression) expression; vexpression.setCachedExpression(null); } ExpressionCache.removeFromCache(configuration, exp, EXPRESSION_CACHE_TYPE_OGNL); }
return VariableExpression.executeVariable(configuration, processingContext, (VariableExpression)expression, expressionEvaluator, expContext);
(boundObjectValue == null? null : boundObjectValue.getExpression());
private static ComputedSpelExpression obtainComputedSpelExpression( final IEngineConfiguration configuration, final IStandardVariableExpression expression, final String spelExpression) { if (expression instanceof VariableExpression) { final VariableExpression vexpression = (VariableExpression) expression; Object cachedExpression = vexpression.getCachedExpression(); if (cachedExpression != null && cachedExpression instanceof ComputedSpelExpression) { return (ComputedSpelExpression) cachedExpression; } cachedExpression = getExpression(configuration, spelExpression); if (cachedExpression != null) { vexpression.setCachedExpression(cachedExpression); } return (ComputedSpelExpression) cachedExpression; } if (expression instanceof SelectionVariableExpression) { final SelectionVariableExpression vexpression = (SelectionVariableExpression) expression; Object cachedExpression = vexpression.getCachedExpression(); if (cachedExpression != null && cachedExpression instanceof ComputedSpelExpression) { return (ComputedSpelExpression) cachedExpression; } cachedExpression = getExpression(configuration, spelExpression); if (cachedExpression != null) { vexpression.setCachedExpression(cachedExpression); } return (ComputedSpelExpression) cachedExpression; } return getExpression(configuration, spelExpression); }
(boundObjectValue == null? null : boundObjectValue.getExpression());
static VariableExpression parseVariable(final String input) { final Matcher matcher = VAR_PATTERN.matcher(input); if (!matcher.matches()) { return null; } final String expression = matcher.group(1); final int expressionLen = expression.length(); if (expressionLen > 2 && expression.charAt(0) == SimpleExpression.EXPRESSION_START_CHAR && expression.charAt(expressionLen - 1) == SimpleExpression.EXPRESSION_END_CHAR) { // Double brackets = enable to-String conversion return new VariableExpression(expression.substring(1, expressionLen - 1), true); } return new VariableExpression(expression, false); }
private static ComputedSpelExpression obtainComputedSpelExpression( final IEngineConfiguration configuration, final IStandardVariableExpression expression, final String spelExpression) { if (expression instanceof VariableExpression) { final VariableExpression vexpression = (VariableExpression) expression; Object cachedExpression = vexpression.getCachedExpression(); if (cachedExpression != null && cachedExpression instanceof ComputedSpelExpression) { return (ComputedSpelExpression) cachedExpression; } cachedExpression = getExpression(configuration, spelExpression); if (cachedExpression != null) { vexpression.setCachedExpression(cachedExpression); } return (ComputedSpelExpression) cachedExpression; } if (expression instanceof SelectionVariableExpression) { final SelectionVariableExpression vexpression = (SelectionVariableExpression) expression; Object cachedExpression = vexpression.getCachedExpression(); if (cachedExpression != null && cachedExpression instanceof ComputedSpelExpression) { return (ComputedSpelExpression) cachedExpression; } cachedExpression = getExpression(configuration, spelExpression); if (cachedExpression != null) { vexpression.setCachedExpression(cachedExpression); } return (ComputedSpelExpression) cachedExpression; } return getExpression(configuration, spelExpression); }
(boundObjectValue == null? null : boundObjectValue.getExpression());
private static ComputedSpelExpression obtainComputedSpelExpression( final IEngineConfiguration configuration, final IStandardVariableExpression expression, final String spelExpression) { if (expression instanceof VariableExpression) { final VariableExpression vexpression = (VariableExpression) expression; Object cachedExpression = vexpression.getCachedExpression(); if (cachedExpression != null && cachedExpression instanceof ComputedSpelExpression) { return (ComputedSpelExpression) cachedExpression; } cachedExpression = getExpression(configuration, spelExpression); if (cachedExpression != null) { vexpression.setCachedExpression(cachedExpression); } return (ComputedSpelExpression) cachedExpression; } if (expression instanceof SelectionVariableExpression) { final SelectionVariableExpression vexpression = (SelectionVariableExpression) expression; Object cachedExpression = vexpression.getCachedExpression(); if (cachedExpression != null && cachedExpression instanceof ComputedSpelExpression) { return (ComputedSpelExpression) cachedExpression; } cachedExpression = getExpression(configuration, spelExpression); if (cachedExpression != null) { vexpression.setCachedExpression(cachedExpression); } return (ComputedSpelExpression) cachedExpression; } return getExpression(configuration, spelExpression); }
(boundObjectValue == null? null : boundObjectValue.getExpression());
private static ComputedSpelExpression obtainComputedSpelExpression( final IEngineConfiguration configuration, final IStandardVariableExpression expression, final String spelExpression) { if (expression instanceof VariableExpression) { final VariableExpression vexpression = (VariableExpression) expression; Object cachedExpression = vexpression.getCachedExpression(); if (cachedExpression != null && cachedExpression instanceof ComputedSpelExpression) { return (ComputedSpelExpression) cachedExpression; } cachedExpression = getExpression(configuration, spelExpression); if (cachedExpression != null) { vexpression.setCachedExpression(cachedExpression); } return (ComputedSpelExpression) cachedExpression; } if (expression instanceof SelectionVariableExpression) { final SelectionVariableExpression vexpression = (SelectionVariableExpression) expression; Object cachedExpression = vexpression.getCachedExpression(); if (cachedExpression != null && cachedExpression instanceof ComputedSpelExpression) { return (ComputedSpelExpression) cachedExpression; } cachedExpression = getExpression(configuration, spelExpression); if (cachedExpression != null) { vexpression.setCachedExpression(cachedExpression); } return (ComputedSpelExpression) cachedExpression; } return getExpression(configuration, spelExpression); }
final String boundExpressionStr = boundExpression.getExpression(); final String computedFieldName; if (boundExpressionStr.indexOf('.') == -1) {
private static ComputedSpelExpression obtainComputedSpelExpression( final IEngineConfiguration configuration, final IStandardVariableExpression expression, final String spelExpression) { if (expression instanceof VariableExpression) { final VariableExpression vexpression = (VariableExpression) expression; Object cachedExpression = vexpression.getCachedExpression(); if (cachedExpression != null && cachedExpression instanceof ComputedSpelExpression) { return (ComputedSpelExpression) cachedExpression; } cachedExpression = getExpression(configuration, spelExpression); if (cachedExpression != null) { vexpression.setCachedExpression(cachedExpression); } return (ComputedSpelExpression) cachedExpression; } if (expression instanceof SelectionVariableExpression) { final SelectionVariableExpression vexpression = (SelectionVariableExpression) expression; Object cachedExpression = vexpression.getCachedExpression(); if (cachedExpression != null && cachedExpression instanceof ComputedSpelExpression) { return (ComputedSpelExpression) cachedExpression; } cachedExpression = getExpression(configuration, spelExpression); if (cachedExpression != null) { vexpression.setCachedExpression(cachedExpression); } return (ComputedSpelExpression) cachedExpression; } return getExpression(configuration, spelExpression); }
final String boundExpressionStr = boundExpression.getExpression(); final String computedFieldName; if (boundExpressionStr.indexOf('.') == -1) {
final String boundExpressionStr = boundExpression.getExpression(); final String computedFieldName; if (boundExpressionStr.indexOf('.') == -1) {