/** * Returns a map with variable bindings. * * @param opts main options * @return bindings */ public static HashMap<String, String> bindings(final MainOptions opts) { final HashMap<String, String> bindings = new HashMap<>(); final String bind = opts.get(MainOptions.BINDINGS).trim(); final StringBuilder key = new StringBuilder(); final StringBuilder val = new StringBuilder(); boolean first = true; final int sl = bind.length(); for (int s = 0; s < sl; s++) { final char ch = bind.charAt(s); if (first) { if (ch == '=') { first = false; } else { key.append(ch); } } else { if (ch == ',') { if (s + 1 == sl || bind.charAt(s + 1) != ',') { bindings.put(key.toString().trim(), val.toString()); key.setLength(0); val.setLength(0); first = true; continue; } // literal commas are escaped by a second comma s++; } val.append(ch); } } if (key.length() != 0) bindings.put(key.toString().trim(), val.toString()); return bindings; }
/** * Parses and sets a single database option. * * @param session REST session * @param param current parameter * @param force force execution * @return success flag, indicates if value was found * @throws BaseXException database exception */ static boolean parseOption( final RESTSession session, final Entry<String, String[]> param, final boolean force) throws BaseXException { final String key = param.getKey().toUpperCase(Locale.ENGLISH); final MainOptions options = session.context.options; final boolean found = options.option(key) != null; if (found || force) options.assign(key, param.getValue()[0]); return found; }
/** * Parses a string as XML and adds the resulting nodes to the specified parent. * * @param value string to parse * @param elem element */ public static void add(final byte[] value, final FElem elem) { try { final Parser parser = new XMLParser(new IOContent(value), MainOptions.get(), true); for (final ANode node : new DBNode(parser).children()) elem.add(node.copy()); } catch (final IOException ex) { // fallback: add string representation Util.debug(ex); elem.add(value); } }