Package org.exist.dom

Examples of org.exist.dom.NodeProxy$SingleNodeIterator


            String term;
            while(nextMatch != null) {
                final NodeId nodeId= nextMatch.getNodeId();
                //If current node id has not been previously processed
                if (!matchNodeIDs.contains(nodeId)) {
                    final NodeProxy mcurrent = new NodeProxy(current.getDocument(), nodeId);
                    Match match = null;
                    int firstOffset = -1;
                    matchNodeIDs.add(nodeId);
                    final String value = mcurrent.getNodeValue();
                    tok.setText(value);
                    int j = 0;
                    if (j < terms.length)
                        {term = terms[j];}
                    else
View Full Code Here


            while (nextMatch != null) {
                final Hashtable<String, Match> matchTable = new Hashtable<String, Match>();
                final NodeId nodeId = nextMatch.getNodeId();
                //If current node id has not been previously processed
                if (!matchGid.contains(nodeId)) {
                    final NodeProxy mcurrent = new NodeProxy(current.getDocument(), nodeId);
                    //Add it in node id array
                    matchGid.add(nodeId);
                    final String value = mcurrent.getNodeValue();
                    tok.setText(value);
                    int j = 0;
                    if (j < patterns.length) {
                        matcher = matchers[j];
                    } else
View Full Code Here

        try {
       
            if(Type.subTypeOf(args[0].getItemType(), Type.NODE)) {
                final NodeValue node = (NodeValue) args[0].itemAt(0);
                if (node.getImplementationType() == NodeValue.PERSISTENT_NODE) {
                    final NodeProxy proxy = (NodeProxy) node;
                    doc = proxy.getDocument();
                    doc.getUpdateLock().acquire(Lock.READ_LOCK);
                }
            } else if(Type.subTypeOf(args[0].getItemType(), Type.STRING)) {
                final String path = args[0].getStringValue();
                doc = context.getBroker().getXMLResource(XmldbURI.xmldbUriFor(path), Lock.READ_LOCK);
            }

            final QName fnName = getSignature().getName();
            if(doc != null) {
                if(fnName.equals(QN_DOCUMENT_NAME)) {
                   result = new StringValue(doc.getFileURI().toString());
                } else if(fnName.equals(QN_DOCUMENT_ID)) {
                    result = new IntegerValue(doc.getDocId(), Type.INT);
                } else if(fnName.equals(QN_ABSOLUTE_RESOURCE_ID)) {
                   
                    BigInteger absoluteId = BigInteger.valueOf(doc.getCollection().getId());
                    absoluteId = absoluteId.shiftLeft(32);
                    absoluteId = absoluteId.or(BigInteger.valueOf(doc.getDocId()));
                    absoluteId = absoluteId.shiftLeft(1);
                    absoluteId = absoluteId.or(BigInteger.valueOf(doc.getResourceType() & 1));
                    result = new IntegerValue(absoluteId, Type.INTEGER);
                   
                }
            } else {
                if(fnName.equals(QN_GET_RESOURCE_BY_ABSOLUTE_ID)) {
                   
                    final IntegerValue absoluteIdParam = (IntegerValue)args[0].itemAt(0);
                    BigInteger absoluteId = (BigInteger)absoluteIdParam.toJavaObject(BigInteger.class);
                   
                    final byte resourceType = absoluteId.testBit(0) ? DocumentImpl.BINARY_FILE : DocumentImpl.XML_FILE;
                    absoluteId = absoluteId.shiftRight(1);
                    final int documentId = absoluteId.and(BigInteger.valueOf(0xFFFFFFFF)).intValue();
                    absoluteId = absoluteId.shiftRight(32);
                    final int collectionId = absoluteId.and(BigInteger.valueOf(0xFFFFFFFF)).intValue();
                   
                    doc = context.getBroker().getResourceById(collectionId, resourceType, documentId);
                    if(doc instanceof BinaryDocument) {
                        final BinaryDocument bin = (BinaryDocument) doc;
                        final InputStream is = context.getBroker().getBinaryResource(bin);
                        final Base64BinaryDocument b64doc = Base64BinaryDocument.getInstance(context, is);
                        return b64doc;
                    } else {
                        return new NodeProxy(doc);
                    }                   
                }
            }
        } catch (final LockException le) {
            throw new XPathException(this, "Unable to lock resource", le);
View Full Code Here

    private final Sequence processText(MemTreeBuilder builder, Sequence nodes, int width,
            FunctionReference callback, FunctionReference resultCallback, Sequence extraArgs) throws XPathException {
        final StringBuilder str = new StringBuilder();
        NodeValue node;
        List<Match.Offset> offsets = null;
        NodeProxy firstProxy = null;
       
        // First step: scan the passed node sequence and collect the string values of all nodes.
        // Translate the relative offsets into absolute offsets.
        for (final SequenceIterator i = nodes.iterate(); i.hasNext(); ) {
            node = (NodeValue) i.nextItem();
            if (node.getImplementationType() == NodeValue.IN_MEMORY_NODE)
                {throw new XPathException(this, "Function kwic-display" +
                        " can not be invoked on constructed nodes");}
            NodeProxy proxy = (NodeProxy) node;
            // remember the first node, we need it later
            if (firstProxy == null)
                {firstProxy = proxy;}
            final TextImpl text = (TextImpl) proxy.getNode();
           
            Match next = proxy.getMatches();
            while (next != null) {
                if (next.getNodeId().equals(text.getNodeId())) {
                    if (offsets == null)
                        {offsets = new ArrayList<Match.Offset>();}
                    final int freq = next.getFrequency();
View Full Code Here

      if(result == null) {
    result = new ExtArrayNodeSet(docs.getDocumentCount(), 1);
                DocumentImpl doc;
    for (final Iterator<DocumentImpl> i = docs.getDocumentIterator(); i.hasNext();) {
                    doc = i.next();
        result.add(new NodeProxy(doc)); //, -1, Node.DOCUMENT_NODE));
                    if(lockOnLoad) {
                        context.addLockedDocument(doc);
                    }
    }
      }
View Full Code Here

      for (final SequenceIterator i = inSeq.iterate(); i.hasNext(); ) {
        Item item = i.nextItem();
        if (item.getType() == Type.DOCUMENT) {
          if (((NodeValue)item).getImplementationType() == NodeValue.PERSISTENT_NODE) {
            final StoredNode root = (StoredNode) ((NodeProxy)item).getDocument().getDocumentElement();
            item = new NodeProxy(root.getDocument(), root.getNodeId(), root.getInternalAddress());
          } else {
            item = (Item)((NodeValue) item).getOwnerDocument().getDocumentElement();
          }
        }
        if (Type.subTypeOf(item.getType(), Type.NODE)) {
          if (((NodeValue)item).getImplementationType() == NodeValue.PERSISTENT_NODE) {
            final int last = builder.getDocument().getLastNode();
            final NodeProxy p = (NodeProxy) item;
            serializer.toReceiver(p, false, false);
                        if (p.getNodeType() == Node.ATTRIBUTE_NODE)
                            {item = builder.getDocument().getLastAttr();}
                        else
                            {item = builder.getDocument().getNode(last + 1);}
          } else {
            ((org.exist.memtree.NodeImpl)item).deepCopy();
View Full Code Here

                        "Using cached results", result);}
            return cached.getResult();
        }
        DocumentImpl lastDoc = null;
        for (final Iterator<NodeProxy> i = nodes.iterator(); i.hasNext();) {
            final NodeProxy currentNode = i.next();
            int sizeHint = Constants.NO_SIZE_HINT;
            if (lastDoc == null || currentNode.getDocument() != lastDoc) {
                lastDoc = currentNode.getDocument();
                sizeHint = nodes.getSizeHint(lastDoc);
            }
            ContextItem contextItem = currentNode.getContext();
            if (contextItem == null) {
                throw new XPathException(this,
                    "Internal evaluation error: context is missing for node " +
                    currentNode.getNodeId() + " !");
            }
            // TODO : review to consider transverse context
            while (contextItem != null) {
                if (contextItem.getContextId() == getExpressionId()) {
                    final NodeProxy next = contextItem.getNode();
                    if (contextIsVirtual || contextSet.contains(next)) {
                        next.addMatches(currentNode);
                        result.add(next, sizeHint);
                    }
                }
                contextItem = contextItem.getNextDirect();
            }
View Full Code Here

                if (contextSet.getDocumentSet().intersection(
                        outerNodeSet.getDocumentSet()).getDocumentCount() == 0)
                        {LOG.info("contextSet and outerNodeSet don't share any document");}
                final NewArrayNodeSet temp = new NewArrayNodeSet(100);
                for (final SequenceIterator i = ancestors.iterate(); i.hasNext();) {
                    NodeProxy p = (NodeProxy) i.nextItem();
                    ContextItem contextNode = p.getContext();
                    temp.reset();
                    while (contextNode != null) {
                        if (contextNode.getContextId() == getExpressionId())
                            {temp.add(contextNode.getNode());}
                        contextNode = contextNode.getNextDirect();
                    }
                    p.clearContext(getExpressionId());
                    // TODO : understand why we sort here...
                    temp.sortInDocumentOrder();
                    for (final SequenceIterator j = innerSeq.iterate(); j.hasNext();) {
                        final NumericValue v = (NumericValue) j.nextItem();
                        // Non integers return... nothing, not even an error !
                        if (!v.hasFractionalPart() && !v.isZero()) {
                            // ... whereas we don't want a sorted array here
                            // TODO : rename this method as getInDocumentOrder ? -pb
                            p = temp.get(v.getInt() - 1);
                            if (p != null) {
                                result.add(p);
                            }
                            // TODO : does null make sense here ? Well... sometimes ;-)
                        }
                    }
                }
                break;
            }
            default:
                for (final SequenceIterator i = outerSequence.iterate(); i.hasNext();) {
                    NodeProxy p = (NodeProxy) i.nextItem();
                    Sequence temp;
                    boolean reverseAxis = true;
                    switch (mode) {
                    case Constants.ANCESTOR_AXIS:
                        temp = contextSet.selectAncestors(p, false, Expression.IGNORE_CONTEXT);
                        break;
                    case Constants.ANCESTOR_SELF_AXIS:
                        temp = contextSet.selectAncestors(p, true, Expression.IGNORE_CONTEXT);
                        break;
                    case Constants.PARENT_AXIS:
                        // TODO : understand why the contextSet is not involved
                        // here
                        // NodeProxy.getParent returns a *theoretical* parent
                        // which is *not* guaranteed to be in the context set !
                        temp = p.getParents(Expression.NO_CONTEXT_ID);
                        break;
                    case Constants.PRECEDING_AXIS:
                        temp = contextSet.selectPreceding(p, Expression.IGNORE_CONTEXT);
                        break;
                    case Constants.PRECEDING_SIBLING_AXIS:
                        temp = contextSet.selectPrecedingSiblings(p, Expression.IGNORE_CONTEXT);
                        break;
                    case Constants.FOLLOWING_SIBLING_AXIS:
                        temp = contextSet.selectFollowingSiblings(p, Expression.IGNORE_CONTEXT);
                        reverseAxis = false;
                        break;
                    case Constants.FOLLOWING_AXIS:
                        temp = contextSet.selectFollowing(p, Expression.IGNORE_CONTEXT);
                        reverseAxis = false;
                        break;
                    case Constants.SELF_AXIS:
                        temp = p;
                        reverseAxis = false;
                        break;
                    default:
                        throw new IllegalArgumentException("Tried to test unknown axis");
                    }
                    if (!temp.isEmpty()) {
                        for (final SequenceIterator j = innerSeq.iterate(); j.hasNext();) {
                            final NumericValue v = (NumericValue) j.nextItem();
                            // Non integers return... nothing, not even an error !
                            if (!v.hasFractionalPart() && !v.isZero()) {
                                final int pos = (reverseAxis ?
                                    temp.getItemCount() - v.getInt() : v.getInt() - 1);
                                // Other positions are ignored
                                if (pos >= 0 && pos < temp.getItemCount()) {
                                    final NodeProxy t = (NodeProxy) temp.itemAt(pos);
                                    // for the current context: filter out those
                                    // context items not selected by the positional predicate
                                    ContextItem ctx = t.getContext();
                                    t.clearContext(Expression.IGNORE_CONTEXT);
                                    while (ctx != null) {
                                        if (ctx.getContextId() == outerContextId) {
                                            if (ctx.getNode().getNodeId().equals(p.getNodeId()))
                                                {t.addContextNode(outerContextId, ctx.getNode());}
                                        } else
                                            {t.addContextNode(ctx.getContextId(), ctx.getNode());}
                                        ctx = ctx.getNextDirect();
                                    }
                                    result.add(t);
                                }
                            }
View Full Code Here

          final Item next = i.nextItem();
          if(Type.subTypeOf(next.getType(), Type.NODE)) {
              final NodeValue nv = (NodeValue)next;
              if(nv.getImplementationType() != NodeValue.PERSISTENT_NODE)
                {throw new XPathException(this, getName() + " cannot be applied to in-memory nodes.");}
              final NodeProxy np = (NodeProxy)nv;
              Match match = np.getMatches();
              while (match != null) {
                if (match.getNodeId().isDescendantOrSelfOf(np.getNodeId())) {
                  count += match.getFrequency();
                }
                match = match.getNextMatch();
           }
          }
View Full Code Here

    final NodeSet result = new NewArrayNodeSet();
    final DateTimeValue dtv = (DateTimeValue) args[1].itemAt(0);
    final long lastModified = dtv.getDate().getTime();
   
    for (final NodeSetIterator i = nodes.iterator(); i.hasNext(); ) {
      final NodeProxy proxy = i.next();
      final DocumentImpl doc = proxy.getDocument();
      final long modified = doc.getMetadata().getLastModified();
      if (modified > lastModified)
        {result.add(proxy);}
    }
    return result;
View Full Code Here

TOP

Related Classes of org.exist.dom.NodeProxy$SingleNodeIterator

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.