Exemplo n.º 1
0
  /**
   * Returns the entries of an archive.
   *
   * @param ctx query context
   * @return entries
   * @throws QueryException query exception
   */
  private Iter entries(final QueryContext ctx) throws QueryException {
    final B64 archive = (B64) checkType(checkItem(expr[0], ctx), AtomType.B64);

    final ValueBuilder vb = new ValueBuilder();
    final ArchiveIn in = ArchiveIn.get(archive.input(info), info);
    try {
      while (in.more()) {
        final ZipEntry ze = in.entry();
        if (ze.isDirectory()) continue;
        final FElem e = new FElem(Q_ENTRY, NS);
        long s = ze.getSize();
        if (s != -1) e.add(Q_SIZE, token(s));
        s = ze.getTime();
        if (s != -1) e.add(Q_LAST_MOD, new Dtm(s, info).string(info));
        s = ze.getCompressedSize();
        if (s != -1) e.add(Q_COMP_SIZE, token(s));
        e.add(ze.getName());
        vb.add(e);
      }
      return vb;
    } catch (final IOException ex) {
      Util.debug(ex);
      throw ARCH_FAIL.thrw(info, ex);
    } finally {
      in.close();
    }
  }
Exemplo n.º 2
0
 /**
  * Binds the specified parameter to a variable.
  *
  * @param rxp parameter
  * @param args argument array
  * @param values values to be bound; the parameter's default value is assigned if the argument is
  *     {@code null} or empty
  * @throws QueryException query exception
  */
 private void bind(final RestXqParam rxp, final Expr[] args, final String... values)
     throws QueryException {
   final Value val;
   if (values == null || values.length == 0) {
     val = rxp.value;
   } else {
     final ValueBuilder vb = new ValueBuilder();
     for (final String s : values) vb.add(new Atm(s));
     val = vb.value();
   }
   bind(rxp.name, args, val);
 }
Exemplo n.º 3
0
 /**
  * Returns a parameter.
  *
  * @param value value
  * @param name name
  * @param declared variable declaration flags
  * @return parameter
  * @throws QueryException HTTP exception
  */
 private RestXqParam param(final Value value, final QNm name, final boolean[] declared)
     throws QueryException {
   // [CG] RESTXQ: allow identical field names?
   final long vs = value.size();
   if (vs < 2) error(ANN_PARAMS, "%", name.string(), 2);
   // name of parameter
   final String key = toString(value.itemAt(0), name);
   // variable template
   final QNm qnm = checkVariable(toString(value.itemAt(1), name), declared);
   // default value
   final ValueBuilder vb = new ValueBuilder();
   for (int v = 2; v < vs; v++) vb.add(value.itemAt(v));
   return new RestXqParam(qnm, key, vb.value());
 }
Exemplo n.º 4
0
 /**
  * Extracts binary entries.
  *
  * @param ctx query context
  * @return binary entry
  * @throws QueryException query exception
  */
 private ValueBuilder extractBinary(final QueryContext ctx) throws QueryException {
   final ValueBuilder vb = new ValueBuilder();
   for (final byte[] b : extract(ctx)) vb.add(new B64(b));
   return vb;
 }
Exemplo n.º 5
0
 /**
  * Extracts text entries.
  *
  * @param ctx query context
  * @return text entry
  * @throws QueryException query exception
  */
 private ValueBuilder extractText(final QueryContext ctx) throws QueryException {
   final String enc = encoding(2, ARCH_ENCODING, ctx);
   final ValueBuilder vb = new ValueBuilder();
   for (final byte[] b : extract(ctx)) vb.add(Str.get(encode(b, enc)));
   return vb;
 }