Example usage for org.springframework.expression.common TemplateParserContext TemplateParserContext

List of usage examples for org.springframework.expression.common TemplateParserContext TemplateParserContext

Introduction

In this page you can find the example usage for org.springframework.expression.common TemplateParserContext TemplateParserContext.

Prototype

public TemplateParserContext(String expressionPrefix, String expressionSuffix) 

Source Link

Document

Create a new TemplateParserContext for the given prefix and suffix.

Usage

From source file:com.creactiviti.piper.core.task.SpelTaskEvaluator.java

private Object evaluate(Object aValue, Context aContext) {
    StandardEvaluationContext context = createEvaluationContext(aContext);
    if (aValue instanceof String) {
        Expression expression = parser.parseExpression((String) aValue,
                new TemplateParserContext(PREFIX, SUFFIX));
        try {/*w w w. j  a va2s  . com*/
            return (expression.getValue(context));
        } catch (SpelEvaluationException e) {
            logger.debug(e.getMessage());
            return aValue;
        }
    } else if (aValue instanceof List) {
        List<Object> evaluatedlist = new ArrayList<>();
        List<Object> list = (List<Object>) aValue;
        for (Object item : list) {
            evaluatedlist.add(evaluate(item, aContext));
        }
        return evaluatedlist;
    } else if (aValue instanceof Map) {
        return evaluateInternal((Map<String, Object>) aValue, aContext);
    }
    return aValue;
}

From source file:org.kuali.rice.krad.uif.service.impl.ExpressionEvaluatorServiceImpl.java

/**
 * @see org.kuali.rice.krad.uif.service.ExpressionEvaluatorService#evaluateExpressionTemplate(java.lang.Object,
 *      java.util.Map, java.lang.String)
 *///from w ww  .  ja v  a 2 s  .com
public String evaluateExpressionTemplate(Object contextObject, Map<String, Object> evaluationParameters,
        String expressionTemplate) {
    StandardEvaluationContext context = new StandardEvaluationContext(contextObject);
    context.setVariables(evaluationParameters);
    addCustomFunctions(context);

    ExpressionParser parser = new SpelExpressionParser();

    String result = null;
    try {
        Expression expression = null;
        if (StringUtils.contains(expressionTemplate, UifConstants.EL_PLACEHOLDER_PREFIX)) {
            expression = parser.parseExpression(expressionTemplate, new TemplateParserContext(
                    UifConstants.EL_PLACEHOLDER_PREFIX, UifConstants.EL_PLACEHOLDER_SUFFIX));
        } else {
            expression = parser.parseExpression(expressionTemplate);
        }

        result = expression.getValue(context, String.class);
    } catch (Exception e) {
        LOG.error("Exception evaluating expression: " + expressionTemplate);
        throw new RuntimeException("Exception evaluating expression: " + expressionTemplate, e);
    }

    return result;
}

From source file:org.kuali.rice.krad.uif.view.DefaultExpressionEvaluator.java

/**
 * Attempts to retrieve the {@link Expression} instance for the given expression template, if
 * not found one is created and added to the cache
 * //from   w  w w  .  j a va  2  s.  c  o m
 * @param expressionTemplate template string for the expression
 * @return Expression instance
 */
protected Expression retrieveCachedExpression(String expressionTemplate) {
    Expression expression = null;

    // return from the expression from cache if present
    if (cachedExpressions.containsKey(expressionTemplate)) {
        return cachedExpressions.get(expressionTemplate);
    }

    // not in cache, create the expression object
    if (StringUtils.contains(expressionTemplate, UifConstants.EL_PLACEHOLDER_PREFIX)) {
        expression = parser.parseExpression(expressionTemplate, new TemplateParserContext(
                UifConstants.EL_PLACEHOLDER_PREFIX, UifConstants.EL_PLACEHOLDER_SUFFIX));
    } else {
        expression = parser.parseExpression(expressionTemplate);
    }

    synchronized (cachedExpressions) {
        cachedExpressions.put(expressionTemplate, expression);
    }

    return expression;
}

From source file:org.openehealth.ipf.commons.ihe.core.payload.SpringExpressionResolver.java

public SpringExpressionResolver(final String filePathPattern) {
    Validate.notEmpty(filePathPattern, "log file path/name pattern");
    final ExpressionParser parser = new SpelExpressionParser();
    final TemplateParserContext parserContext = new TemplateParserContext("[", "]");
    parser.parseExpression(filePathPattern, parserContext);
    expression = parser.parseExpression(filePathPattern, parserContext);
}