Search in sources :

Example 6 with JexlException

use of org.apache.commons.jexl3.JexlException in project dbeaver by serge-rider.

the class AbstractDescriptor method parseExpression.

public static Expression parseExpression(String exprString) throws DBException {
    synchronized (AbstractDescriptor.class) {
        if (jexlEngine == null) {
            jexlEngine = new JexlEngine(null, null, null, null);
            jexlEngine.setCache(100);
        }
    }
    try {
        return jexlEngine.createExpression(exprString);
    } catch (JexlException e) {
        throw new DBException("Bad expression", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) JexlEngine(org.apache.commons.jexl2.JexlEngine) JexlException(org.apache.commons.jexl2.JexlException)

Example 7 with JexlException

use of org.apache.commons.jexl3.JexlException in project dbeaver by dbeaver.

the class AbstractDescriptor method parseExpression.

public static Expression parseExpression(String exprString) throws DBException {
    synchronized (AbstractDescriptor.class) {
        if (jexlEngine == null) {
            jexlEngine = new JexlEngine(null, null, null, null);
            jexlEngine.setCache(100);
        }
    }
    try {
        return jexlEngine.createExpression(exprString);
    } catch (JexlException e) {
        throw new DBException("Bad expression", e);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) JexlEngine(org.apache.commons.jexl2.JexlEngine) JexlException(org.apache.commons.jexl2.JexlException)

Example 8 with JexlException

use of org.apache.commons.jexl3.JexlException in project opennms by OpenNMS.

the class JexlIndexStorageStrategy method getResourceNameFromIndex.

/**
 * {@inheritDoc}
 */
@Override
public String getResourceNameFromIndex(CollectionResource resource) {
    String resourceName = null;
    try {
        UnifiedJEXL.Expression expr = EL.parse(m_parameters.get(PARAM_INDEX_FORMAT));
        JexlContext context = new MapContext();
        m_parameters.entrySet().forEach((entry) -> {
            context.set(entry.getKey(), entry.getValue());
        });
        updateContext(context, resource);
        resourceName = (String) expr.evaluate(new ReadonlyContext(context));
    } catch (JexlException e) {
        LOG.error("getResourceNameFromIndex(): error evaluating index-format [{}] as a Jexl Expression", m_parameters.get(PARAM_INDEX_FORMAT), e);
    } finally {
        if (resourceName == null) {
            resourceName = resource.getInstance();
        }
    }
    if ("true".equals(m_parameters.get(PARAM_CLEAN_OUTPUT)) && resourceName != null) {
        resourceName = resourceName.replaceAll("\\s+", "_").replaceAll(":", "_").replaceAll("\\\\", "_").replaceAll("[\\[\\]]", "_").replaceAll("[|/]", "_").replaceAll("=", "").replaceAll("[_]+$", "").replaceAll("___", "_");
    }
    LOG.debug("getResourceNameFromIndex(): {}", resourceName);
    return resourceName;
}
Also used : UnifiedJEXL(org.apache.commons.jexl2.UnifiedJEXL) JexlException(org.apache.commons.jexl2.JexlException) JexlContext(org.apache.commons.jexl2.JexlContext) ReadonlyContext(org.apache.commons.jexl2.ReadonlyContext) MapContext(org.apache.commons.jexl2.MapContext)

Aggregations

JexlException (org.apache.commons.jexl2.JexlException)8 MapContext (org.apache.commons.jexl2.MapContext)4 JexlContext (org.apache.commons.jexl2.JexlContext)3 JexlEngine (org.apache.commons.jexl2.JexlEngine)2 DBException (org.jkiss.dbeaver.DBException)2 Attribute (org.traccar.model.Attribute)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Expression (org.apache.commons.jexl2.Expression)1 ReadonlyContext (org.apache.commons.jexl2.ReadonlyContext)1 UnifiedJEXL (org.apache.commons.jexl2.UnifiedJEXL)1 ExpressionException (org.opennms.netmgt.measurements.api.exceptions.ExpressionException)1 Expression (org.opennms.netmgt.measurements.model.Expression)1