Ejemplo n.º 1
0
 /**
  * Finds the closest namespace node for the specified pre value.
  *
  * @param pre pre value
  * @param data data reference
  * @return node
  */
 NSNode find(final int pre, final Data data) {
   final int s = find(pre);
   // no match found: return current node
   if (s == -1) return this;
   final NSNode ch = children[s];
   final int cp = ch.pr;
   // return exact hit
   if (cp == pre) return ch;
   // found node is preceding sibling
   if (cp + data.size(cp, Data.ELEM) <= pre) return this;
   // continue recursive search
   return children[s].find(pre, data);
 }
Ejemplo n.º 2
0
  /**
   * Lists resources of the specified database.
   *
   * @return success flag
   * @throws IOException I/O exception
   */
  private boolean listDB() throws IOException {
    final String db = args[0];
    final String path = args[1] != null ? args[1] : "";
    if (!Databases.validName(db)) return error(NAME_INVALID_X, db);

    final Table table = new Table();
    table.description = RESOURCES;
    table.header.add(INPUT_PATH);
    table.header.add(TYPE);
    table.header.add(MimeTypes.CONTENT_TYPE);
    table.header.add(SIZE);

    try {
      // add xml documents
      final Data data = Open.open(db, context);
      final Resources res = data.resources;
      final IntList il = res.docs(path);
      final int ds = il.size();
      for (int i = 0; i < ds; i++) {
        final int pre = il.get(i);
        final TokenList tl = new TokenList(3);
        final byte[] file = data.text(pre, true);
        tl.add(file);
        tl.add(DataText.M_XML);
        tl.add(MimeTypes.APP_XML);
        tl.add(data.size(pre, Data.DOC));
        table.contents.add(tl);
      }
      // add binary resources
      for (final byte[] file : res.binaries(path)) {
        final String f = string(file);
        final TokenList tl = new TokenList(3);
        tl.add(file);
        tl.add(DataText.M_RAW);
        tl.add(MimeTypes.get(f));
        tl.add(data.meta.binary(f).length());
        table.contents.add(tl);
      }
      Close.close(data, context);
    } catch (final IOException ex) {
      return error(Util.message(ex));
    }
    out.println(table.sort().finish());
    return true;
  }
Ejemplo n.º 3
0
 public synchronized int size(Object key) {
   Data data = (Data) map.get(key);
   if (data == null) map.put(key, (data = new Data(key)));
   return data.size();
 }