Package org.apache.commons.jxpath

Examples of org.apache.commons.jxpath.Pointer


        public List getNodes() {
            if (nodes == null) {
                List pointers = getPointers();
                nodes = new ArrayList();
                for (int i = 0; i < pointers.size(); i++) {
                    Pointer pointer = (Pointer) pointers.get(i);
                    nodes.add(pointer.getValue());
                }
                nodes = Collections.unmodifiableList(nodes);
            }
            return nodes;
        }
View Full Code Here


        public List getValues() {
            if (values == null) {
                List pointers = getPointers();
                values = new ArrayList();
                for (int i = 0; i < pointers.size(); i++) {
                    Pointer pointer = (Pointer) pointers.get(i);
                    values.add(pointer.getValue());
                }
                values = Collections.unmodifiableList(values);
            }
            return values;
        }
View Full Code Here

        List failedRules = new ArrayList();

        Iterator pointerIter = jxpContext.iteratePointers(rule.getContext());

        while (pointerIter.hasNext()) {
            Pointer ptr = (Pointer) pointerIter.next();

            // prepare result Rule
            Rule nextFailedRule = new Rule();

            nextFailedRule.setContext(ptr.asPath());

            // switch to the context of the rule
            JXPathContext localJxpContext = JXPathContext.newContext(jxpContext,
                                                ptr.getValue());

            // evaluate asserts
            Iterator assertIter = rule.getAssert().iterator();

            while (assertIter.hasNext()) {
View Full Code Here

        // // This is supposed to do the right thing
        // jxcontext_.setValue(xpath, values);
        // }
        //

        Pointer pointer = jxcontext_.getPointer(xpath);
        Object property = pointer.getNode();

        // if there are multiple values to set
        // (like in the selectMany case),
        // iterate over the array and set individual values

        // when the instance property is array
        if ((property!=null) && property.getClass().isArray()) {
            Class componentType = property.getClass().getComponentType();

            property = java.lang.reflect.Array.newInstance(componentType,
                values.length);
            java.lang.System.arraycopy(values, 0, property, 0, values.length);
            pointer.setValue(property);
        } else if (property instanceof Collection) {
            Collection cl = (Collection) property;

            cl.clear();
            cl.addAll(java.util.Arrays.asList(values));
View Full Code Here

        }
        List nodeset = new LinkedList();
        Iterator iter = jxcontext_.iteratePointers(xpathSelector);

        while (iter.hasNext()) {
            Pointer nextPointer = (Pointer) iter.next();
            String path = nextPointer.asPath();

            nodeset.add(path);
        }
        return nodeset;
    }
View Full Code Here

        // // This is supposed to do the right thing
        // jxcontext_.setValue(xpath, values);
        // }
        //

        Pointer pointer = jxcontext_.getPointer(xpath);
        Object property = pointer.getNode();

        // if there are multiple values to set
        // (like in the selectMany case),
        // iterate over the array and set individual values

        // when the instance property is array
        if ((property!=null) && property.getClass().isArray()) {
            Class componentType = property.getClass().getComponentType();

            property = java.lang.reflect.Array.newInstance(componentType,
                values.length);
            java.lang.System.arraycopy(values, 0, property, 0, values.length);
            pointer.setValue(property);
        } else if (property instanceof Collection) {
            Collection cl = (Collection) property;

            cl.clear();
            cl.addAll(java.util.Arrays.asList(values));
View Full Code Here

        }
        List nodeset = new LinkedList();
        Iterator iter = jxcontext_.iteratePointers(xpathSelector);

        while (iter.hasNext()) {
            Pointer nextPointer = (Pointer) iter.next();
            String path = nextPointer.asPath();

            nodeset.add(path);
        }
        return nodeset;
    }
View Full Code Here

        List failedRules = new ArrayList();

        Iterator pointerIter = jxpContext.iteratePointers(rule.getContext());

        while (pointerIter.hasNext()) {
            Pointer ptr = (Pointer) pointerIter.next();

            // prepare result Rule
            Rule nextFailedRule = new Rule();

            nextFailedRule.setContext(ptr.asPath());

            // switch to the context of the rule
            JXPathContext localJxpContext = JXPathContext.newContext(jxpContext,
                                                ptr.getValue());

            // evaluate asserts
            Iterator assertIter = rule.getAssert().iterator();

            while (assertIter.hasNext()) {
View Full Code Here

                                                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());
                        consumer.startElement(NS, VALUE, VALUE, EMPTY_ATTRS);
                        Object val = ptr.getNode();
                        String str = String.valueOf(val);
                        consumer.characters(str.toCharArray(), 0, str.length());
                        consumer.endElement(NS, VALUE, VALUE);

                    }
View Full Code Here

                    throw new SAXParseException(err.getMessage(),
                                                ev.location,
                                                null);
                }
                while (iter.hasNext()) {
                    Pointer ptr = (Pointer)iter.next();
                    JXPathContext localJXPathContext =
                        currentContext.getRelativeContext(ptr);
                    String path = "";
                    if (contextPath != null) {
                        path = contextPath + "/.";
                    }
                    path += ptr.asPath();
                    execute(consumer,
                            form,
                            currentView,
                            path,
                            rootContext,
                            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 XPathExpr ref = startGroup.ref;
                if (ref != null) {
                    Pointer ptr;
                    try {
                        ptr = ref.getPointer(rootContext, currentContext);
                    } catch (Exception exc) {
                        throw new SAXParseException(exc.getMessage(),
                                                    ev.location,
                                                    exc);
                    }
                    JXPathContext localJXPathContext =
                        currentContext.getRelativeContext(ptr);
                    String path;
                    if (ref.absolute) {
                        path = ref.string;
                    } else {
                        path = contextPath;
                        if (path != null) {
                            path += "/.";
                        } else {
                            path = "";
                        }
                        path += ref.string;
                    }
                    execute(consumer,
                            form,
                            currentView,
                            path,
                            rootContext,
                            localJXPathContext,
                            startGroup.next,
                            startGroup.endGroup);
                    ev = startGroup.endGroup;
                    continue;
                }
            } else if (ev instanceof StartItemSet) {
                StartItemSet startItemSet = (StartItemSet)ev;
                final XPathExpr nodeset = startItemSet.nodeset;
                Iterator iter = null;
                try {
                    if (nodeset == null) {
                        iter = EMPTY_ITER;
                    } else {
                        iter =
                            nodeset.iteratePointers(rootContext,
                                                    currentContext);
                    }
                } 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()) {
                    Pointer ptr = (Pointer)iter.next();
                    JXPathContext localJXPathContext =
                        currentContext.getRelativeContext(ptr);
                    AttributesImpl attrs = new AttributesImpl();
                    attrs.addAttribute(null, 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,
                            path,
                            rootContext,
View Full Code Here

TOP

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

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.