Package org.apache.commons.jxpath

Examples of org.apache.commons.jxpath.Pointer


                                                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,
                            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) {
                    Object value;
                    try {
                        value = ref.getNode(rootContext, currentContext);
                    } catch (Exception exc) {
                        throw new SAXParseException(exc.getMessage(),
                                                    ev.location,
                                                    exc);
                    }
                    JXPathContext localJXPathContext =
                        jxpathContextFactory.newContext(null, value);
                    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()) {
                    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(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


        Object getNode(JXPathContext root, JXPathContext current) {
            JXPathContext ctx = current;
            if (absolute) {
                ctx = root;
            }
            Pointer ptr = jxpath.getPointer(ctx, string);
            if (ptr == null) {
                return null;
            }
            return ptr.getNode();
        }
View Full Code Here

                boolean oldLenient = jxpathContext.isLenient();
                if (lenient != null) jxpathContext.setLenient(lenient.booleanValue());
                try {
                    Iterator iter = e.iteratePointers(jxpathContext);
                    if (iter.hasNext()) {
                        Pointer first = (Pointer)iter.next();
                        if (iter.hasNext()) {
                            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;
                        }
                        return first.getNode();                   
                    }
                    return null;
                } finally {
                    jxpathContext.setLenient(oldLenient);
                }
View Full Code Here

                int skipCounter, count = 1;
                JXPathContext localJXPathContext = null;
                while (i <= end && iter.hasNext()) {
                    Object value = iter.next();
                    if (value instanceof Pointer) {
                        Pointer ptr = (Pointer)value;
                        localJXPathContext = jxpathContext.getRelativeContext(ptr);
                        try {
                            value = ptr.getNode();
                        } catch (Exception exc) {
                            throw new SAXParseException(exc.getMessage(), ev.location, null);
                        }
                    } else {
                        localJXPathContext = jxpathContextFactory.newContext(jxpathContext, value);
View Full Code Here

    /**
     * Actively performs the binding from the ObjectModel wrapped in a jxpath
     * context to the Woody-form.
     */
    public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException {
        Pointer ptr = jxpc.getPointer(this.xpath);
        if (ptr.getNode() != null) {
            JXPathContext subContext = jxpc.getRelativeContext(ptr);
            super.doLoad(frmModel, subContext);
            if (getLogger().isDebugEnabled())
                getLogger().debug("done loading " + toString());
        } else {
View Full Code Here

    /**
     * Actively performs the binding from the Woody-form to the ObjectModel
     * wrapped in a jxpath context.
     */
    public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
        Pointer ptr = jxpc.getPointer(this.xpath);
        if (ptr.getNode() == null) {
            jxpc.createPath(this.xpath);
            // Need to recreate the pointer after creating the path
            ptr = jxpc.getPointer(this.xpath);
        }
        JXPathContext subContext = jxpc.getRelativeContext(ptr);
View Full Code Here

        }

        Widget widget = frmModel.getWidget(this.id);

        // Move to widget context
        Pointer pointer = jctx.getPointer(this.path);

        // FIXME: remove this ugly hack and get the request from the Avalon context once
        // binding builder are real components
        Request request = ObjectModelHelper.getRequest(CocoonComponentManager.getCurrentEnvironment().getObjectModel());

        try {
            Map values = new HashMap(3);
            values.put("widget", widget);
            values.put("jxpathPointer", pointer);
            if (pointer.getNode() != null) {
                values.put("jxpathContext", jctx.getRelativeContext(pointer));
            }

            JavaScriptHelper.execScript(this.loadScript, values, request);
View Full Code Here

        }

        Widget widget = frmModel.getWidget(this.id);

        // Move to widget context and create the path if needed
        Pointer pointer = jctx.createPath(this.path);
        JXPathContext widgetCtx = jctx.getRelativeContext(pointer);
        try {
            // FIXME: remove this ugly hack and get the request from the Avalon context once
            // binding builder are real components
            Request request = ObjectModelHelper.getRequest(CocoonComponentManager.getCurrentEnvironment().getObjectModel());
View Full Code Here

        if (this.clearOnLoad) {
            repeater.removeRows();
        }

        // Move to repeater context
        Pointer ptr = jctx.getPointer(this.repeaterPath);
        if (ptr.getNode() != null) {
            // There are some nodes to load from

            JXPathContext repeaterContext = jctx.getRelativeContext(ptr);
            // build a jxpath iterator for pointers
            Iterator rowPointers = repeaterContext.iteratePointers(this.rowPath);

            //iterate through it
            int rowNum = 0;
            while (rowPointers.hasNext()) {
                // Get a row. It is created if needed (depends on clearOnLoad)
                Repeater.RepeaterRow thisRow;
                if (repeater.getSize() > rowNum) {
                    thisRow = repeater.getRow(rowNum);
                } else {
                    thisRow = repeater.addRow();
                }
                rowNum++;

                // make a jxpath sub context on the iterated element
                Pointer jxp = (Pointer) rowPointers.next();
                JXPathContext rowContext = repeaterContext.getRelativeContext(jxp);

                this.rowBinding.loadFormFromModel(thisRow, rowContext);
            }
        }
View Full Code Here

            // Delete all that is already present
            repeaterContext.removeAll(this.rowPath);

            for (int i = 0; i < repeater.getSize(); i++) {
                String path = this.rowPath + '[' + (i+1) + ']';
                Pointer rowPtr = repeaterContext.createPath(path);
                JXPathContext rowContext = repeaterContext.getRelativeContext(rowPtr);
                this.rowBinding.saveFormToModel(repeater.getRow(i), rowContext);
            }
        }
    }
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.