public NodeSet filterDocuments(NodeSet otherSet) {
   DocumentSet docs = otherSet.getDocumentSet();
   NodeSet newSet = new NewArrayNodeSet();
   for (Iterator i = iterator(); i.hasNext(); ) {
     NodeProxy p = (NodeProxy) i.next();
     if (docs.contains(p.getDocument().getDocId())) newSet.add(p);
   }
   return newSet;
 }
  /**
   * Return a new node set containing the parent nodes of all nodes in the current set.
   *
   * @param contextId an <code>int</code> value
   * @return a <code>NodeSet</code> value
   */
  public NodeSet getParents(int contextId) {
    NodeSet parents = new NewArrayNodeSet();
    NodeProxy parent = null;
    for (Iterator i = iterator(); i.hasNext(); ) {
      NodeProxy current = (NodeProxy) i.next();
      NodeId parentID = current.getNodeId().getParentId();
      // Filter out the temporary nodes wrapper element
      // Moved the parentID != NodeId.DOCUMENT_NODE test inside for /a/parent::node() to work
      // correctly.
      // Added the needed test parentID != null, detected in org.exist.xquery.OptimizerTest
      // "//node()[parent::mods:title &= 'ethnic']" which caused an NPE here
      // since I dont know when. /ljo
      if (parentID != null
          && !(parentID.getTreeLevel() == 1
              && current.getDocument().getCollection().isTempCollection())) {
        if (parent == null
            || parent.getDocument().getDocId() != current.getDocument().getDocId()
            || !parent.getNodeId().equals(parentID)) {
          if (parentID != NodeId.DOCUMENT_NODE) {
            parent =
                new NodeProxy(
                    current.getDocument(),
                    parentID,
                    Node.ELEMENT_NODE,
                    StoredNode.UNKNOWN_NODE_IMPL_ADDRESS);
          } else {
            parent =
                new NodeProxy(
                    current.getDocument(),
                    parentID,
                    Node.DOCUMENT_NODE,
                    StoredNode.UNKNOWN_NODE_IMPL_ADDRESS);
          }
        }
        if (Expression.NO_CONTEXT_ID != contextId) {
          parent.addContextNode(contextId, current);
        } else {
          parent.copyContext(current);
        }
        parent.addMatches(current);
        parents.add(parent);
      }
    }

    return parents;
  }
示例#3
0
  /* (non-Javadoc)
   * @see org.exist.xquery.Expression#eval(org.exist.dom.DocumentSet, org.exist.xquery.value.Sequence, org.exist.xquery.value.Item)
   */
  public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
    logger.error(
        "Use of deprecated function fn:doctype(). "
            + "It will be removed soon. Please "
            + "use util:doctype() instead.");
    if (context.getProfiler().isEnabled()) {
      context.getProfiler().start(this);
      context
          .getProfiler()
          .message(
              this,
              Profiler.DEPENDENCIES,
              "DEPENDENCIES",
              Dependency.getDependenciesName(this.getDependencies()));
      if (contextSequence != null)
        context
            .getProfiler()
            .message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
      if (contextItem != null)
        context
            .getProfiler()
            .message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());
    }

    MutableDocumentSet docs = new DefaultDocumentSet();
    for (int i = 0; i < getArgumentCount(); i++) {
      Sequence seq = getArgument(i).eval(contextSequence, contextItem);
      for (SequenceIterator j = seq.iterate(); j.hasNext(); ) {
        String next = j.nextItem().getStringValue();
        context.getBroker().getXMLResourcesByDoctype(next, docs);
      }
    }

    NodeSet result = new ExtArrayNodeSet(1);
    for (Iterator i = docs.getDocumentIterator(); i.hasNext(); ) {
      result.add(new NodeProxy((DocumentImpl) i.next(), NodeId.DOCUMENT_NODE));
    }

    if (context.getProfiler().isEnabled()) context.getProfiler().end(this, "", result);

    return result;
  }