/** * Returns the specified image as icon. * * @param name name of icon * @return icon */ public static ImageIcon icon(final String name) { ImageIcon ii = ICONS.get(name); if (ii != null) return ii; Image img; if (GUIConstants.scale > 1) { // choose large image or none final URL url = GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null; if (url == null) { // resize low-res image if no hi-res image exists img = get(url(name)); final int w = (int) (img.getWidth(null) * GUIConstants.scale); final int h = (int) (img.getHeight(null) * GUIConstants.scale); final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.drawImage(img, 0, 0, w, h, null); g2.dispose(); img = tmp; } else { img = get(url); } } else { img = get(name); } ii = new ImageIcon(img); ICONS.put(name, ii); return ii; }
/** * Returns an icon for the specified file. * * @param file file reference * @return icon */ public static Icon file(final IOFile file) { if (file == null) return UNKNOWN; // fallback code for displaying icons final String path = file.path(); final MediaType type = MediaType.get(path); if (type.isXML()) return XML; if (type.isXQuery()) return XQUERY; if (path.contains(IO.BASEXSUFFIX)) return BASEX; // only works with standard dpi (https://bugs.openjdk.java.net/browse/JDK-6817929) if (Prop.WIN && !GUIConstants.large()) { // retrieve system icons (only supported on Windows) final int p = path.lastIndexOf(path, '.'); final String suffix = p == -1 ? null : path.substring(p + 1); Icon icon = null; if (suffix != null) icon = FILES.get(suffix); if (icon == null) { icon = FS.getSystemIcon(file.file()); if (suffix != null) FILES.put(suffix, icon); } return icon; } // default icon chooser return type.isText() ? TEXT : UNKNOWN; }
/** * Parses connection options. * * @param options options * @return connection properties */ private static Properties connProps(final HashMap<String, String> options) { final Properties props = new Properties(); for (final Entry<String, String> entry : options.entrySet()) { props.setProperty(entry.getKey(), entry.getValue()); } return props; }
/** * Parses the query. * * @param p performance * @throws QueryException query exception */ private void parse(final Performance p) throws QueryException { qp.http(http); for (final Entry<String, String[]> entry : vars.entrySet()) { final String name = entry.getKey(); final String[] value = entry.getValue(); if (name == null) qp.context(value[0], value[1]); else qp.bind(name, value[0], value[1]); } qp.parse(); if (p != null) info.parsing += p.time(); }
/** * Initializes the servlet context, based on the servlet context. Parses all context parameters * and passes them on to the database context. * * @param sc servlet context * @throws IOException I/O exception */ static synchronized void init(final ServletContext sc) throws IOException { // skip process if context has already been initialized if (context != null) return; // set servlet path as home directory final String path = sc.getRealPath("/"); System.setProperty(Prop.PATH, path); // parse all context parameters final HashMap<String, String> map = new HashMap<String, String>(); // store default web root map.put(MainProp.HTTPPATH[0].toString(), path); final Enumeration<?> en = sc.getInitParameterNames(); while (en.hasMoreElements()) { final String key = en.nextElement().toString(); if (!key.startsWith(Prop.DBPREFIX)) continue; // only consider parameters that start with "org.basex." String val = sc.getInitParameter(key); if (eq(key, DBUSER, DBPASS, DBMODE, DBVERBOSE)) { // store servlet-specific parameters as system properties System.setProperty(key, val); } else { // prefix relative paths with absolute servlet path if (key.endsWith("path") && !new File(val).isAbsolute()) { val = path + File.separator + val; } // store remaining parameters (without project prefix) in map map.put(key.substring(Prop.DBPREFIX.length()).toUpperCase(Locale.ENGLISH), val); } } context = new Context(map); if (SERVER.equals(System.getProperty(DBMODE))) { new BaseXServer(context); } else { context.log = new Log(context); } }
@Override public Item item(final QueryContext qc, final InputInfo ii) throws QueryException { checkCreate(qc); // URL to relational database final String url = string(toToken(exprs[0], qc)); final JDBCConnections jdbc = jdbc(qc); try { if (exprs.length > 2) { // credentials final String user = string(toToken(exprs[1], qc)); final String pass = string(toToken(exprs[2], qc)); if (exprs.length == 4) { // connection options final Options opts = toOptions(3, Q_OPTIONS, new Options(), qc); // extract auto-commit mode from options boolean ac = true; final HashMap<String, String> options = opts.free(); final String commit = options.get(AUTO_COMM); if (commit != null) { ac = Strings.yes(commit); options.remove(AUTO_COMM); } // connection properties final Properties props = connProps(options); props.setProperty(USER, user); props.setProperty(PASS, pass); // open connection final Connection conn = getConnection(url, props); // set auto/commit mode conn.setAutoCommit(ac); return Int.get(jdbc.add(conn)); } return Int.get(jdbc.add(getConnection(url, user, pass))); } return Int.get(jdbc.add(getConnection(url))); } catch (final SQLException ex) { throw BXSQ_ERROR_X.get(info, ex); } }
/** Reads in the property file. */ static { try { final String file = "/completions.properties"; final InputStream is = TextPanel.class.getResourceAsStream(file); if (is == null) { Util.errln(file + " not found."); } else { try (final NewlineInput nli = new NewlineInput(is)) { for (String line; (line = nli.readLine()) != null; ) { final int i = line.indexOf('='); if (i == -1 || line.startsWith("#")) continue; final String key = line.substring(0, i), value = line.substring(i + 1); if (REPLACE.put(key, value.replace("\\n", "\n")) != null) { Util.errln(file + ": " + key + " was assigned twice"); } } } } } catch (final IOException ex) { Util.errln(ex); } }
/** * Binds a variable. * * @param name name of variable (if {@code null}, value will be bound as context value) * @param value value to be bound * @param type type * @return reference */ public AQuery bind(final String name, final String value, final String type) { vars.put(name, new String[] {value, type}); return this; }