Package org.apache.commons.jxpath

Examples of org.apache.commons.jxpath.CompiledExpression


                                      startElement.raw,
                                      startElement.attributes);

            } else if (ev instanceof StartRepeat) {
                StartRepeat startRepeat = (StartRepeat)ev;
                final CompiledExpression nodeset = startRepeat.nodeset;
                Iterator iter = null;
                try {
                    if (nodeset == null) {
                        iter = NULL_ITER;
                    } else {
                        iter =
                            nodeset.iteratePointers(jxpathContext);
                    }
                } catch (Exception exc) {
                    throw new SAXParseException(exc.getMessage(),
                                                ev.location,
                                                exc);
                } catch (Error err) {
                    throw new SAXParseException(err.getMessage(),
                                                ev.location,
                                                null);
                }
                while (iter.hasNext()) {
                    Object value;
                    Pointer ptr = (Pointer)iter.next();
                    try {
                        value = ptr.getNode();
                    } catch (Exception exc) {
                        throw new SAXParseException(exc.getMessage(),
                                                        ev.location,
                                                        exc);
                    }
                    JXPathContext localJXPathContext =
                        jxpathContextFactory.newContext(null, value);
                    String path = "";
                    if (contextPath != null) {
                        path = contextPath + "/.";
                    }
                    path += ptr.asPath();
                    execute(consumer,
                            form,
                            currentView,
                            path,
                            localJXPathContext,
                            startRepeat.next,
                            startRepeat.endRepeat);
                }
                ev = startRepeat.endRepeat.next;
                continue;
            } else if (ev instanceof StartGroup) {
                StartGroup startGroup = (StartGroup)ev;
                StartElement startElement = startGroup.startElement;
                consumer.startElement(startElement.namespaceURI,
                                      startElement.localName,
                                      startElement.raw,
                                      startElement.attributes);
                final CompiledExpression ref = startGroup.ref;
                if (ref != null) {
                    Object value;
                    try {
                        value = ref.getValue(jxpathContext);
                    } catch (Exception exc) {
                        throw new SAXParseException(exc.getMessage(),
                                                    ev.location,
                                                    exc);
                    }
                    JXPathContext localJXPathContext =
                        jxpathContextFactory.newContext(null, value);
                    String path = "";
                    if (contextPath != null) {
                        path = contextPath + "/.";
                    }
                    path += startElement.attributes.getValue(REF);
                    execute(consumer,
                            form,
                            currentView,
                            path,
                            localJXPathContext,
                            startGroup.next,
                            startGroup.endGroup);
                    ev = startGroup.endGroup;
                    continue;
                }
            } else if (ev instanceof StartItemSet) {
                StartItemSet startItemSet = (StartItemSet)ev;
                final CompiledExpression nodeset = startItemSet.nodeset;
                Iterator iter = null;
                try {
                    if (nodeset == null) {
                        iter = NULL_ITER;
                    } else {
                        iter =
                            nodeset.iteratePointers(jxpathContext);
                    }
                } catch (Exception exc) {
                    throw new SAXParseException(exc.getMessage(),
                                                ev.location,
                                                exc);
                } catch (Error err) {
                    throw new SAXParseException(err.getMessage(),
                                                ev.location,
                                                null);
                }
                while (iter.hasNext()) {
                    Object value;
                    Pointer ptr = (Pointer)iter.next();
                    try {
                        value = ptr.getNode();
                    } catch (Exception exc) {
                        throw new SAXParseException(exc.getMessage(),
                                                        ev.location,
                                                        exc);
                    }
                    JXPathContext localJXPathContext =
                        jxpathContextFactory.newContext(null, value);
                    AttributesImpl attrs = new AttributesImpl();
                    attrs.addAttribute(NS, "ref", "ref", "CDATA",
                                       ptr.asPath());
                    consumer.startElement(NS, "item", "item",
                                          attrs);
                    String path = "";
                    if (contextPath != null) {
                        path = contextPath + "/.";
                    }
                    path += ptr.asPath();
                    execute(consumer,
                            form,
                            currentView,
                            ptr.asPath(),
                            localJXPathContext,
                            startItemSet.next,
                            startItemSet.endItemSet);
                    consumer.endElement(NS, "item", "item");
                }
                ev = startItemSet.endItemSet.next;
                continue;
            } else if (ev instanceof StartInputControl) {
                //
                // input, textarea, secret, select1, selectMany
                //
                StartInputControl startInputControl =
                    (StartInputControl)ev;
                CompiledExpression ref = startInputControl.ref;
                StartElement startElement = startInputControl.startElement;
                String refStr = startElement.attributes.getValue("ref");
                consumer.startElement(startElement.namespaceURI,
                                      startElement.localName,
                                      startElement.raw,
                                      startElement.attributes);
                if (ref != null) {
                    Iterator iter = ref.iteratePointers(jxpathContext);
                    while (iter.hasNext()) {
                        Pointer ptr = (Pointer)iter.next();
                        AttributesImpl attrs = new AttributesImpl();
                        attrs.addAttribute(NS, REF, REF, "CDATA",
                                           ptr.asPath());
View Full Code Here


            throws SAXException {
            Event newEvent = null;
            if (NS.equals(namespaceURI)) {
                if (localName.equals(REPEAT)) {
                    String items = attrs.getValue(NODESET);
                    CompiledExpression expr =
                        compileExpr(items, locator);
                    StartRepeat startRepeat =
                        new StartRepeat(locator, namespaceURI,
                                        localName, raw, attrs, expr);
                    newEvent = startRepeat;
                } else if (localName.equals(ITEMSET)) {
                    String items = attrs.getValue(NODESET);
                    CompiledExpression expr =
                        compileExpr(items, locator);
                    StartItemSet startItemSet =
                        new StartItemSet(locator, namespaceURI,
                                         localName, raw, attrs, expr);
                    newEvent = startItemSet;
                } else if (isReadonlyInputControl(localName)) {
                    String refStr = attrs.getValue("ref");
                    CompiledExpression ref =
                        compileExpr(refStr, locator);
                    StartReadonlyInputControl startInputControl =
                        new StartReadonlyInputControl(locator,
                                                      ref,
                                                      new StartElement(locator,
                                                                       namespaceURI, localName, raw, attrs));
                    newEvent = startInputControl;
                } else if (isInputControl(localName)) {
                    String refStr = attrs.getValue("ref");
                    CompiledExpression ref =
                        compileExpr(refStr, locator);
                    StartInputControl startInputControl =
                        new StartInputControl(locator,
                                              ref,
                                              new StartElement(locator, namespaceURI,
                                                               localName, raw, attrs));
                    newEvent = startInputControl;
                } else if (SUBMIT.equals(localName)) {
                    StartSubmit startSubmit =
                        new StartSubmit(locator,
                                        new StartElement(locator, namespaceURI, localName, raw, attrs));
                    newEvent = startSubmit;
                } else if (ITEM.equals(localName)) {
                    StartItem startItem =
                        new StartItem(locator,
                                        new StartElement(locator, namespaceURI, localName, raw, attrs));
                    newEvent = startItem;
                } else if (CHOICES.equals(localName)) {
                    StartChoices startChoices =
                        new StartChoices(locator,
                                        new StartElement(locator, namespaceURI, localName, raw, attrs));
                    newEvent = startChoices;
                } else if (VALUE.equals(localName)) {
                    StartValue startValue =
                        new StartValue(locator,
                                        new StartElement(locator, namespaceURI, localName, raw, attrs));
                    newEvent = startValue;
                } else if (OUTPUT.equals(localName)) {
                    String refStr = attrs.getValue(REF);
                    String valueStr = attrs.getValue(VALUE);
                    if (refStr != null && valueStr != null) {
                        throw new SAXParseException("ref and value are mutually exclusive", locator, null);
                    }
                    CompiledExpression ref = compileExpr(refStr,
                                                         locator);
                    CompiledExpression value = compileExpr(valueStr,
                                                           locator);
                    StartOutput startOutput =
                        new StartOutput(locator,
                                        ref, value,
                                        new StartElement(locator, namespaceURI, localName, raw, attrs));
                    newEvent = startOutput;
                } else if (FORM.equals(localName)) {
                    StartForm startForm =
                        new StartForm(locator,
                                      new StartElement(locator, namespaceURI, localName, raw, attrs));
                    newEvent = startForm;
                } else if (VIOLATIONS.equals(localName)) {
                    StartViolations startViolations =
                        new StartViolations(locator,
                                            (Event)stack.peek(),
                                            new StartElement(locator, namespaceURI, localName, raw, attrs));
                    newEvent = startViolations;
                } else if (GROUP.equals(localName)) {
                    String refStr = attrs.getValue(REF);
                    CompiledExpression ref =
                        compileExpr(refStr, locator);
                    StartGroup startGroup =
                        new StartGroup(locator,
                                       ref,
                                       new StartElement(locator, namespaceURI, localName, raw, attrs));
                    newEvent = startGroup;
                } else if (HIDDEN.equals(localName)) {
                    String refStr = attrs.getValue(REF);
                    CompiledExpression ref =
                        compileExpr(refStr, locator);
                    StartHidden startHidden =
                        new StartHidden(locator,
                                       ref,
                                       new StartElement(locator, namespaceURI, localName, raw, attrs));
View Full Code Here

        compileExpr(String expr, Locator location)
        throws SAXParseException {
        if (expr == null) return null;
        expr = expr.trim();
        try {
            CompiledExpression jxpath = JXPathContext.compile(expr);
            return new XPathExpr(expr, jxpath, expr.startsWith("/"));
        } catch (Exception exc) {
            throw new SAXParseException(exc.getMessage(),
                                        location, exc);
        } catch (Error err) {
View Full Code Here

            for (int j = 0; j < xPathChildren.length; j++) {
                Configuration xPathChild = xPathChildren[j];

                String xPathName = xPathChild.getAttribute("name");
                CompiledExpression xPath = JXPathContext.compile(xPathChild.getAttribute("test"));

                xPathMap.put(xPathName, xPath);
            }
            if (xPathMap.size() > 0) {
                // store xpath - config if there is some
View Full Code Here

        throws Exception {
        if (expr != null) {
            Object compiled = expr.compiledExpression;
            try {
                if (compiled instanceof CompiledExpression) {
                    CompiledExpression e = (CompiledExpression)compiled;
                    boolean oldLenient = jxpathContext.isLenient();
                    if (lenient != null) {
                        jxpathContext.setLenient(lenient.booleanValue());
                    }
                    try {
                        return e.getValue(jxpathContext);
                    } finally {
                        jxpathContext.setLenient(oldLenient);
                    }
                } else if (compiled instanceof org.apache.commons.jexl.Expression) {
                    org.apache.commons.jexl.Expression e =
                        (org.apache.commons.jexl.Expression)compiled;
                    return e.evaluate(jexlContext);
                }
                return compiled;
            } catch (InvocationTargetException e) {
                Throwable t = e.getTargetException();
                if (t instanceof Exception) {
                    throw (Exception)t;
                }
                throw (Error)t;
            }
View Full Code Here

                           JXPathContext jxpathContext, Boolean lenient)
        throws Exception {
        try {
            Object compiled = expr.compiledExpression;
            if (compiled instanceof CompiledExpression) {
                CompiledExpression e = (CompiledExpression)compiled;
                boolean oldLenient = jxpathContext.isLenient();
                if (lenient != null) jxpathContext.setLenient(lenient.booleanValue());
                try {
                    Iterator iter =
                        e.iteratePointers(jxpathContext);
                    if (!iter.hasNext()) {
                        return null;
                    }
                    Pointer first = (Pointer)iter.next();
                    if (!iter.hasNext()) {
                        return first.getNode();
                    }
                    List result = new LinkedList();
                    result.add(first.getNode());
                    boolean dom = (first.getNode() instanceof Node);
                    while (iter.hasNext()) {
                        Object obj = ((Pointer)iter.next()).getNode();
                        dom = dom && (obj instanceof Node);
                        result.add(obj);
                    }
                    Object[] arr;
                    if (dom) {
                        arr = new Node[result.size()];
                    } else {
                        arr = new Object[result.size()];
                    }
                    result.toArray(arr);
                    return arr;
                } finally {
                    jxpathContext.setLenient(oldLenient);
                }
            } else if (compiled instanceof org.apache.commons.jexl.Expression) {
                org.apache.commons.jexl.Expression e =
                    (org.apache.commons.jexl.Expression)compiled;
                return e.evaluate(jexlContext);
            }
            return expr.raw;
        } catch (InvocationTargetException e) {
            Throwable t = e.getTargetException();
            if (t instanceof Exception) {
                throw (Exception)t;
            }
            throw (Error)t;
        }
View Full Code Here

                String var, varStatus;
                try {
                    if (items != null) {
                        Expression expr = (Expression)items;
                        if (expr.compiledExpression instanceof CompiledExpression) {
                            CompiledExpression compiledExpression =
                                (CompiledExpression)expr.compiledExpression;
                            Object val =
                                compiledExpression.getPointer(jxpathContext,
                                                              expr.raw).getNode();
                            // FIXME: workaround for JXPath bug
                            if (val instanceof NativeArray) {
                                iter = new JSIntrospector.NativeArrayIterator((NativeArray)val);
                            } else {
                                iter = compiledExpression.iteratePointers(jxpathContext);
                            }
                        } else if (expr.compiledExpression instanceof org.apache.commons.jexl.Expression) {
                            org.apache.commons.jexl.Expression e =
                                (org.apache.commons.jexl.Expression)expr.compiledExpression;
                            Object result = e.evaluate(jexlContext);
View Full Code Here

            for (int j = 0; j<xPathChildren.length; j++) {
                Configuration xPathChild = xPathChildren[j];

                String xPathName = xPathChild.getAttribute("name");
                CompiledExpression xPath = JXPathContext.compile(xPathChild.getAttribute("test"));

                xPathMap.put(xPath, xPathName);
            }
            if (xPathMap.size()>0) {
                // store xpath - config if there is some
View Full Code Here

        compileExpr(String expr, Locator location)
        throws SAXParseException {
        if (expr == null) return null;
        expr = expr.trim();
        try {
            CompiledExpression jxpath = JXPathContext.compile(expr);
            return new XPathExpr(expr, jxpath, expr.startsWith("/"));
        } catch (Exception exc) {
            throw new SAXParseException(exc.getMessage(),
                                        location, exc);
        } catch (Error err) {
View Full Code Here

                                JXPathContext jxpathContext, Boolean lenient) throws Exception {
        if (expr != null) {
            Object compiled = expr.compiledExpression;
            try {
                if (compiled instanceof CompiledExpression) {
                    CompiledExpression e = (CompiledExpression)compiled;
                    boolean oldLenient = jxpathContext.isLenient();
                    if (lenient != null) {
                        jxpathContext.setLenient(lenient.booleanValue());
                    }
                    try {
                        return e.getValue(jxpathContext);
                    } finally {
                        jxpathContext.setLenient(oldLenient);
                    }
                } else if (compiled instanceof Expression) {
                    Expression e = (Expression)compiled;
                    return e.evaluate(jexlContext);
                }
                return compiled;
            } catch (InvocationTargetException e) {
                Throwable t = e.getTargetException();
                if (t instanceof Exception) {
                    throw (Exception)t;
                }
                throw (Error)t;
            }
View Full Code Here

TOP

Related Classes of org.apache.commons.jxpath.CompiledExpression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.