示例#1
0
 /**
  * Returns the current serialization options.
  *
  * @param mth consider specified serialization method (may be {@code null})
  * @return options
  * @throws BaseXException database exception
  */
 private SerializerOptions options(final SerialMethod mth) throws BaseXException {
   final SerializerOptions sopts = new SerializerOptions();
   sopts.assign(params.getText());
   sopts.set(SerializerOptions.METHOD, SerialMethod.valueOf(method.getSelectedItem()));
   sopts.set(SerializerOptions.ENCODING, encoding.getSelectedItem());
   if (mth == SerialMethod.JSON) {
     final JsonSerialOptions jopts = new JsonSerialOptions();
     jopts.assign(mparams.getText());
     sopts.set(SerializerOptions.JSON, jopts);
   } else if (mth == SerialMethod.CSV) {
     final CsvOptions copts = new CsvOptions();
     copts.assign(mparams.getText());
     sopts.set(SerializerOptions.CSV, copts);
   }
   return sopts;
 }
示例#2
0
  @Override
  public void close() {
    try {
      gui.set(MainOptions.EXPORTER, options(SerialMethod.valueOf(method.getSelectedItem())));
    } catch (final BaseXException ex) {
      throw Util.notExpected(ex);
    }
    if (!ok) return;

    super.close();
    path.store();
  }
示例#3
0
  @Override
  public void action(final Object comp) {
    final String pth = path();
    final IOFile io = new IOFile(pth);
    String inf = io.isDir() && io.children().length > 0 ? DIR_NOT_EMPTY : null;
    ok = !pth.isEmpty();

    final SerialMethod mth = SerialMethod.valueOf(method.getSelectedItem());
    final OptionsOption<? extends Options> opts =
        mth == SerialMethod.JSON
            ? SerializerOptions.JSON
            : mth == SerialMethod.CSV ? SerializerOptions.CSV : null;
    final boolean showmparams = opts != null;
    mparams.setEnabled(showmparams);

    if (ok) {
      gui.gopts.set(GUIOptions.INPUTPATH, pth);
      try {
        if (comp == method) {
          if (showmparams) {
            final Options mopts = options(null).get(opts);
            mparams.setToolTipText(tooltip(mopts));
            mparams.setText(mopts.toString());
          } else {
            mparams.setToolTipText(null);
            mparams.setText("");
          }
        }
        Serializer.get(new ArrayOutput(), options(mth));
      } catch (final IOException ex) {
        ok = false;
        inf = ex.getMessage();
      }
    }

    info.setText(inf, ok ? Msg.WARN : Msg.ERROR);
    enableOK(buttons, B_OK, ok);
  }