Example usage for org.springframework.expression.spel.standard SpelExpressionParser SpelExpressionParser

List of usage examples for org.springframework.expression.spel.standard SpelExpressionParser SpelExpressionParser

Introduction

In this page you can find the example usage for org.springframework.expression.spel.standard SpelExpressionParser SpelExpressionParser.

Prototype

public SpelExpressionParser() 

Source Link

Document

Create a parser with default settings.

Usage

From source file:io.gravitee.gateway.el.SpelTemplateEngine.java

@Override
public String convert(String expression) {
    // Escape sequence
    final String replaced = expression.replaceAll(EXPRESSION_REGEX, EXPRESSION_REGEX_SUBSTITUTE);

    return new SpelExpressionParser().parseExpression(replaced, new TemplateParserContext())
            .getValue(getTemplateContext().getContext(), String.class);
}

From source file:net.nan21.dnet.core.presenter.converter.AbstractDsConverter.java

public AbstractDsConverter() {
    this.parser = new SpelExpressionParser();
}

From source file:org.springframework.batch.admin.web.JsonWrapper.java

@SuppressWarnings("unchecked")
public JsonWrapper(String content) throws Exception {
    this.content = content;
    try {/*from  www  . j a va  2  s  .  c  om*/
        target = new MappingJsonFactory().createJsonParser(content.replace("\\", "/")).readValueAs(Map.class);
    } catch (JsonParseException e) {
        throw new JsonMappingException("Cannot create wrapper for:\n" + content, e);
    }
    context = new StandardEvaluationContext();
    context.addPropertyAccessor(new MapAccessor());
    parser = new SpelExpressionParser();
}

From source file:com.px100systems.util.RuleEngine.java

/**
 * Set the list of rules. teh first one returning non-null, wins.
 * @param rules a list of Spring EL expressions typically "condition ? result : laternateResult" ones
 *///from w  w  w. j  av  a  2  s. c  om
@Required
public void setRules(List<String> rules) {
    this.rules = new ArrayList<Expression>();

    SpelExpressionParser parser = new SpelExpressionParser();
    for (String s : rules)
        this.rules.add(parser.parseExpression(s));
}

From source file:ar.com.zauber.commons.web.uri.factory.ExpressionMapUriFactoryTest.java

/** set up */
@Before//from   www  .ja  v a2  s.  c o  m
public final void setUp() {
    Map<String, String> uris = new HashMap<String, String>();
    uris.put("propertiesAndMethods",
            "/{#root[0].propA}+{#root[0].computedProperty()}+" + "{#root[0].propertyCollection()[2]}");
    uris.put("singleArgument", "/hola/que/tal/{#root[0].propA}");
    uris.put("multipleArguments", "/hola/que/tal/{#root[0].propA}...{#root[1]}");
    uris.put("encodedArgument", "/hola/que/tal/{#encode(#root[0].propB)}");
    expMapUriFactory = new ExpressionMapUriFactory(new SpelExpressionParser(), uris);

    final Map<String, String> turis = new HashMap<String, String>();
    turis.put("usuario", "/v1/u/{username}/empresas/");
    turis.put("foo", "bar");
    uriTemplateMapUriFactory = new ExpressionMapUriFactory(turis, ExpressionMapUriFactory.Type.URITEMPLATE);
}

From source file:org.arrow.model.gateway.impl.ExclusiveGateway.java

@Override
public List<EventMessage> fork(Execution execution, ExecutionService service) {

    ExpressionParser parser = new SpelExpressionParser();

    for (Flow flow : getOutgoingFlows()) {

        // handle multiple outgoing flows
        ConditionExpression ce = ((SequenceFlow) flow).getConditionExpression();

        if (ce == null) {
            continue;
        }//from www.j  av a  2  s .com

        StandardEvaluationContext context = new StandardEvaluationContext();
        context.setVariables(execution.getVariables());

        Expression expr = parser.parseExpression(ce.getCondition());
        Boolean result = expr.getValue(context, Boolean.class);

        if ((result != null) && (result)) {
            flow.enableRelation(execution);
            break;
        }
    }

    // mark gateway as finished
    execution.setState(State.SUCCESS);
    finish(execution, service);

    return Arrays.asList();
}

