@Override public void execute(final GUI gui) { final DialogExport dialog = new DialogExport(gui); if (!dialog.ok()) return; final IOFile root = new IOFile(dialog.path()); // check if existing files will be overwritten if (root.exists()) { IO file = null; boolean overwrite = false; final Data d = gui.context.data(); final IntList il = d.resources.docs(); final int is = il.size(); for (int i = 0; i < is; i++) { file = root.merge(Token.string(d.text(il.get(i), true))); if (file.exists()) { if (overwrite) { // more than one file will be overwritten; check remaining tests file = null; break; } overwrite = true; } } if (overwrite) { // show message for overwriting files or directories final String msg = file == null ? FILES_REPLACE_X : FILE_EXISTS_X; if (file == null) file = root; if (!BaseXDialog.confirm(gui, Util.info(msg, file))) return; } } DialogProgress.execute(gui, new Export(root.path())); }
/** * Adds parameters from the passed on request body. * * @param body request body * @param params map parameters */ private static void addParams(final String body, final Map<String, String[]> params) { for (final String nv : body.split("&")) { final String[] parts = nv.split("=", 2); if (parts.length < 2) continue; try { params.put(parts[0], new String[] {URLDecoder.decode(parts[1], Token.UTF8)}); } catch (final Exception ex) { Util.notexpected(ex); } } }
/** * Returns the color for the specified string or {@code null}. * * @param string string string * @return color */ static String color(final byte[] string) { for (final Object[] color : COLORS) { final int cl = color.length; for (int c = 1; c < cl; c++) { final Object o = color[c]; final byte[] col = o instanceof byte[] ? (byte[]) o : Token.token(o instanceof Class ? Util.className((Class<?>) o) : o.toString()); if (Token.eq(col, string)) return color[0].toString(); } } return null; }
@Override public Item item(final QueryContext qc, final InputInfo ii) throws QueryException { final String form = string(toToken(exprs[0], qc)); final int es = exprs.length; final Object[] args = new Object[es - 1]; for (int e = 1; e < es; e++) { final Item it = exprs[e].item(qc, info); args[e - 1] = it == null ? null : it.type.isUntyped() ? string(it.string(info)) : it.toJava(); } try { return Str.get(String.format(form, args)); } catch (final RuntimeException ex) { throw ERRFORMAT_X_X.get(info, Util.className(ex), ex); } }
/** * Creates an exception with the specified message. * * @param msg message * @param ext error extension * @return exception * @throws QueryException query exception */ QueryException error(final String msg, final Object... ext) throws QueryException { throw new QueryException(function.info, Err.BASX_RESTXQ, Util.info(msg, ext)); }