Пример #1
0
  /**
   * Executes a query.
   *
   * @param query query to be executed
   * @return list of serialized result items
   * @throws IOException error during query execution
   */
  private StringList execute(final WebDAVQuery query) throws IOException {
    final ClassLoader cl = getClass().getClassLoader();
    final InputStream s = cl.getResourceAsStream(FILE);
    if (s == null) throw new IOException("WebDAV module not found");
    final byte[] module = new IOStream(s).read();

    final QueryProcessor qp = new QueryProcessor(query.toString(), http.context());
    try {
      for (final Entry<String, Object> entry : query.entries()) {
        qp.bind(entry.getKey(), entry.getValue());
      }
      qp.ctx.parseLibrary(string(module), FILE, qp.sc);

      final Result r = qp.execute();
      final int n = (int) r.size();
      final StringList items = new StringList(n);
      for (int i = 0; i < n; i++) {
        final ArrayOutput ao = new ArrayOutput();
        r.serialize(Serializer.get(ao), 0);
        items.add(ao.toString());
      }
      return items;
    } catch (final QueryException ex) {
      throw new BaseXException(ex);
    } catch (final Exception ex) {
      Util.debug(ex);
      throw new BaseXException(ex);
    } finally {
      qp.close();
    }
  }