From source file:py.una.pol.karaku.dao.filter.KarakuEntityFilterHandler.java

@PostConstruct
public void init() {

    parser = new SpelExpressionParser();
}

From source file:org.arrow.model.gateway.impl.InclusiveGateway.java

/**
 * {@inheritDoc}/*from ww w.ja va2  s .  c o m*/
 */
@Override
public List<EventMessage> fork(Execution execution, ExecutionService service) {

    ExpressionParser parser = new SpelExpressionParser();

    for (Flow flow : getOutgoingFlows()) {

        // handle multiple outgoing flows
        ConditionExpression ce = ((SequenceFlow) flow).getConditionExpression();
        notNull(ce, "no condition detected on flow " + flow.getId());

        StandardEvaluationContext context = new StandardEvaluationContext();
        context.setVariables(execution.getVariables());

        Expression expression = parser.parseExpression(ce.getCondition());
        Boolean result = expression.getValue(context, Boolean.class);

        if ((result != null) && result) {
            flow.enableRelation(execution);
        }
    }

    // mark gateway as finished
    execution.setState(State.SUCCESS);
    finish(execution, service);

    return Arrays.asList();
}

From source file:org.ldaptive.beans.spring.SpringClassDescriptor.java

/** {@inheritDoc} */
@Override/*from ww  w.  j a  va2  s . c o  m*/
public void initialize(final Class<?> type) {
    // check for entry annotation
    final Entry entryAnnotation = AnnotationUtils.findAnnotation(type, Entry.class);
    if (entryAnnotation != null) {
        if (!entryAnnotation.dn().equals("")) {
            setDnValueMutator(new DnValueMutator() {
                @Override
                public String getValue(final Object object) {
                    final ExpressionParser parser = new SpelExpressionParser();
                    final Expression exp = parser.parseExpression(entryAnnotation.dn());
                    return exp.getValue(context, object, String.class);
                }

                @Override
                public void setValue(final Object object, final String value) {
                }
            });
        }
        for (final Attribute attr : entryAnnotation.attributes()) {
            final String expr = attr.property();
            final ExpressionParser parser = new SpelExpressionParser();
            final Expression exp = parser.parseExpression(expr);
            addAttributeValueMutator(new AttributeValueMutator() {
                @Override
                public String getName() {
                    return attr.name();
                }

                @Override
                public boolean isBinary() {
                    return attr.binary();
                }

                @Override
                public SortBehavior getSortBehavior() {
                    return attr.sortBehavior();
                }

                @Override
                public Collection<String> getStringValues(final Object object) {
                    @SuppressWarnings("unchecked")
                    final Collection<String> values = (Collection<String>) exp.getValue(context, object,
                            Collection.class);
                    return values;
                }

                @Override
                public Collection<byte[]> getBinaryValues(final Object object) {
                    @SuppressWarnings("unchecked")
                    final Collection<byte[]> values = (Collection<byte[]>) exp.getValue(context, object,
                            Collection.class);
                    return values;
                }

                @Override
                public void setStringValues(final Object object, final Collection<String> values) {
                    exp.setValue(context, object, values);
                }

                @Override
                public void setBinaryValues(final Object object, final Collection<byte[]> values) {
                    exp.setValue(context, object, values);
                }
            });
        }
    }
}

From source file:org.ldaptive.beans.spring.SpelAttributeValueMutator.java

/**
 * Creates a new spel attribute value mutator.
 *
 * @param  attr  containing the SPEL configuration
 * @param  context  containing the values
 *//*from ww w.j  a v a2  s.  c om*/
public SpelAttributeValueMutator(final Attribute attr, final EvaluationContext context) {
    attribute = attr;

    final ExpressionParser parser = new SpelExpressionParser();
    expression = parser
            .parseExpression(attribute.property().length() > 0 ? attribute.property() : attribute.name());
    evaluationContext = context;
    if ("".equals(attribute.transcoder())) {
        transcoder = null;
    } else {
        transcoder = parser.parseExpression(attribute.transcoder()).getValue(ValueTranscoder.class);
    }
}