Example usage for org.apache.commons.jxpath.ri Parser parseExpression

List of usage examples for org.apache.commons.jxpath.ri Parser parseExpression

Introduction

In this page you can find the example usage for org.apache.commons.jxpath.ri Parser parseExpression.

Prototype

public static Object parseExpression(String expression, Compiler compiler) 

Source Link

Document

Parses the XPath expression.

Usage

From source file:com.w20e.socrates.model.Eval.java

/**
 * Create a new Eval class.//from  www . jav a2s .  c  om
 * @param expr Expression to use for eval.
 * @param m Model
 * @param i Instance
 */
public Eval(final String expr, final Model m, final Instance i) {

    try {
        this.lv = (Expression) Parser.parseExpression(expr, ExpressionCompiler.getInstance());
        this.lv = XRefSolver.resolve(m, i, this.lv, null);
    } catch (Exception e) {
        this.lv = new Undef();
    }

    this.model = m;
    this.instance = i;
}

From source file:com.w20e.socrates.model.Eval.java

/**
 * Get the left operand. This will first resolve the expression
 * that was used in the constructor, and than parse it, and return the
 * eval'ed result of that./*from   w w  w . j a v a2  s .  c om*/
 * @return Left Operand for this expression. This will first parse
 * the eval'ed result of the left operand as string.
 */
@Override
public final Expression getLeftOperand() {

    try {
        return (Expression) Parser.parseExpression(this.lv.eval().toString(), ExpressionCompiler.getInstance());

    } catch (Exception e) {
        return new Undef();
    }
}

From source file:org.chiba.xml.xforms.constraints.DependencyGraph.java

/**
 * determines which nodes are referenced by given xpath expression and returns them as nodes.
 *
 * @param xpath - the xpath expression under examination
 * @return a list with nodes referenced in given xpath
 *//*from  w w w .j a  v  a2s  .com*/
public Vector getXPathRefNodes(JXPathContext relativeContext, String xpath) {
    ReferenceFinder referenceFinder = new ReferenceFinder();
    Parser.parseExpression(xpath, referenceFinder);

    List pathes = referenceFinder.getLocationPathes();
    Vector refNodes = new Vector();

    for (int i = 0; i < pathes.size(); i++) {
        String refPath = pathes.get(i).toString();
        Instance instance = (Instance) relativeContext.getParentContext().getContextBean();
        JXPathContext context = relativeContext;

        if (PathUtil.hasInstanceFunction(refPath)) {
            String instanceId = PathUtil.getInstanceId(instance.getModel(), refPath);

            // use container for instance lookup to allow cross-model references
            instance = (Instance) instance.getModel().getContainer().lookup(instanceId);
            context = instance.getInstanceContext();
        }

        // iterate all referenced nodes
        Iterator iterator = context.iteratePointers(refPath);

        while (iterator.hasNext()) {
            Pointer localPointer = (Pointer) iterator.next();
            //                Object node = localPointer.getNode();
            //                if (node instanceof Pointer) {
            //                    localPointer = (Pointer) node;
            //                }

            String realPath = localPointer.asPath();
            LocalValue localValue = instance.getModelItem(realPath);

            if (localValue != null) {
                // add *existing* reference node
                refNodes.add(localValue.getNode());
            }
        }
    }

    return refNodes;
}

From source file:org.chiba.xml.xforms.xpath.XPathCompiler.java

/**
 * __UNDOCUMENTED__//  w  ww .j a va  2 s.  c om
 *
 * @param xpath __UNDOCUMENTED__
 * @return __UNDOCUMENTED__
 * @throws XFormsException __UNDOCUMENTED__
 */
public Document compile(String xpath) throws XFormsException {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        factory.setValidating(false);

        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.newDocument();
        Element root = document.createElement("xpath");
        root.setAttribute("expression", xpath);
        document.appendChild(root);

        Element result = (Element) Parser.parseExpression(xpath, new DOMCompiler(document));
        root.appendChild(result);

        return document;
    } catch (Exception e) {
        throw new XFormsException(e);
    }
}

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

/**
 * Returns the set of all references to other nodes contained in the given
 * XPath expression.//from   w  w w .  j  a  v a2 s  . c  om
 *
 * @param xpath the XPath expression.
 * @return the set of all references to other nodes.
 * @throws XFormsException if a reference detection error occurred.
 */
public Set getReferences(String xpath) throws XFormsException {
    try {
        if (this.compiler == null) {
            this.compiler = new TreeCompiler();
        }

        Object expression = Parser.parseExpression(xpath, this.compiler);
        Map references = new HashMap();
        addExpressionReferences(references, null, (Expression) expression);

        return references.keySet();
    } catch (Exception e) {
        throw new XFormsException(e);
    }
}

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

/**
 * Parses the specified xpath and throws a JXPathException if there is a syntax exception.
 *///from   www  . j  a v  a 2 s.co  m
public static void validate(String xpath) {
    Parser.parseExpression(xpath, compiler);
}

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

public static void validate(String xpath, NamespaceContext xmlns) {
    Expression expression = (Expression) Parser.parseExpression(xpath, compiler);
    validateExpression(expression, xmlns);
}