Package org.apache.commons.jxpath

Examples of org.apache.commons.jxpath.Pointer


            } else {
                thisRow = repeater.addRow();
            }

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

            // hand it over to children
            this.uniqueFieldBinding.loadFormFromModel(thisRow, rowContext);
            this.rowBinding.loadFormFromModel(thisRow, rowContext);
View Full Code Here


                //if rowIdValue != null --> iterate nodes to find match
                Iterator rowPointers =
                    repeaterContext.iteratePointers(this.rowPath);
                boolean found = false;
                while (rowPointers.hasNext()) {
                    Pointer jxp = (Pointer) rowPointers.next();
                    JXPathContext rowContext =
                        repeaterContext.getRelativeContext(jxp);

                    Object matchId = rowContext.getValue(this.uniqueRowIdPath);
                    if (matchId != null && this.uniqueRowIdConvertor != null) {
                        if (matchId instanceof String) {
                            matchId = this.uniqueRowIdConvertor.convertFromString((String)matchId, this.uniqueRowIdConvertorLocale, null);
                        } else {
                            getLogger().warn("Convertor ignored on backend-value which isn't of type String.");
                        }
                    }

                    if (rowIdValue.equals(matchId)) {
                        // match! --> bind to children
                        this.rowBinding.saveFormToModel(thisRow, rowContext);
                        //        --> store rowIdValue in list of updatedRowIds
                        updatedRowIds.add(rowIdValue);
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    // this is a new row
                    rowsToInsert.add(thisRow);
                    // also add it to the updated row id's so that this row doesn't get deleted
                    updatedRowIds.add(rowIdValue);
                }
            } else {
                //if rowId == null --> remember to insert this one later
                rowsToInsert.add(thisRow);
            }
        }

        //again iterate nodes for deletion
        Iterator rowPointers = repeaterContext.iteratePointers(this.rowPath);
        List rowsToDelete = new ArrayList();
        while (rowPointers.hasNext()) {
            Pointer jxp = (Pointer) rowPointers.next();
            JXPathContext rowContext = repeaterContext.getRelativeContext((Pointer)jxp.clone());

            Object matchId = rowContext.getValue(this.uniqueRowIdPath);
            if (matchId != null && this.uniqueRowIdConvertor != null) {
                if (matchId instanceof String) {
                    matchId = this.uniqueRowIdConvertor.convertFromString((String)matchId, this.uniqueRowIdConvertorLocale, null);
                } else {
                    getLogger().warn("Convertor ignored on backend-value which isn't of type String.");
                }
            }

            // check if matchPath was in list of updates, if not --> bind for delete
            if (!updatedRowIds.contains(matchId)) {
                rowsToDelete.add(rowContext);
            }
        }

        if (rowsToDelete.size() > 0) {
            if (this.deleteRowBinding == null) {
                getLogger().warn("RepeaterBinding has detected rows to delete, " +
                    "but misses the <on-delete-row> binding to do it.");
            }
            else {
                // run backwards through the list, so that we don't get into trouble by shifting indexes
                for (int i = rowsToDelete.size() - 1; i >= 0; i--)
                    this.deleteRowBinding.saveFormToModel(frmModel, rowsToDelete.get(i));
            }
        }

        // count how many we have now
        int indexCount = 1;
        rowPointers = repeaterContext.iteratePointers(this.rowPathForInsert);
        while (rowPointers.hasNext()) {
            rowPointers.next();
            indexCount++;
        }

        // end with rows to insert (to make sure they don't get deleted!)
        if(rowsToInsert.size() > 0) {
            if (this.insertRowBinding != null) {
                Iterator rowIterator = rowsToInsert.iterator();
                //register the factory!
                //this.insertRowBinding.saveFormToModel(repeater, repeaterContext);
                while (rowIterator.hasNext()) {
                    Repeater.RepeaterRow thisRow = (Repeater.RepeaterRow) rowIterator.next();
                    // Perform the insert row binding.
                    this.insertRowBinding.saveFormToModel(repeater, repeaterContext);
                    // -->  create the path to let the context be created
                    Pointer newRowContextPointer = repeaterContext.createPath(this.rowPathForInsert + "[" + indexCount + "]");
                    JXPathContext newRowContext = repeaterContext.getRelativeContext(newRowContextPointer);
                    if (getLogger().isDebugEnabled())
                        getLogger().debug("inserted row at " + newRowContextPointer.asPath());
                    //    + rebind to children for update
                    this.rowBinding.saveFormToModel(thisRow, newRowContext);
                    getLogger().debug("bound new row");
                    indexCount++;
                }
View Full Code Here

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

        // Find the location of the repeater data.
        Pointer repeaterPointer = jctx.getPointer(this.repeaterPath);

        // Check if there is data present.
        //
        // (Otherwise, should we check the leniency config option
        // to decide whether to be silent or throw an exception?)
        if (repeaterPointer != null) {

            // Narrow to repeater context.
            JXPathContext repeaterContext = jctx.getRelativeContext(repeaterPointer);

            // Build a jxpath iterator for the repeater row pointers.
            Iterator rowPointers = repeaterContext.iteratePointers(this.rowPath);

            // Iterate through the rows of data.
            int rowNum = 0;
            while (rowPointers.hasNext()) {

                // Get or create a row widget.
                Repeater.RepeaterRow thisRow;
                if (repeater.getSize() > rowNum) {
                    thisRow = repeater.getRow(rowNum);
                } else {
                    thisRow = repeater.addRow();
                }
                rowNum++;

                // Narrow to the row context.
                Pointer rowPointer = (Pointer) rowPointers.next();
                JXPathContext rowContext = repeaterContext.getRelativeContext(rowPointer);

                // If virtual rows are requested, place a deep clone of the row data
                // into a temporary node, and narrow the context to this virtual row.
                //
                // (A clone of the data is used to prevent modifying the source document.
                // Otherwise, the appendChild method would remove the data from the source
                // document.  Is this protection worth the penalty of a deep clone?)
                //
                // (This implementation of virtual rows currently only supports DOM
                // bindings, but could easily be extended to support other bindings.)

                if (virtualRows == true) {
                    Node repeaterNode = (Node)repeaterPointer.getNode();
                    Node virtualNode = repeaterNode.getOwnerDocument().createElementNS(null, "virtual");
                    Node clone = ((Node)rowPointer.getNode()).cloneNode(true);
                    virtualNode.appendChild(clone);
                    rowContext = JXPathContext.newContext(repeaterContext, virtualNode);
                }

                // Finally, perform the load row binding.
View Full Code Here

                    // Iterate through the repeater rows.
                    for (int i = 0; i < repeater.getSize(); i++) {

                        // Narrow to the repeater row context.
                        Pointer rowPointer = repeaterContext.getPointer(this.rowPathInsert);
                        JXPathContext rowContext = repeaterContext.getRelativeContext(rowPointer);

                        // Variables used for virtual rows.
                        // They are initialized here just to keep the compiler happy.
                        Node rowNode = null;
View Full Code Here

        while(iter.hasNext()) {
            String stringValue = "";
            Object label = null;

            // Get a context on the current item
            Pointer ptr = (Pointer)iter.next();
            if (ptr.getValue() != null) {
                JXPathContext itemCtx = ctx.getRelativeContext(ptr);

                // Get the value as a string
                Object value = itemCtx.getValue(this.valuePath);
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 {
View Full Code Here

        if (i >= jxCollection.getOriginalCollectionSize()) {
            return null;
        }
        if (this.sortedItems == null) {
            JXPathContext storageContext = this.jxCollection.getStorageContext();
            Pointer pointer = storageContext.getPointer(binding.getRowPath() + "[" + (i + 1) + "]");
            JXPathContext rowContext = storageContext.getRelativeContext(pointer);
            RepeaterItem item = new RepeaterItem(new Integer(i + 1));
            item.setContext(rowContext);
            return item;
        } else {
View Full Code Here

   
    Iterator pointerIter = elements.iterator ();
    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

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

        // Find the location of the repeater data.
        Pointer repeaterPointer = jctx.getPointer(this.repeaterPath);

        // Check if there is data present.
        //
        // (Otherwise, should we check the leniency config option
        // to decide whether to be silent or throw an exception?)
        if (repeaterPointer != null) {

            // Narrow to repeater context.
            JXPathContext repeaterContext = jctx.getRelativeContext(repeaterPointer);

            // Build a jxpath iterator for the repeater row pointers.
            Iterator rowPointers = repeaterContext.iteratePointers(this.rowPath);

            // Iterate through the rows of data.
            int rowNum = 0;
            while (rowPointers.hasNext()) {

                // Get or create a row widget.
                Repeater.RepeaterRow thisRow;
                if (repeater.getSize() > rowNum) {
                    thisRow = repeater.getRow(rowNum);
                } else {
                    thisRow = repeater.addRow();
                }
                rowNum++;

                // Narrow to the row context.
                Pointer rowPointer = (Pointer) rowPointers.next();
                JXPathContext rowContext = repeaterContext.getRelativeContext(rowPointer);

                // If virtual rows are requested, place a deep clone of the row data
                // into a temporary node, and narrow the context to this virtual row.
                //
                // (A clone of the data is used to prevent modifying the source document.
                // Otherwise, the appendChild method would remove the data from the source
                // document.  Is this protection worth the penalty of a deep clone?)
                //
                // (This implementation of virtual rows currently only supports DOM
                // bindings, but could easily be extended to support other bindings.)

                if (virtualRows) {
                    Node repeaterNode = (Node)repeaterPointer.getNode();
                    Node virtualNode = repeaterNode.getOwnerDocument().createElementNS(null, "virtual");
                    Node node = (Node)rowPointer.getNode();
                    Node clone = node.cloneNode(true);
                    Node fakeDocElement = node.getOwnerDocument().getDocumentElement().cloneNode(false);
                    virtualNode.appendChild(clone);
                    fakeDocElement.appendChild(virtualNode);
                    rowContext = JXPathContext.newContext(repeaterContext, fakeDocElement);
View Full Code Here

                    // Iterate through the repeater rows.
                    for (int i = 0; i < repeater.getSize(); i++) {

                        // Narrow to the repeater row context.
                        Pointer rowPointer = repeaterContext.getPointer(this.rowPathInsert);
                        JXPathContext rowContext = repeaterContext.getRelativeContext(rowPointer);

                        // Variables used for virtual rows.
                        // They are initialized here just to keep the compiler happy.
                        Node rowNode = null;
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.