Пример #1
0
  @Override
  public void action(final Object comp) {
    final boolean valid = general.action(comp, true);
    ft.action(ftxindex.isSelected());

    // ...must be located before remaining checks
    if (comp == general.browse || comp == general.input) dbname.setText(general.dbname);

    final String nm = dbname.getText().trim();
    ok = valid && !nm.isEmpty();

    String inf = valid ? ok ? null : ENTER_DB_NAME : RES_NOT_FOUND;
    Msg icon = Msg.ERROR;
    if (ok) {
      ok = Databases.validName(nm);
      if (ok) gui.gopts.set(GUIOptions.DBNAME, nm);

      if (!ok) {
        // name of database is invalid
        inf = Util.info(INVALID_X, NAME);
      } else if (general.input.getText().trim().isEmpty()) {
        // database will be empty
        inf = EMPTY_DB;
        icon = Msg.WARN;
      } else if (db.contains(nm)) {
        // old database will be overwritten
        inf = OVERWRITE_DB;
        icon = Msg.WARN;
      }
    }

    general.info.setText(inf, icon);
    enableOK(buttons, B_OK, ok);
  }
Пример #2
0
  @Override
  public Item item(final QueryContext qc, final InputInfo ii) throws QueryException {
    final String name = string(toToken(exprs[0], qc));
    if (!Databases.validName(name)) throw BXDB_NAME_X.get(info, name);
    if (!qc.context.soptions.dbExists(name)) throw BXDB_WHICH_X.get(info, name);

    qc.resources.updates().add(new BackupCreate(name, info, qc), qc);
    return null;
  }
Пример #3
0
 /**
  * Parses and returns a glob expression, which extends {@link #name(Cmd)} function with asterisks,
  * question marks and commands.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return glob expression
  * @throws QueryException query exception
  */
 private String glob(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   while (true) {
     final char ch = parser.curr();
     if (!Databases.validChar(ch) && ch != '*' && ch != '?' && ch != ',') {
       return finish(eoc() || ws(ch) ? sb : null, cmd);
     }
     sb.append(parser.consume());
   }
 }
Пример #4
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;
  }
Пример #5
0
  @Override
  protected boolean run() {
    // close existing database
    new Close().run(context);

    final String db = args[0];
    if (!Databases.validName(db)) return error(NAME_INVALID_X, db);

    try {
      final Data data = open(db, context);
      context.openDB(data);
      if (data.meta.oldindex()) info(H_INDEX_FORMAT);
      if (data.meta.corrupt) info(DB_CORRUPT);
      return info(DB_OPENED_X, db, perf);
    } catch (final IOException ex) {
      return error(Util.message(ex));
    }
  }
Пример #6
0
 /**
  * Parses and returns a name. A name may contain letters, numbers and any of the special
  * characters <code>!#$%&'()+-=@[]^_`{}~</code>.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return name
  * @throws QueryException query exception
  */
 private String name(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   while (Databases.validChar(parser.curr())) sb.append(parser.consume());
   return finish(eoc() || ws(parser.curr()) ? sb : null, cmd);
 }