예제 #1
0
 /**
  * Converts the specified commands into a string list.
  *
  * @param comp input completions
  * @return string list
  */
 private static StringList list(final Enum<?>[] comp) {
   final StringList list = new StringList();
   if (comp != null) {
     for (final Enum<?> c : comp) list.add(c.name().toLowerCase(Locale.ENGLISH));
   }
   return list;
 }
예제 #2
0
파일: Command.java 프로젝트: plutext/basex
 /**
  * Adds the names of the database that has been addressed by the argument index. No databases will
  * be added if the argument uses glob syntax.
  *
  * @param db databases
  * @param a argument index
  * @return {@code false} if database cannot be determined due to glob syntax
  */
 protected final boolean databases(final StringList db, final int a) {
   // return true if the addressed database argument does not exists
   if (args.length <= a || args[a] == null) return true;
   final boolean noglob = !args[a].matches(".*[\\?\\*,].*");
   if (noglob) db.add(args[a]);
   return noglob;
 }
예제 #3
0
파일: List.java 프로젝트: JohnLeM/basex
 /**
  * Returns a list of all databases.
  *
  * @param ctx database context
  * @return list of databases
  */
 public static StringList list(final Context ctx) {
   final StringList db = new StringList();
   for (final IOFile f : ctx.mprop.dbpath().children()) {
     final String name = f.name();
     if (f.isDir() && !name.startsWith(".")) db.add(name);
   }
   return db.sort(false);
 }
예제 #4
0
 /**
  * Refreshes the list of recent query files and updates the query path.
  *
  * @param file new file
  */
 void refreshHistory(final IOFile file) {
   final StringList sl = new StringList();
   String path = null;
   if (file != null) {
     path = file.path();
     gui.gprop.set(GUIProp.WORKPATH, file.dirPath());
     sl.add(path);
     tabs.setToolTipTextAt(tabs.getSelectedIndex(), path);
   }
   final String[] qu = gui.gprop.strings(GUIProp.EDITOR);
   for (int q = 0; q < qu.length && q < 19; q++) {
     final String f = qu[q];
     if (!f.equalsIgnoreCase(path) && IO.get(f).exists()) sl.add(f);
   }
   // store sorted history
   gui.gprop.set(GUIProp.EDITOR, sl.toArray());
   hist.setEnabled(!sl.isEmpty());
 }
예제 #5
0
  /**
   * Default constructor.
   *
   * @param main reference to the main window
   */
  public DialogExport(final GUI main) {
    super(main, EXPORT);

    // create checkboxes
    final BaseXBack p = new BaseXBack(new TableLayout(4, 1, 0, 0));
    p.add(new BaseXLabel(OUTPUT_DIR + COL, true, true).border(0, 0, 6, 0));

    // output label
    BaseXBack pp = new BaseXBack(new TableLayout(1, 2, 8, 0));

    path = new BaseXTextField(main.gopts.get(GUIOptions.INPUTPATH), this);
    pp.add(path.history(GUIOptions.INPUTS, this));

    final BaseXButton browse = new BaseXButton(BROWSE_D, this);
    browse.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            choose();
          }
        });
    pp.add(browse);
    p.add(pp);

    // provide components for method and encoding
    final MainOptions opts = gui.context.options;
    final SerializerOptions sopts = opts.get(MainOptions.EXPORTER);

    // method (ignore last entry)
    final StringList sl = new StringList();
    for (final SerialMethod sm : SerialMethod.values()) sl.add(sm.name());
    sl.remove(sl.size() - 1);
    method = new BaseXCombo(this, sl.finish());
    final SerialMethod sm = sopts.get(SerializerOptions.METHOD);
    method.setSelectedItem((sm == null ? SerialMethod.BASEX : sm).name());

    mparams = new BaseXTextField(this);
    mparams.setColumns(24);

    final BaseXBack mth = new BaseXBack(new TableLayout(1, 2, 8, 0));
    mth.add(method);
    mth.add(mparams);

    encoding = new BaseXCombo(this, ENCODINGS);
    String enc = sopts.get(SerializerOptions.ENCODING);
    boolean f = false;
    for (final String s : ENCODINGS) f |= s.equals(enc);
    if (!f) {
      enc = enc.toUpperCase(Locale.ENGLISH);
      for (final String s : ENCODINGS) f |= s.equals(enc);
    }
    encoding.setSelectedItem(f ? enc : sopts.get(SerializerOptions.ENCODING));

    params = new BaseXTextField(sopts.toString(), this);
    params.setToolTipText(tooltip(SerializerMode.DEFAULT.get()));

    pp = new BaseXBack(new TableLayout(3, 2, 16, 6)).border(8, 0, 8, 0);
    pp.add(new BaseXLabel(METHOD + COL, true, true));
    pp.add(mth);
    pp.add(new BaseXLabel(ENCODING + COL, true, true));
    pp.add(encoding);
    pp.add(new BaseXLabel(PARAMETERS + COL, true, true));
    pp.add(params);
    p.add(pp);
    info = new BaseXLabel(" ").border(8, 0, 0, 0);
    p.add(info);

    // indentation
    set(p, BorderLayout.CENTER);

    // buttons
    pp = new BaseXBack(new BorderLayout());
    buttons = okCancel();
    pp.add(buttons, BorderLayout.EAST);
    set(pp, BorderLayout.SOUTH);

    action(method);
    finish(null);
  }
예제 #6
0
파일: BaseX.java 프로젝트: james-jw/basex
  @Override
  protected final void parseArgs() throws IOException {
    ops = new IntList();
    vals = new StringList();

    final MainParser arg = new MainParser(this);
    while (arg.more()) {
      final char c;
      String v = null;
      if (arg.dash()) {
        c = arg.next();
        if (c == 'd') {
          // activate debug mode
          Prop.debug = true;
        } else if (c == 'b'
            || c == 'c'
            || c == 'C'
            || c == 'i'
            || c == 'I'
            || c == 'o'
            || c == 'q'
            || c == 'r'
            || c == 's'
            || c == 't' && local()) {
          // options followed by a string
          v = arg.string();
        } else if (c == 'D' && local()
            || c == 'u' && local()
            || c == 'R'
            || c == 'v'
            || c == 'V'
            || c == 'w'
            || c == 'x'
            || c == 'X'
            || c == 'z') {
          // options to be toggled
          v = "";
        } else if (!local()) {
          // client options: need to be set before other options
          if (c == 'n') {
            // set server name
            context.soptions.set(StaticOptions.HOST, arg.string());
          } else if (c == 'p') {
            // set server port
            context.soptions.set(StaticOptions.PORT, arg.number());
          } else if (c == 'P') {
            // specify password
            context.soptions.set(StaticOptions.PASSWORD, arg.string());
          } else if (c == 'U') {
            // specify user name
            context.soptions.set(StaticOptions.USER, arg.string());
          } else {
            throw arg.usage();
          }
        } else {
          throw arg.usage();
        }
      } else {
        v = arg.string().trim();
        // interpret as command file if input string ends with command script suffix
        c = v.endsWith(IO.BXSSUFFIX) ? 'c' : 'Q';
      }
      if (v != null) {
        ops.add(c);
        vals.add(v);
      }
    }
  }