Package org.exist.dom

Examples of org.exist.dom.NodeProxy


     * @throws XPathException
     */
    public static NodeSet fmapNodes(final NodeSet nodes, final F<NodeProxy, NodeProxy> f) throws XPathException {
        NodeSet result = new ExtArrayNodeSet();
        for (NodeSetIterator iterator = nodes.iterator(); iterator.hasNext();) {
            NodeProxy node = f.f(iterator.next());
            if (node != null)
                result.add(node);
        }
        result.iterate(); // ensure result is ready to use
        return result;
View Full Code Here


                        NodeId nodeId = nodes[i].nodeId;
                        for (int j = i; j < nodes.length; j++) {
                            if (nodes[j].nodeType == XMLStreamReader.END_ELEMENT &&
                                    nodes[j].nodeId.equals(nodeId)) {
                                isClosed = true;
                                NodeProxy proxy = new NodeProxy(otherDoc, nodes[i].nodeId);
                                Serializer serializer = broker.getSerializer();
                                serializer.reset();
                                serializer.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");
                                serializer.setReceiver(handler);
                                serializer.toReceiver(proxy, false);
                                i = j;
                                break;
                            }
                        }
                        if (!isClosed) {
                            attribs = new AttrList();
                            if (nodes[i].qname.needsNamespaceDecl())
                                attribs.addAttribute(ATTR_NAMESPACE, nodes[i].qname.getNamespaceURI());
                            attribs.addAttribute(ATTR_NAME, nodes[i].qname.getStringValue());
                            handler.startElement(ELEMENT_START, attribs);
                            handler.endElement(ELEMENT_START);
                        }
                        break;
                    case XMLStreamReader.END_ELEMENT:
                        attribs = new AttrList();
                        if (nodes[i].qname.needsNamespaceDecl())
                            attribs.addAttribute(ATTR_NAMESPACE, nodes[i].qname.getNamespaceURI());
                        attribs.addAttribute(ATTR_NAME, nodes[i].qname.getStringValue());
                        handler.startElement(ELEMENT_END, attribs);
                        handler.endElement(ELEMENT_END);
                        break;
                    case XMLStreamReader.COMMENT:
                        attribs = new AttrList();
                        handler.startElement(ELEMENT_COMMENT, attribs);
                        handler.characters(nodes[i].value);
                        handler.endElement(ELEMENT_COMMENT);
                        break;
                    default:
                        NodeProxy proxy = new NodeProxy(otherDoc, nodes[i].nodeId);
                        Serializer serializer = broker.getSerializer();
                        serializer.reset();
                        serializer.setProperty(Serializer.GENERATE_DOC_EVENTS, "false");
                        serializer.setReceiver(handler);
                        serializer.toReceiver(proxy, false);
View Full Code Here

        NodeSet result = NodeSets.fmapNodes(headNodes, new F<NodeProxy, NodeProxy>() {

            @Override
            public NodeProxy f(NodeProxy headNode) {
                NodeProxy tailNode = tailNodes.get(headNode);
                if (tailNode != null) {
                    return getMatchingNode(headNode, tailNode, expressionId);
                } else {
                    return null;
                }
View Full Code Here

        return result;
    }

    private NodeProxy getMatchingNode(NodeProxy headNode, NodeProxy tailNode, final int expressionId) {
        NodeProxy result = null;

        Match match = null;
        boolean found = false;

        for (Match headMatch = headNode.getMatches(); headMatch != null && !found; headMatch = headMatch
View Full Code Here

    public void nodes() {
        DBBroker broker = null;
        try {
            broker = pool.get(pool.getSecurityManager().getSystemSubject());
            DocumentImpl doc = (DocumentImpl) broker.getXMLResource(TEST_COLLECTION_URI.append("test.xml"));
            NodeProxy p = new NodeProxy(doc, pool.getNodeFactory().createFromString("1.1"));

            StringWriter writer = new StringWriter();
            SAXSerializer serializer = new SAXSerializer(writer, new Properties());
            Marshaller.marshall(broker, p, serializer);
            String serialized = writer.toString();
View Full Code Here

    LocalCollection collection = null;
    Subject user = null;
   
    LocalXMLResource res = null;
    if (r instanceof NodeProxy) {
      NodeProxy p = (NodeProxy) r;
      res = new LocalXMLResource(user, db, collection, p);
    } else if (r instanceof Node) {
      res = new LocalXMLResource(user, db, collection, XmldbURI.EMPTY_URI);
      res.setContentAsDOM((Node)r);
    } else if (r instanceof AtomicValue) {
View Full Code Here

                        last = start + next.inserted;
                    }
                }
                Difference.Insert diff;
                if (nodesA[start0].nodeType == XMLStreamReader.END_ELEMENT) {
                    diff = new Difference.Append(new NodeProxy(docA, nodesA[start0].nodeId), docB);
                    changes.add(diff);
                } else {
                    diff = (Difference.Insert) inserts.get(nodesA[start0].nodeId);
                    if (diff == null) {
                        diff = new Difference.Insert(new NodeProxy(docA, nodesA[start0].nodeId), docB);
                        inserts.put(nodesA[start0].nodeId, diff);
                    }
                }
               
                // now scan the chunk and collect the nodes
                DiffNode[] nodes = new DiffNode[last - start];
                int j = 0;
                for (int i = start; i < last; i++, j++) {
                    if (LOG.isTraceEnabled())
                        LOG.trace(Integer.toString(i) + " " + nodesB[i]);
                    nodes[j] = nodesB[i];
                }
                diff.addNodes(nodes);
            }
            if (next.deleted > 0) {
              // This is a simple test to correct an issue when two nodes of the same
              // node-name are siblings and the first is deleted. What happens is the first
              // element doesn't get it's start node deleted and the second does. So
              // the second element basically ends up with the first one's start element.
              // Which causes problems for the second element's attributes.
              DiffNode beforeElement = nodesA[start0 - 1];
              DiffNode lastElement = nodesA[lastDeleted - 1];

              if(beforeElement.qname != null
                  && lastElement.qname != null
                  && beforeElement.qname.equals(lastElement.qname)
                  && beforeElement.nodeType == XMLStreamReader.START_ELEMENT
                  && lastElement.nodeType == XMLStreamReader.START_ELEMENT) {
                start0--;
                lastDeleted--;
              }
             
              if (LOG.isTraceEnabled())
                    LOG.trace("Deleted: " + start0 + " last: " + lastDeleted);
                for (int i = start0; i < lastDeleted; i++) {
                    boolean elementDeleted = false;
                    if (nodesA[i].nodeType == XMLStreamReader.START_ELEMENT) {
                        for (int j = i; j < lastDeleted; j++) {
                            if (nodesA[j].nodeType == XMLStreamReader.END_ELEMENT &&
                                    nodesA[j].nodeId.equals(nodesA[i].nodeId)) {
                                Difference.Delete diff = new Difference.Delete(new NodeProxy(docA, nodesA[i].nodeId));
                                changes.add(diff);
                                i = j;
                                elementDeleted = true;
                                break;
                            }
                        }
                    }
                    if (!elementDeleted) {
                        Difference.Delete diff = new Difference.Delete(nodesA[i].nodeType, new NodeProxy(docA, nodesA[i].nodeId));
                        changes.add(diff);
                    }
                }
            }
            next = next.link;
View Full Code Here

        }
        return changes;
    }

    protected DiffNode[] getNodes(DBBroker broker, DocumentImpl root) throws XMLStreamException, IOException {
        EmbeddedXMLStreamReader reader = broker.newXMLStreamReader(new NodeProxy(root, NodeId.DOCUMENT_NODE, root.getFirstChildAddress()), false);
        List<DiffNode> nodes = new ArrayList<DiffNode>();
        DiffNode node;
        while (reader.hasNext()) {
            int status = reader.next();
            NodeId nodeId = (NodeId) reader.getProperty(EmbeddedXMLStreamReader.PROPERTY_NODE_ID);
View Full Code Here

            if (getArgumentCount() == 2) {
                NodeValue nv = (NodeValue) args[1].itemAt(0);
                if (nv.getImplementationType() == NodeValue.IN_MEMORY_NODE)
                    throw new XPathException(this, "Second argument to remove should be a persistent node, not " +
                        "an in-memory node.");
                NodeProxy proxy = (NodeProxy) nv;
                index.remove(id, proxy.getDocument());
            } else {
                index.remove(id);
            }
        } catch (EXistException e) {
            throw new XPathException(this, e.getMessage(), e);
View Full Code Here

     
        NodeValue nodeValue = (NodeValue) args[0].itemAt(0);
        if (nodeValue.getImplementationType() != NodeValue.PERSISTENT_NODE) {
            return Sequence.EMPTY_SEQUENCE;
        }
        NodeProxy proxy = (NodeProxy) nodeValue;
        Match match = proxy.getMatches();
        float score = 0.0f;
        while (match != null) {
            if (match.getIndexId() == LuceneIndex.ID) {
                float currentScore = ((LuceneIndexWorker.LuceneMatch)match).getScore();
                score += currentScore;
View Full Code Here

TOP

Related Classes of org.exist.dom.NodeProxy

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.