예제 #1
0
    @Override
    public void execute(final GUI gui) {
      final boolean rt = gui.gprop.invert(GUIProp.FILTERRT);
      gui.stop();
      // refresh buttons in input bar
      gui.refreshControls();
      // refresh editor buttons
      gui.editor.refreshMark();

      final Context ctx = gui.context;
      final boolean root = ctx.root();
      final Data data = ctx.data();
      if (!rt) {
        if (!root) {
          gui.notify.context(new Nodes(0, data), true, null);
          gui.notify.mark(ctx.current(), null);
        }
      } else {
        if (root) {
          gui.notify.mark(new Nodes(data), null);
        } else {
          final Nodes mark = ctx.marked;
          ctx.marked = new Nodes(data);
          gui.notify.context(mark, true, null);
        }
      }
    }
예제 #2
0
 @Override
 public void execute(final GUI gui) {
   // skip operation for root context
   final Context ctx = gui.context;
   if (ctx.root()) return;
   // jump to database root
   ctx.update();
   gui.notify.context(ctx.current(), false, null);
 }
예제 #3
0
 @Override
 public void execute(final GUI gui) {
   final Context ctx = gui.context;
   Nodes marked = ctx.marked;
   if (marked.size() == 0) {
     final int pre = gui.context.focused;
     if (pre == -1) return;
     marked = new Nodes(pre, ctx.data());
   }
   gui.notify.context(marked, false, null);
 }
  /**
   * Runs the example code.
   *
   * @param args (ignored) command-line arguments
   * @throws BaseXException if a database command fails
   */
  public static void main(final String[] args) throws BaseXException {
    // Create database context
    Context context = new Context();

    System.out.println("=== CreateCollection ===");

    // ------------------------------------------------------------------------
    // You can modify the CREATEFILTER property to import XML
    // files with suffixes other than XML (for example KML):
    new Set("CREATEFILTER", "*.xml").execute(context);

    // Variant 1 --------------------------------------------------------------
    // Create a collection and add all documents within the specified path
    System.out.println("\n* Create a collection.");

    new CreateDB("Collection", "src/main/resources/").execute(context);
    new DropDB("Collection").execute(context);

    // Variant 2 --------------------------------------------------------------
    // Or: Create an empty collection, add documents in a second pass
    // and optimize the database to refresh the index structures
    System.out.println("\n* Create an empty collection and add documents.");

    new CreateDB("Collection").execute(context);
    new Add("", "src/main/resources/").execute(context);
    new Optimize().execute(context);

    // ------------------------------------------------------------------------
    // Remove a single document from the collection
    System.out.println("\n* Remove a single document.");

    new Delete("test.xml").execute(context);

    // ------------------------------------------------------------------------
    // Show information on the currently opened database
    System.out.println("\n* Show database information:");

    System.out.println(new InfoDB().execute(context));

    // ------------------------------------------------------------------------
    // Drop the database
    System.out.println("\n* Drop the collection.");

    new DropDB("Collection").execute(context);

    // ------------------------------------------------------------------------
    // Close the database context
    context.close();
  }
예제 #5
0
파일: Command.java 프로젝트: plutext/basex
  /**
   * Executes the command, prints the result to the specified output stream and returns a success
   * flag.
   *
   * @param ctx database context
   * @param os output stream
   * @return success flag. The {@link #info()} method returns information on a potential exception
   */
  private boolean exec(final Context ctx, final OutputStream os) {
    // check if data reference is available
    final Data dt = ctx.data();
    if (dt == null && data) return error(NO_DB_OPENED);

    // check permissions
    if (!ctx.perm(perm, dt != null ? dt.meta : null)) return error(PERM_REQUIRED_X, perm);

    // set updating flag
    updating = updating(ctx);

    try {
      // register process
      ctx.register(this);
      // run command and return success flag
      return run(ctx, os);
    } finally {
      // guarantee that process will be unregistered
      ctx.unregister(this);
    }
  }
예제 #6
0
 @Override
 public void execute(final GUI gui) {
   // skip operation for root context
   final Context ctx = gui.context;
   if (ctx.root()) return;
   // check if all nodes are document nodes
   boolean doc = true;
   final Data data = ctx.data();
   for (final int pre : ctx.current().pres) doc &= data.kind(pre) == Data.DOC;
   if (doc) {
     // if yes, jump to database root
     ctx.update();
     gui.notify.context(ctx.current(), false, null);
   } else {
     // otherwise, jump to parent nodes
     gui.execute(new Cs(".."));
   }
 }
예제 #7
0
 @Override
 public void execute(final GUI gui) {
   final Context ctx = gui.context;
   final Nodes n = ctx.marked;
   ctx.copied = new Nodes(n.pres, n.data);
 }
예제 #8
0
 /** Static clean-up. */
 @AfterClass
 public static void cleanUpClass() {
   CTX_IX.close();
 }
예제 #9
0
파일: Command.java 프로젝트: plutext/basex
 /**
  * Closes the specified database if it is currently opened and only pinned once.
  *
  * @param ctx database context
  * @param db database to be closed
  * @return closed flag
  */
 protected static boolean close(final Context ctx, final String db) {
   final boolean close =
       ctx.data() != null && db.equals(ctx.data().meta.name) && ctx.dbs.pins(db) == 1;
   return close && new Close().run(ctx);
 }