@Override public String det() { final String path = input.io().path(); return path.isEmpty() ? Util.info(LINE_X, input.line()) : Util.info(SCANPOS_X_X, input.io().path(), input.line()); }
/** * Shows a quit dialog for the specified editor. * * @param edit editor to be saved * @return {@code false} if confirmation was canceled */ private boolean confirm(final EditorArea edit) { if (edit.modified && (edit.opened() || edit.getText().length != 0)) { final Boolean ok = BaseXDialog.yesNoCancel(gui, Util.info(CLOSE_FILE_X, edit.file.name())); if (ok == null || ok && !save()) return false; } return true; }
@Override public final void service(final HttpServletRequest req, final HttpServletResponse res) throws IOException { final HTTPContext http = new HTTPContext(req, res, this); final boolean restxq = this instanceof RestXqServlet; try { http.authorize(); run(http); http.log(SC_OK, ""); } catch (final HTTPException ex) { http.status(ex.getStatus(), Util.message(ex), restxq); } catch (final LoginException ex) { http.status(SC_UNAUTHORIZED, Util.message(ex), restxq); } catch (final IOException | QueryException ex) { http.status(SC_BAD_REQUEST, Util.message(ex), restxq); } catch (final ProcException ex) { http.status(SC_BAD_REQUEST, Text.INTERRUPTED, restxq); } catch (final Exception ex) { final String msg = Util.bug(ex); Util.errln(msg); http.status(SC_INTERNAL_SERVER_ERROR, Util.info(UNEXPECTED, msg), restxq); } finally { if (Prop.debug) { Util.outln("_ REQUEST _________________________________" + Prop.NL + req); final Enumeration<String> en = req.getHeaderNames(); while (en.hasMoreElements()) { final String key = en.nextElement(); Util.outln(Text.LI + key + Text.COLS + req.getHeader(key)); } Util.out("_ RESPONSE ________________________________" + Prop.NL + res); } } }
/** * Creates the error message from the specified text and extension array. * * @param text text message with optional placeholders * @param ext info extensions * @return argument */ private static String message(final String text, final Object[] ext) { final int es = ext.length; for (int e = 0; e < es; e++) { if (ext[e] instanceof ExprInfo) ext[e] = chop(((ExprInfo) ext[e]).toErrorString(), null); } return Util.info(text, ext); }
/** Open all selected files externally. */ private void openExternal() { for (final IOFile file : selectedValues()) { try { file.open(); } catch (final IOException ex) { BaseXDialog.error(project.gui, Util.info(FILE_NOT_OPENED_X, file)); } } }
/** * Performs a search. * * @param sc search context * @param jump jump to next hit */ final void search(final SearchContext sc, final boolean jump) { try { rend.search(sc); if (!sc.search.isEmpty()) gui.status.setText(Util.info(Text.STRINGS_FOUND_X, sc.nr())); if (jump) jump(SearchDir.CURRENT, false); } catch (final Exception ex) { final String msg = Util.message(ex).replaceAll(Prop.NL + ".*", ""); gui.status.setError(Text.REGULAR_EXPR + Text.COLS + msg); } }
@Override public void run() { try { for (int i = 0; i < runs; ++i) { Performance.sleep((long) (50 * RND.nextDouble())); // Return nth text of the database final int n = RND.nextInt() % MAX + 1; final String qu = Util.info(QUERY, n); new XQuery(qu).execute(context); } } catch (final BaseXException ex) { ex.printStackTrace(); } }
/** * Returns a keystroke for the specified string. * * @param cmd command * @return keystroke */ public static KeyStroke keyStroke(final GUICommand cmd) { final Object sc = cmd.shortcuts(); if (sc == null) return null; final String scut; if (sc instanceof BaseXKeys[]) { final BaseXKeys[] scs = (BaseXKeys[]) sc; if (scs.length == 0) return null; scut = scs[0].shortCut(); } else { scut = Util.info(sc, META); } final KeyStroke ks = KeyStroke.getKeyStroke(scut); if (ks == null) Util.errln("Could not assign shortcut: " + sc + " / " + scut); return ks; }
@Override public void run() { try { // Perform some queries for (int i = 0; i < runs; ++i) { Performance.sleep((long) (50 * RND.nextDouble())); // Return nth text of the database final int n = RND.nextInt() % MAX + 1; final String qu = Util.info(QUERY, n); session.execute("xquery " + qu); } session.close(); } catch (final Exception ex) { ex.printStackTrace(); } }
@Override public final String toString() { return Util.info("\"%\"", string(null)); }
/** * 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)); }
/** * Returns an error string for an unknown key. * * @param key key * @return error string */ public final synchronized String unknown(final String key) { final String sim = similar(key); return Util.info(sim != null ? Text.UNKNOWN_OPT_SIMILAR_X_X : Text.UNKNOWN_OPTION_X, key, sim); }
@Override public String header() { return Util.info(S_CONSOLE_X, local() ? S_STANDALONE : S_CLIENT); }