Exemple #1
0
 /**
  * Checks the response to an HTTP request.
  *
  * @param v query result
  * @param itemsCount expected number of items
  * @param expStatus expected status
  */
 private static void checkResponse(final Value v, final int itemsCount, final int expStatus) {
   assertEquals(itemsCount, v.size());
   assertTrue(v.itemAt(0) instanceof FElem);
   final FElem response = (FElem) v.itemAt(0);
   assertNotNull(response.attributes());
   if (!eq(response.attribute(STATUS), token(expStatus))) {
     fail("Expected: " + expStatus + "\nFound: " + response);
   }
 }
  /**
   * 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);
    }
  }
  /**
   * Creates annotation child elements.
   *
   * @param anns annotations
   * @param parent parent element
   * @param uri include uri
   * @throws QueryException query exception
   */
  final void annotation(final AnnList anns, final FElem parent, final boolean uri)
      throws QueryException {

    for (final Ann ann : anns) {
      final FElem annotation = elem("annotation", parent);
      if (ann.sig != null) {
        annotation.add("name", ann.sig.id());
        if (uri) annotation.add("uri", ann.sig.uri);
      } else {
        annotation.add("name", ann.name.string());
        if (uri) annotation.add("uri", ann.name.uri());
      }

      for (final Item it : ann.args) {
        final FElem literal = elem("literal", annotation);
        literal.add("type", it.type.toString()).add(it.string(null));
      }
    }
  }