/** * 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); }
/** * Recursively populates the cache. * * @param root root directory * @param pc file cache * @throws InterruptedException interruption */ void add(final IOFile root, final ProjectCache pc) throws InterruptedException { // check if file cache was replaced or invalidated if (pc != cache) throw new InterruptedException(); final IOFile[] files = root.children(); for (final IOFile file : files) { if (file.name().equals(IO.IGNORESUFFIX)) return; } for (final IOFile file : files) { if (file.isDir()) { add(file, pc); } else { pc.add(file.path()); } } }
@Override protected boolean run() throws IOException { final String path = MetaData.normPath(args[0]); if (path == null) return error(NAME_INVALID_X, args[0]); final IOFile bin = context.data().meta.binary(path); if (bin == null || !bin.exists() || bin.isDir()) return error(RES_NOT_FOUND_X, path); try { final BufferInput bi = new BufferInput(bin); try { for (int b; (b = bi.read()) != -1; ) out.write(b); } finally { bi.close(); } return info(QUERY_EXECUTED_X, perf); } catch (final IOException ex) { return error(FILE_NOT_STORED_X, ex); } }
@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); }
@Override protected boolean run() { final boolean create = context.user.has(Perm.CREATE); String path = MetaData.normPath(args[0]); if (path == null || path.endsWith(".")) return error(NAME_INVALID_X, args[0]); if (in == null) { final IO io = IO.get(args[1]); if (!io.exists() || io.isDir()) return error(RES_NOT_FOUND_X, create ? io : args[1]); in = io.inputSource(); // set/add name of document if ((path.isEmpty() || path.endsWith("/")) && !(io instanceof IOContent)) path += io.name(); } // ensure that the final name is not empty if (path.isEmpty()) return error(NAME_INVALID_X, path); // ensure that the name is not empty and contains no trailing dots final Data data = context.data(); if (data.inMemory()) return error(NO_MAINMEM); final IOFile file = data.meta.binary(path); if (path.isEmpty() || path.endsWith(".") || file == null || file.isDir()) return error(NAME_INVALID_X, create ? path : args[0]); // start update if (!data.startUpdate()) return error(DB_PINNED_X, data.meta.name); try { store(in, file); return info(QUERY_EXECUTED_X_X, "", perf); } catch (final IOException ex) { return error(FILE_NOT_STORED_X, Util.message(ex)); } finally { data.finishUpdate(); } }