コード例 #1
0
ファイル: ParseExpr.java プロジェクト: OliverEgli/basex-rss
  /**
   * Checks if an expression yields a valid and existing {@link IO} instance. Returns the instance
   * or an exception.
   *
   * @param e expression to be evaluated
   * @param ctx query context
   * @return io instance
   * @throws QueryException query exception
   */
  public final IO checkIO(final Expr e, final QueryContext ctx) throws QueryException {

    checkAdmin(ctx);
    final byte[] name = checkStr(e, ctx);
    final IO io = IO.get(string(name));
    if (!io.exists()) DOCERR.thrw(input, name);
    return io;
  }
コード例 #2
0
ファイル: Add.java プロジェクト: OliverEgli/basex-rss
  @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));
      }
    }
  }