예제 #1
0
 /**
  * Checks if the items can be compared. Items are comparable
  *
  * @param b second item
  * @return result of check
  */
 public final boolean comparable(final Item b) {
   return type == b.type
       || num() && b.num()
       || (unt() || str()) && (b.str() || b.unt())
       || dur() && b.dur()
       || func();
 }
예제 #2
0
  @Override
  public void prepare() throws QueryException {
    // build data with all documents, to prevent dirty reads
    md = new MemData(data);
    for (final Item d : docs) {
      final MemData docData;
      if (d.node()) {
        // adding a document node
        final ANode doc = (ANode) d;
        if (doc.ndType() != NodeType.DOC) UPDOCTYPE.thrw(input, doc);
        docData = new MemData(data);
        new DataBuilder(docData).build(doc);
      } else if (d.str()) {
        // adding file(s) from a path
        final String docpath = string(d.atom(input));
        final String nm = ctx.mprop.random(data.meta.name);
        final DirParser p = new DirParser(IO.get(docpath), ctx.prop);
        final MemBuilder b = new MemBuilder(nm, p, ctx.prop);
        try {
          docData = b.build();
        } catch (final IOException e) {
          throw DOCERR.thrw(input, docpath);
        }
      } else {
        throw STRNODTYPE.thrw(input, this, d.type);
      }
      md.insert(md.meta.size, -1, docData);
    }

    // set new names, if needed
    final IntList pres = md.doc();
    if (pres.size() == 1 && name != null) {
      // name is specified and a single document is added: set the name
      final byte[] nm = path == null ? name : concat(path, SLASH, name);
      md.update(pres.get(0), Data.DOC, nm);
    } else if (path != null) {
      // path is specified: replace the path of each new document
      for (int i = 0, is = pres.size(); i < is; i++) {
        final int d = pres.get(i);
        final byte[] old = md.text(d, true);
        final int p = lastIndexOf(old, '/');
        final byte[] nm = p < 0 ? old : subtoken(old, p + 1);
        md.update(d, Data.DOC, concat(path, SLASH, nm));
      }
    }
  }
예제 #3
0
 /**
  * Checks if the specified item is a string or an empty sequence. Returns a token representation
  * or an exception.
  *
  * @param it item to be checked
  * @return item
  * @throws QueryException query exception
  */
 public final byte[] checkEStr(final Item it) throws QueryException {
   if (it == null) return EMPTY;
   if (!it.str() && !it.unt()) Err.type(this, AtomType.STR, it);
   return it.atom(input);
 }
예제 #4
0
 /**
  * Checks if the specified expression yields a string. Returns a token representation or an
  * exception.
  *
  * @param e expression to be evaluated
  * @param ctx query context
  * @return item
  * @throws QueryException query exception
  */
 public final byte[] checkStr(final Expr e, final QueryContext ctx) throws QueryException {
   final Item it = checkItem(e, ctx);
   if (!it.str() && !it.unt()) Err.type(this, AtomType.STR, it);
   return it.atom(input);
 }