Package org.apache.commons.jexl2

Examples of org.apache.commons.jexl2.MapContext


        return result;
    }

    public String evaluate(final String expression, final AbstractAttributable attributable) {

        final JexlContext jexlContext = new MapContext();

        if (attributable instanceof SyncopeUser) {
            SyncopeUser user = (SyncopeUser) attributable;

            jexlContext.set("username", user.getUsername() != null
                    ? user.getUsername()
                    : "");
            jexlContext.set("creationDate", user.getCreationDate() != null
                    ? user.getDateFormatter().format(user.getCreationDate())
                    : "");
            jexlContext.set("lastLoginDate", user.getLastLoginDate() != null
                    ? user.getDateFormatter().format(user.getLastLoginDate())
                    : "");
            jexlContext.set("failedLogins", user.getFailedLogins() != null
                    ? user.getFailedLogins()
                    : "");
            jexlContext.set("changePwdDate", user.getChangePwdDate() != null
                    ? user.getDateFormatter().format(user.getChangePwdDate())
                    : "");
        }

        addAttrsToContext(attributable.getAttributes(), jexlContext);
View Full Code Here


    public JexlContext addAttrsToContext(final Collection<? extends AbstractAttr> attributes,
            final JexlContext jexlContext) {

        JexlContext context = jexlContext == null
                ? new MapContext()
                : jexlContext;

        for (AbstractAttr attribute : attributes) {
            List<String> attributeValues = attribute.getValuesAsStrings();
            String expressionValue = attributeValues.isEmpty()
View Full Code Here

    public JexlContext addDerAttrsToContext(final Collection<? extends AbstractDerAttr> derAttributes,
            final Collection<? extends AbstractAttr> attributes, final JexlContext jexlContext) {

        JexlContext context = jexlContext == null
                ? new MapContext()
                : jexlContext;

        for (AbstractDerAttr attribute : derAttributes) {
            String expressionValue = attribute.getValue(attributes);
            if (expressionValue == null) {
View Full Code Here

        return context;
    }

    public String evaluate(final String expression, final AbstractAttributableTO attributableTO) {

        final JexlContext context = new MapContext();

        if (attributableTO instanceof UserTO) {
            UserTO user = (UserTO) attributableTO;

            context.set("username", user.getUsername() != null
                    ? user.getUsername()
                    : "");
            context.set("password", user.getPassword() != null
                    ? user.getPassword()
                    : "");
        }

        for (AttributeTO attribute : attributableTO.getAttributes()) {
            List<String> attributeValues = attribute.getValues();
            String expressionValue = attributeValues.isEmpty()
                    ? ""
                    : attributeValues.get(0);

            LOG.debug("Add attribute {} with value {}", new Object[] { attribute.getSchema(), expressionValue });

            context.set(attribute.getSchema(), expressionValue);
        }
        for (AttributeTO attribute : attributableTO.getDerivedAttributes()) {
            List<String> attributeValues = attribute.getValues();
            String expressionValue = attributeValues.isEmpty()
                    ? ""
                    : attributeValues.get(0);

            LOG.debug("Add attribute {} with value {}", new Object[] { attribute.getSchema(), expressionValue });

            context.set(attribute.getSchema(), expressionValue);
        }
        for (AttributeTO attribute : attributableTO.getVirtualAttributes()) {
            List<String> attributeValues = attribute.getValues();
            String expressionValue = attributeValues.isEmpty()
                    ? ""
                    : attributeValues.get(0);

            LOG.debug("Add attribute {} with value {}", new Object[] { attribute.getSchema(), expressionValue });

            context.set(attribute.getSchema(), expressionValue);
        }

        // Evaluate expression using the context prepared before
        return evaluate(expression, context);
    }
View Full Code Here

    }

    private boolean evaluateMandatoryCondition(final String mandatoryCondition,
            final List<? extends AbstractAttr> attributes) {

        JexlContext jexlContext = new MapContext();
        jexlUtil.addAttrsToContext(attributes, jexlContext);

        return Boolean.parseBoolean(jexlUtil.evaluate(mandatoryCondition, jexlContext));
    }
View Full Code Here

        JMeterContext jmctx = JMeterContextService.getContext();
        JMeterVariables vars = jmctx.getVariables();

        try
        {
            JexlContext jc = new MapContext();
            jc.set("log", log); //$NON-NLS-1$
            jc.set("ctx", jmctx); //$NON-NLS-1$
            jc.set("vars", vars); //$NON-NLS-1$
            jc.set("props", JMeterUtils.getJMeterProperties()); //$NON-NLS-1$
            // Previously mis-spelt as theadName
            jc.set("threadName", Thread.currentThread().getName()); //$NON-NLS-1$
            jc.set("sampler", currentSampler); //$NON-NLS-1$ (may be null)
            jc.set("sampleResult", previousResult); //$NON-NLS-1$ (may be null)
            jc.set("OUT", System.out);//$NON-NLS-1$

            // Now evaluate the script, getting the result
            Expression e = getJexlEngine().createExpression( exp );
            Object o = e.evaluate(jc);
            if (o != null)
View Full Code Here

    }

    private boolean evaluateMandatoryCondition(final String mandatoryCondition,
            final List<? extends AbstractAttr> attributes) {

        JexlContext jexlContext = new MapContext();
        jexlUtil.addAttrsToContext(attributes, jexlContext);

        return Boolean.parseBoolean(jexlUtil.evaluate(mandatoryCondition, jexlContext));
    }
View Full Code Here

      script = ENGINE.createScript(filter);
    } catch (JexlException e) {
      throw new FeedEntryFilterException("Exception while parsing expression " + filter, e);
    }

    JexlContext context = new MapContext();
    context.set("title", Jsoup.parse(entry.getContent().getTitle()).text().toLowerCase());
    context.set("author", entry.getContent().getAuthor().toLowerCase());
    context.set("content", Jsoup.parse(entry.getContent().getContent()).text().toLowerCase());
    context.set("url", entry.getUrl().toLowerCase());

    Callable<Object> callable = script.callable(context);
    Future<Object> future = executor.submit(callable);
    Object result = null;
    try {
View Full Code Here

  public static JexlContext fillContext(Set<String> dataObjectIds,
      DataObjectService dataObjectHandler,
      String uniqueProcessId,
      String instanceId) {
    // create context
    JexlContext jc = new MapContext();
       
    // fill context
    for (String id : dataObjectIds) {
      jc.set(id, dataObjectHandler.loadObject(uniqueProcessId, instanceId, id));
    }
   
    return jc;
  }
View Full Code Here

        }

        // Evaluate AccountLink expression
        String evalAccountLink = null;
        if (StringUtils.isNotBlank(attrUtil.getAccountLink(resource))) {
            final JexlContext jexlContext = new MapContext();
            JexlUtil.addFieldsToContext(subject, jexlContext);
            JexlUtil.addAttrsToContext(subject.getAttrs(), jexlContext);
            JexlUtil.addDerAttrsToContext(subject.getDerAttrs(), subject.getAttrs(), jexlContext);
            evalAccountLink = JexlUtil.evaluate(attrUtil.getAccountLink(resource), jexlContext);
        }
View Full Code Here

TOP

Related Classes of org.apache.commons.jexl2.MapContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.