Search in sources :

Example 1 with JXPathInvalidSyntaxException

use of org.apache.commons.jxpath.JXPathInvalidSyntaxException in project collect by openforis.

the class AbstractExpression method findNode.

protected Node<?> findNode(Node<?> contextNode, Node<?> thisNode, Predicate<Node<?>> predicate) throws InvalidExpressionException {
    try {
        JXPathContext jxPathContext = createJXPathContext(contextNode, thisNode);
        Iterator<?> pointers = compiledExpression.iteratePointers(jxPathContext);
        while (pointers.hasNext()) {
            Object item = pointers.next();
            if (item instanceof ModelNodePointer) {
                ModelNodePointer modelNodePointer = (ModelNodePointer) item;
                Object ptrNode = modelNodePointer.getNode();
                if (ptrNode != null && ptrNode instanceof Node) {
                    Node<?> node = (Node<?>) ptrNode;
                    if (predicate.evaluate(node)) {
                        return node;
                    }
                }
            } else if (item instanceof VariablePointer && ((VariablePointer) item).getName().equals(THIS)) {
                if (predicate.evaluate(thisNode)) {
                    return thisNode;
                }
            }
        // ignore node pointer if it's a NullPointer
        }
        return null;
    } catch (IllegalArgumentException e) {
        throw new InvalidExpressionException(e.getMessage(), this.compiledExpression.toString());
    } catch (JXPathInvalidSyntaxException e) {
        throw new InvalidExpressionException(e.getMessage());
    }
}
Also used : JXPathInvalidSyntaxException(org.apache.commons.jxpath.JXPathInvalidSyntaxException) ModelJXPathContext(org.openforis.idm.model.expression.internal.ModelJXPathContext) JXPathContext(org.apache.commons.jxpath.JXPathContext) VariablePointer(org.apache.commons.jxpath.ri.model.VariablePointer) Node(org.openforis.idm.model.Node) ModelNodePointer(org.openforis.idm.model.expression.internal.ModelNodePointer)

Example 2 with JXPathInvalidSyntaxException

use of org.apache.commons.jxpath.JXPathInvalidSyntaxException in project collect by openforis.

the class AbstractExpression method iterateMultiple.

protected void iterateMultiple(Node<?> contextNode, Node<?> thisNode, NodeVisitor visitor) throws InvalidExpressionException {
    try {
        JXPathContext jxPathContext = createJXPathContext(contextNode, thisNode);
        Iterator<?> pointers = compiledExpression.iteratePointers(jxPathContext);
        while (pointers.hasNext()) {
            Object item = pointers.next();
            if (item instanceof ModelNodePointer) {
                ModelNodePointer modelNodePointer = (ModelNodePointer) item;
                Object ptrNode = modelNodePointer.getNode();
                if (ptrNode != null && ptrNode instanceof Node) {
                    Node<?> node = (Node<?>) ptrNode;
                    visitor.visit(node, node.getIndex());
                }
            } else if (item instanceof VariablePointer && ((VariablePointer) item).getName().equals(THIS)) {
                visitor.visit(thisNode, thisNode.getIndex());
            }
        // ignore node pointer if it's a NullPointer
        }
    } catch (IllegalArgumentException e) {
        throw new InvalidExpressionException(e.getMessage(), this.compiledExpression.toString());
    } catch (JXPathInvalidSyntaxException e) {
        throw new InvalidExpressionException(e.getMessage());
    }
}
Also used : JXPathInvalidSyntaxException(org.apache.commons.jxpath.JXPathInvalidSyntaxException) ModelJXPathContext(org.openforis.idm.model.expression.internal.ModelJXPathContext) JXPathContext(org.apache.commons.jxpath.JXPathContext) VariablePointer(org.apache.commons.jxpath.ri.model.VariablePointer) Node(org.openforis.idm.model.Node) ModelNodePointer(org.openforis.idm.model.expression.internal.ModelNodePointer)

Example 3 with JXPathInvalidSyntaxException

use of org.apache.commons.jxpath.JXPathInvalidSyntaxException in project collect by openforis.

the class AbstractExpression method evaluateSingle.

protected Object evaluateSingle(Node<?> contextNode, Node<?> thisNode) throws InvalidExpressionException {
    try {
        JXPathContext jxPathContext = createJXPathContext(contextNode, thisNode);
        Object object = compiledExpression.getValue(jxPathContext);
        return object;
    } catch (IllegalArgumentException e) {
        throw new InvalidExpressionException(e.getMessage(), this.compiledExpression.toString());
    } catch (JXPathInvalidSyntaxException e) {
        throw new InvalidExpressionException(e.getMessage(), this.compiledExpression.toString());
    } catch (JXPathNotFoundException e) {
        return null;
    }
}
Also used : JXPathNotFoundException(org.apache.commons.jxpath.JXPathNotFoundException) JXPathInvalidSyntaxException(org.apache.commons.jxpath.JXPathInvalidSyntaxException) ModelJXPathContext(org.openforis.idm.model.expression.internal.ModelJXPathContext) JXPathContext(org.apache.commons.jxpath.JXPathContext)

Example 4 with JXPathInvalidSyntaxException

use of org.apache.commons.jxpath.JXPathInvalidSyntaxException in project collect by openforis.

the class ExpressionFactory method compileExpression.

private ModelJXPathCompiledExpression compileExpression(String expression, boolean normalizeNumber) throws InvalidExpressionException {
    ExpressionKey key = new ExpressionKey(expression, normalizeNumber);
    ModelJXPathCompiledExpression compiled = COMPILED_EXPRESSIONS.get(key);
    if (compiled == null) {
        try {
            String normalizedExpression = Path.getNormalizedPath(expression);
            compiled = ModelJXPathContext.compile(this, normalizedExpression, normalizeNumber);
            COMPILED_EXPRESSIONS.put(key, compiled);
        } catch (JXPathInvalidSyntaxException e) {
            throw new InvalidExpressionException(e.getMessage());
        }
    }
    return compiled;
}
Also used : ModelJXPathCompiledExpression(org.openforis.idm.model.expression.internal.ModelJXPathCompiledExpression) JXPathInvalidSyntaxException(org.apache.commons.jxpath.JXPathInvalidSyntaxException)

Aggregations

JXPathInvalidSyntaxException (org.apache.commons.jxpath.JXPathInvalidSyntaxException)4 JXPathContext (org.apache.commons.jxpath.JXPathContext)3 ModelJXPathContext (org.openforis.idm.model.expression.internal.ModelJXPathContext)3 VariablePointer (org.apache.commons.jxpath.ri.model.VariablePointer)2 Node (org.openforis.idm.model.Node)2 ModelNodePointer (org.openforis.idm.model.expression.internal.ModelNodePointer)2 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)1 ModelJXPathCompiledExpression (org.openforis.idm.model.expression.internal.ModelJXPathCompiledExpression)1