예제 #1
0
 public static Sequence atomize(Sequence input) throws XPathException {
   if (input.hasOne()) return input.itemAt(0).atomize();
   Item next;
   ValueSequence result = new ValueSequence();
   for (SequenceIterator i = input.iterate(); i.hasNext(); ) {
     next = i.nextItem();
     result.add(next.atomize());
   }
   return result;
 }
예제 #2
0
 /* (non-Javadoc)
  * @see org.exist.xquery.value.AbstractSequence#addAll(org.exist.xquery.value.Sequence)
  */
 public void addAll(Sequence other) throws XPathException {
   if (other.hasOne()) {
     add(other.itemAt(0));
   } else if (!other.isEmpty()) {
     for (final SequenceIterator i = other.iterate(); i.hasNext(); ) {
       final Item next = i.nextItem();
       if (next != null) {
         add(next);
       }
     }
   }
 }
예제 #3
0
 public Entry(Item item) throws XPathException {
   this.item = item;
   values = new AtomicValue[groupSpecs.length];
   for (int i = 0; i < groupSpecs.length; i++) {
     final Sequence seq = groupSpecs[i].getGroupExpression().eval(null);
     values[i] = AtomicValue.EMPTY_VALUE;
     // TODO : get rid of getLength()
     if (seq.hasOne()) {
       values[i] = seq.itemAt(0).atomize();
     } else if (seq.hasMany()) {
       throw new XPathException(
           "expected a single value for group by expression "
               + ExpressionDumper.dump(groupSpecs[i].getGroupExpression())
               + " ; found: "
               + seq.getItemCount());
     }
   }
 }
예제 #4
0
  /** @see org.exist.xquery.Expression#eval(Sequence, Item) */
  public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {
    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());
    }

    Sequence result;
    Sequence arg = getArgument(0).eval(contextSequence, contextItem);
    if (arg.isEmpty()) result = BooleanValue.FALSE;
    else {
      String path = arg.itemAt(0).getStringValue();
      try {
        result = BooleanValue.valueOf(DocUtils.isDocumentAvailable(this.context, path));
      } catch (Exception e) {
        throw new XPathException(getASTNode(), e.getMessage());
      }
    }

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

    return result;
  }
예제 #5
0
  /*
   * (non-Javadoc)
   *
   * @see org.exist.xquery.BasicFunction#eval(org.exist.xquery.value.Sequence[],
   *      org.exist.xquery.value.Sequence)
   */
  public Sequence eval(Sequence contextSequence, Item contextItem) throws XPathException {

    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());
    }

    Expression arg1 = getArgument(0);
    Sequence s1 = arg1.eval(contextSequence, contextItem);

    Expression arg2 = getArgument(1);
    context.pushDocumentContext();
    Sequence s2 = arg2.eval(contextSequence, contextItem);
    context.popDocumentContext();

    if (s1.isEmpty()) {
      return BooleanValue.valueOf(s2.isEmpty());
    } else if (s2.isEmpty()) {
      return BooleanValue.valueOf(s1.isEmpty());
    }

    Sequence result = null;
    StringBuffer v1 = new StringBuffer();
    StringBuffer v2 = new StringBuffer();
    try {
      if (s1.hasMany()) {
        for (int i = 0; i < s1.getItemCount(); i++) {
          v1.append(serialize((NodeValue) s1.itemAt(i)));
        }
      } else {
        v1.append(serialize((NodeValue) s1.itemAt(0)));
      }
      if (s2.hasMany()) {
        for (int i = 0; i < s2.getItemCount(); i++) {
          v2.append(serialize((NodeValue) s2.itemAt(i)));
        }
      } else {
        v2.append(serialize((NodeValue) s2.itemAt(0)));
      }
      Diff d = new Diff(v1.toString(), v2.toString());
      boolean identical = d.identical();
      if (!identical) {
        logger.warn("Diff result: " + d.toString());
      }
      result = new BooleanValue(identical);
    } catch (Exception e) {
      throw new XPathException(
          this,
          "An exception occurred while serializing node " + "for comparison: " + e.getMessage(),
          e);
    }

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

    return result;
  }