Example usage for org.apache.commons.jxpath.ri.compiler LocationPath isAbsolute

List of usage examples for org.apache.commons.jxpath.ri.compiler LocationPath isAbsolute

Introduction

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

Prototype

public boolean isAbsolute() 

Source Link

Document

Learn whether this LocationPath is absolute.

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);// w w w  .  j  av  a  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 addLocationPath(Expression context, LocationPath path) {
    if (context == null || path.isAbsolute()) {
        return path;
    }/*from  w  w w  . j a  va2 s . c o  m*/

    Step[] steps = path.getSteps();
    return addSteps(context, steps, steps.length);
}

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()));
        }//from w ww .  j a  v  a  2  s . com
    }
    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);

}