コード例 #1
0
ファイル: QueryTest.java プロジェクト: runeengh/basex
 /**
  * Creates a container for the specified node values.
  *
  * @param doc document
  */
 protected static void create(final String doc) {
   try {
     new CreateDB(Util.className(SandboxTest.class), doc).execute(context);
   } catch (final BaseXException ex) {
     Util.notExpected(ex);
   }
 }
コード例 #2
0
ファイル: Functions.java プロジェクト: Ruritariye/basex
 /** Constructor, registering statically available XQuery functions. */
 private Functions() {
   for (final Function def : Function.values()) {
     final String dsc = def.desc;
     final byte[] ln = token(dsc.substring(0, dsc.indexOf(PAR1)));
     final int i = add(new QNm(ln, def.uri()).id());
     if (i < 0) Util.notexpected("Function defined twice:" + def);
     funcs[i] = def;
   }
 }
コード例 #3
0
ファイル: QueryTest.java プロジェクト: runeengh/basex
  /** Tests the specified instance. */
  @Test
  public void test() {
    final StringBuilder sb = new StringBuilder();
    int fail = 0;

    for (final Object[] qu : queries) {
      final boolean correct = qu.length == 3;
      final String query = qu[correct ? 2 : 1].toString();
      final Value cmp = correct ? (Value) qu[1] : null;

      final QueryProcessor qp = new QueryProcessor(query, context);
      try {
        final Value val = qp.value();
        if (!correct || !new DeepCompare().equal(val, cmp)) {
          sb.append("[" + qu[0] + "] " + query);
          String s = correct && cmp.size() != 1 ? "#" + cmp.size() : "";
          sb.append("\n[E" + s + "] ");
          if (correct) {
            final String cp = cmp.toString();
            sb.append('\'');
            sb.append(cp.length() > 1000 ? cp.substring(0, 1000) + "..." : cp);
            sb.append('\'');
          } else {
            sb.append("error");
          }
          final TokenBuilder types = new TokenBuilder();
          for (final Item it : val) types.add(it.type.toString()).add(" ");
          s = val.size() == 1 ? "" : "#" + val.size();
          sb.append("\n[F" + s + "] '" + val + "', " + types + details() + '\n');
          ++fail;
        }
      } catch (final Exception ex) {
        final String msg = ex.getMessage();
        if (correct || msg == null || msg.contains("mailman")) {
          final String cp = correct && cmp.data() != null ? cmp.toString() : "()";
          sb.append(
              "["
                  + qu[0]
                  + "] "
                  + query
                  + "\n[E] "
                  + cp
                  + "\n[F] "
                  + (msg == null ? Util.className(ex) : msg.replaceAll("\r\n?|\n", " "))
                  + ' '
                  + details()
                  + '\n');
          ex.printStackTrace();
          ++fail;
        }
      } finally {
        qp.close();
      }
    }
    if (fail != 0) fail(fail + " Errors. [E] = expected, [F] = found:\n" + sb.toString().trim());
  }
コード例 #4
0
ファイル: TypeSwitch.java プロジェクト: fpapai/basex
 @Override
 public Iter iter(final QueryContext qc) throws QueryException {
   final Value seq = qc.value(ts);
   for (final TypeCase tc : cases) {
     final Iter iter = tc.iter(qc, seq);
     if (iter != null) return iter;
   }
   // will never happen
   throw Util.notExpected();
 }
コード例 #5
0
  /**
   * Parses a string as XML and adds the resulting nodes to the specified parent.
   *
   * @param value string to parse
   * @param elem element
   */
  public static void add(final byte[] value, final FElem elem) {

    try {
      final Parser parser = new XMLParser(new IOContent(value), MainOptions.get(), true);
      for (final ANode node : new DBNode(parser).children()) elem.add(node.copy());
    } catch (final IOException ex) {
      // fallback: add string representation
      Util.debug(ex);
      elem.add(value);
    }
  }
コード例 #6
0
ファイル: RestXqFunction.java プロジェクト: jolau/basex-api
 /**
  * Adds parameters from the passed on request body.
  *
  * @param body request body
  * @param params map parameters
  */
 private static void addParams(final String body, final Map<String, String[]> params) {
   for (final String nv : body.split("&")) {
     final String[] parts = nv.split("=", 2);
     if (parts.length < 2) continue;
     try {
       params.put(parts[0], new String[] {URLDecoder.decode(parts[1], Token.UTF8)});
     } catch (final Exception ex) {
       Util.notexpected(ex);
     }
   }
 }
コード例 #7
0
ファイル: B64.java プロジェクト: runeengh/basex
 @Override
 public String toString() {
   return Util.info("\"%\"", org.basex.util.Base64.encode(data));
 }
コード例 #8
0
ファイル: RestXqFunction.java プロジェクト: jolau/basex-api
 /**
  * Creates an exception with the specified message.
  *
  * @param msg message
  * @param ext error extension
  * @return exception
  * @throws QueryException query exception
  */
 QueryException error(final String msg, final Object... ext) throws QueryException {
   throw new QueryException(function.info, Err.BASX_RESTXQ, Util.info(msg, ext));
 }