/* (non-Javadoc)
  * @see org.exist.xquery.value.Sequence#toNodeSet()
  */
 public NodeSet toNodeSet() throws XPathException {
   // for this method to work, all items have to be nodes
   if (itemType != Type.ANY_TYPE && Type.subTypeOf(itemType, Type.NODE)) {
     final NodeSet set = new ExtArrayNodeSet();
     // We can't make it from an ExtArrayNodeSet (probably because it is sorted ?)
     // NodeSet set = new ArraySet(100);
     for (int i = 0; i < this.count; i++) {
       NodeValue v = null;
       final Entry temp = items[i];
       v = (NodeValue) temp.item;
       if (v.getImplementationType() != NodeValue.PERSISTENT_NODE) {
         set.add((NodeProxy) v);
       } else {
         set.add((NodeProxy) v);
       }
     }
     return set;
   } else {
     throw new XPathException(
         "Type error: the sequence cannot be converted into"
             + " a node set. Item type is "
             + Type.getTypeName(itemType));
   }
 }
Beispiel #2
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;
  }