Example usage for org.apache.commons.jxpath.ri.compiler ExpressionPath getPredicates

List of usage examples for org.apache.commons.jxpath.ri.compiler ExpressionPath getPredicates

Introduction

In this page you can find the example usage for org.apache.commons.jxpath.ri.compiler ExpressionPath getPredicates.

Prototype

public Expression[] getPredicates() 

Source Link

Document

Predicates are the expressions in brackets that may follow the root expression of the path.

Usage

From source file:org.chiba.xml.xpath.impl.JXPathReferenceFinderImpl.java

private void addExpressionReferences(Map references, Expression context, Expression expression) {
    // handle location pathes like "../relative/path" or "//absolute/path"
    if (expression instanceof LocationPath) {
        // put location path in context and add as reference
        LocationPath locationPath = (LocationPath) expression;
        Path path = addLocationPath(context, (LocationPath) expression);
        references.put(path.toString(), path);

        // pass empty location path when there is no context
        Expression contextExpression = (Expression) (context == null
                ? this.compiler.locationPath(locationPath.isAbsolute(), null)
                : context);//ww  w .  j a  va  2 s . c o m
        // add references of step predicates
        addStepReferences(references, contextExpression, locationPath.getSteps());
        return;
    }
    // handle expression pathes like "instance('id')/path" or "ext:function()[predicate]/path"
    if (expression instanceof ExpressionPath) {
        // add expression path as reference
        ExpressionPath expressionPath = (ExpressionPath) expression;
        references.put(expressionPath.toString(), expressionPath);

        // add references in expression predicates
        Expression[] predicates = expressionPath.getPredicates();
        for (int i = 0; predicates != null && i < predicates.length; i++) {
            addExpressionReferences(references, expressionPath.getExpression(), predicates[i]);
        }

        // add references in step predicates
        addStepReferences(references, expressionPath.getExpression(), expressionPath.getSteps());
        return;
    }
    // handle standalone instance() function
    if (expression instanceof ExtensionFunction) {
        ExtensionFunction function = (ExtensionFunction) expression;
        // todo: how to handle all functions returning a nodeset ?
        if (function.getFunctionName().getName().equals("instance")) {
            references.put(expression.toString(), expression);
            return;
        }
    }
    // handle all other operations like "black + white" or "count(../apples and /oranges)"
    if (expression instanceof Operation) {
        Operation operation = (Operation) expression;
        Expression[] arguments = operation.getArguments();

        // add references in function arguments
        for (int i = 0; arguments != null && i < arguments.length; i++) {
            addExpressionReferences(references, context, arguments[i]);
        }
    }
    // don't handle constants
    // if (expression instanceof Constant) {
    // }
    // don't handle variable references (maybe needed someday)
    // if (expression instanceof VariableReference) {
    //  }
}

From source file:org.chiba.xml.xpath.impl.JXPathReferenceFinderImpl.java

private Path addSteps(Expression context, Step[] steps, int length) {
    List stepList = new ArrayList();
    if (context instanceof Path) {
        Path path = (Path) context;
        if (path.getSteps() != null) {
            stepList.addAll(Arrays.asList(((Path) context).getSteps()));
        }// w w  w.  ja  va  2 s  . co  m
    }
    for (int i = 0; i < length; i++) {
        stepList.add(steps[i]);
    }
    Step[] stepArray = (Step[]) stepList.toArray(new Step[stepList.size()]);

    if (context instanceof LocationPath) {
        LocationPath locationPath = (LocationPath) context;
        return (Path) this.compiler.locationPath(locationPath.isAbsolute(), stepArray);
    }
    if (context instanceof ExpressionPath) {
        ExpressionPath expressionPath = (ExpressionPath) context;
        return (Path) this.compiler.expressionPath(expressionPath.getExpression(),
                expressionPath.getPredicates(), stepArray);
    }
    return (Path) this.compiler.expressionPath(context, null, stepArray);

}

From source file:org.xchain.framework.jxpath.JXPathValidator.java

static void validateExpressionPath(ExpressionPath ep, NamespaceContext xmlns) {
    validateExpression(ep.getExpression(), xmlns);
    for (Expression predicate : ep.getPredicates()) {
        validateExpression(predicate, xmlns);
    }/*from  www .ja  v a  2s. c  o  m*/
}