Esempio n. 1
1
 @Override
 public String getHeaderField(final String field) {
   final List<String> values = headers.get(field);
   final StringBuilder sb = new StringBuilder();
   for (final String v : values) sb.append(v).append(';');
   return sb.substring(0, sb.length() - 1);
 }
Esempio n. 2
1
 /**
  * Returns a tooltip for the specified options string.
  *
  * @param opts serialization options
  * @return string
  */
 private static String tooltip(final Options opts) {
   final StringBuilder sb = new StringBuilder("<html><b>").append(PARAMETERS).append(":</b><br>");
   for (final Option<?> so : opts) {
     if (!(so instanceof OptionsOption)) sb.append("\u2022 ").append(so).append("<br/>");
   }
   return sb.append("</html>").toString();
 }
Esempio n. 3
1
 /**
  * Adds human readable shortcuts to the specified string.
  *
  * @param str text of tooltip
  * @param sc shortcut
  * @return tooltip
  */
 public static String addShortcut(final String str, final String sc) {
   if (sc == null || str == null) return str;
   final StringBuilder sb = new StringBuilder();
   for (final String s : sc.split(" ")) {
     String t = "%".equals(s) ? Prop.MAC ? "meta" : "control" : s;
     if (t.length() != 1) t = Toolkit.getProperty("AWT." + t.toLowerCase(Locale.ENGLISH), t);
     sb.append('+').append(t);
   }
   return str + " (" + sb.substring(1) + ')';
 }
Esempio n. 4
1
  /**
   * Sets a mnemomic for the specified button.
   *
   * @param b button
   * @param mnem mnemonics that have already been assigned
   */
  public static void setMnemonic(final AbstractButton b, final StringBuilder mnem) {
    // do not set mnemonics for Mac! Alt+key used for special characters.
    if (Prop.MAC) return;

    // find and assign unused mnemomic
    final String label = b.getText();
    final int ll = label.length();
    for (int l = 0; l < ll; l++) {
      final char ch = Character.toLowerCase(label.charAt(l));
      if (!letter(ch) || mnem.indexOf(Character.toString(ch)) != -1) continue;
      b.setMnemonic(ch);
      mnem.append(ch);
      break;
    }
  }
Esempio n. 5
0
 @Override
 public String layoutString(final boolean all) {
   final StringBuilder str = new StringBuilder(horiz ? "H " : "V ");
   for (final ViewLayout c : comp) str.append(c.layoutString(all));
   str.append("- ");
   return str.toString();
 }
Esempio n. 6
0
  @Override
  public void keyTyped(final KeyEvent e) {
    if (undo == null || control(e) || DELNEXT.is(e) || DELPREV.is(e) || ESCAPE.is(e)) return;

    text.pos(text.cursor());
    // string to be added
    String ch = String.valueOf(e.getKeyChar());

    // remember if marked text is to be deleted
    boolean del = true;
    final byte[] txt = text.text();
    if (TAB.is(e)) {
      if (text.marked()) {
        // check if lines are to be indented
        final int s = Math.min(text.pos(), text.start());
        final int l = Math.max(text.pos(), text.start()) - 1;
        for (int p = s; p <= l && p < txt.length; p++) del &= txt[p] != '\n';
        if (!del) {
          text.indent(s, l, e.isShiftDown());
          ch = null;
        }
      } else {
        boolean c = true;
        for (int p = text.pos() - 1; p >= 0 && c; p--) {
          final byte b = txt[p];
          c = ws(b);
          if (b == '\n') break;
        }
        if (c) ch = "  ";
      }
    }

    // delete marked text
    if (text.marked() && del) text.delete();

    if (ENTER.is(e)) {
      // adopt indentation from previous line
      final StringBuilder sb = new StringBuilder(1).append(e.getKeyChar());
      int s = 0;
      for (int p = text.pos() - 1; p >= 0; p--) {
        final byte b = txt[p];
        if (b == '\n') break;
        if (b == '\t') {
          s += 2;
        } else if (b == ' ') {
          s++;
        } else {
          s = 0;
        }
      }
      for (int p = 0; p < s; p++) sb.append(' ');
      ch = sb.toString();
    }

    if (ch != null) text.add(ch);
    text.setCaret();
    rend.calc();
    showCursor(2);
    e.consume();
  }
Esempio n. 7
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder(COPY + ' ');
   for (final Let t : copies)
     sb.append(t.var).append(' ').append(ASSIGN).append(' ').append(t.expr).append(' ');
   return sb.append(MODIFY + ' ' + expr[0] + ' ' + RETURN + ' ' + expr[1]).toString();
 }
Esempio n. 8
0
  /**
   * Constructor.
   *
   * @param rq request
   * @param rs response
   * @throws IOException I/O exception
   */
  public HTTPContext(final HttpServletRequest rq, final HttpServletResponse rs) throws IOException {

    req = rq;
    res = rs;
    final String m = rq.getMethod();
    method = HTTPMethod.get(m);

    final StringBuilder uri = new StringBuilder(req.getRequestURL());
    final String qs = req.getQueryString();
    if (qs != null) uri.append('?').append(qs);
    log(false, m, uri);

    // set UTF8 as default encoding (can be overwritten)
    res.setCharacterEncoding(UTF8);

    segments = toSegments(req.getPathInfo());
    path = join(0);

    user = System.getProperty(DBUSER);
    pass = System.getProperty(DBPASS);

    // set session-specific credentials
    final String auth = req.getHeader(AUTHORIZATION);
    if (auth != null) {
      final String[] values = auth.split(" ");
      if (values[0].equals(BASIC)) {
        final String[] cred = Base64.decode(values[1]).split(":", 2);
        if (cred.length != 2) throw new LoginException(NOPASSWD);
        user = cred[0];
        pass = cred[1];
      } else {
        throw new LoginException(WHICHAUTH, values[0]);
      }
    }
  }
Esempio n. 9
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   if (url != null) sb.append(url).append(", ");
   if (line != Integer.MIN_VALUE) sb.append(line).append(':').append(column).append(": ");
   return sb.append(message).toString();
 }
Esempio n. 10
0
 /**
  * Parses and returns a number.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return name
  * @throws QueryException query exception
  */
 private String number(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   if (parser.curr() == '-') sb.append(parser.consume());
   while (digit(parser.curr())) sb.append(parser.consume());
   return finish(eoc() || ws(parser.curr()) ? sb : null, cmd);
 }
Esempio n. 11
0
 /**
  * Parses and returns a command. A command is limited to letters.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return name
  * @throws QueryException query exception
  */
 private String command(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   while (!eoc() && !ws(parser.curr())) {
     sb.append(parser.consume());
   }
   return finish(sb, cmd);
 }
Esempio n. 12
0
 /**
  * Returns an extended error message.
  *
  * @param err error message
  * @return result of check
  */
 private boolean extError(final String err) {
   // will only be evaluated when an error has occurred
   final StringBuilder sb = new StringBuilder();
   if (options.get(MainOptions.QUERYINFO)) {
     sb.append(info()).append(qp.info()).append(NL).append(ERROR).append(COL).append(NL);
   }
   sb.append(err);
   return error(sb.toString());
 }
Esempio n. 13
0
 /**
  * Returns a string representation of all found arguments.
  *
  * @param args array with arguments
  * @return string representation
  */
 static String foundArgs(final Value[] args) {
   // compose found arguments
   final StringBuilder sb = new StringBuilder();
   for (final Value v : args) {
     if (sb.length() != 0) sb.append(", ");
     sb.append(v instanceof Jav ? Util.className(((Jav) v).toJava()) : v.seqType());
   }
   return sb.toString();
 }
Esempio n. 14
0
  /** Tests the specified instance. */
  @Test
  public void test() {
    final StringBuilder sb = new StringBuilder();
    int fail = 0;

    for (final Object[] qu : queries) {
      final boolean correct = qu.length == 3;
      final String query = qu[correct ? 2 : 1].toString();
      final Value cmp = correct ? (Value) qu[1] : null;

      final QueryProcessor qp = new QueryProcessor(query, context);
      try {
        final Value val = qp.value();
        if (!correct || !new DeepCompare().equal(val, cmp)) {
          sb.append("[" + qu[0] + "] " + query);
          String s = correct && cmp.size() != 1 ? "#" + cmp.size() : "";
          sb.append("\n[E" + s + "] ");
          if (correct) {
            final String cp = cmp.toString();
            sb.append('\'');
            sb.append(cp.length() > 1000 ? cp.substring(0, 1000) + "..." : cp);
            sb.append('\'');
          } else {
            sb.append("error");
          }
          final TokenBuilder types = new TokenBuilder();
          for (final Item it : val) types.add(it.type.toString()).add(" ");
          s = val.size() == 1 ? "" : "#" + val.size();
          sb.append("\n[F" + s + "] '" + val + "', " + types + details() + '\n');
          ++fail;
        }
      } catch (final Exception ex) {
        final String msg = ex.getMessage();
        if (correct || msg == null || msg.contains("mailman")) {
          final String cp = correct && cmp.data() != null ? cmp.toString() : "()";
          sb.append(
              "["
                  + qu[0]
                  + "] "
                  + query
                  + "\n[E] "
                  + cp
                  + "\n[F] "
                  + (msg == null ? Util.className(ex) : msg.replaceAll("\r\n?|\n", " "))
                  + ' '
                  + details()
                  + '\n');
          ex.printStackTrace();
          ++fail;
        }
      } finally {
        qp.close();
      }
    }
    if (fail != 0) fail(fail + " Errors. [E] = expected, [F] = found:\n" + sb.toString().trim());
  }
Esempio n. 15
0
 @Override
 public void execute(final GUI gui) {
   final StringBuilder sb = new StringBuilder();
   final Nodes n = gui.context.copied;
   for (int i = 0; i < n.size(); ++i) {
     if (i > 0) sb.append(',');
     sb.append(openPre(n, i));
   }
   gui.context.copied = null;
   gui.execute(new XQuery("insert nodes (" + sb + ") into " + openPre(gui.context.marked, 0)));
 }
Esempio n. 16
0
 /**
  * Parses and returns a glob expression, which extends {@link #name(Cmd)} function with asterisks,
  * question marks and commands.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return glob expression
  * @throws QueryException query exception
  */
 private String glob(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   while (true) {
     final char ch = parser.curr();
     if (!Databases.validChar(ch) && ch != '*' && ch != '?' && ch != ',') {
       return finish(eoc() || ws(ch) ? sb : null, cmd);
     }
     sb.append(parser.consume());
   }
 }
Esempio n. 17
0
 @Override
 protected boolean run() {
   final String query = find(args[0], context, root);
   final boolean ok = query(query);
   final StringBuilder sb = new StringBuilder();
   if (prop.is(Prop.QUERYINFO)) {
     sb.append(NL).append(QUERY_CC).append(NL).append(query).append(NL);
   }
   sb.append(info());
   error(sb.toString());
   return ok;
 }
Esempio n. 18
0
 /**
  * Parses and returns a string, delimited by a semicolon or, optionally, a space. Quotes can be
  * used to include spaces.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @param space stop when encountering space
  * @return string
  * @throws QueryException query exception
  */
 private String string(final Cmd cmd, final boolean space) throws QueryException {
   final StringBuilder sb = new StringBuilder();
   consumeWS();
   boolean q = false;
   while (parser.more()) {
     final char c = parser.curr();
     if (!q && ((space ? c <= ' ' : c < ' ') || eoc())) break;
     if (c == '"') q ^= true;
     else sb.append(c);
     parser.consume();
   }
   return finish(sb, cmd);
 }
Esempio n. 19
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   final int pl = post.length;
   for (int p = 0; p < pl; p++) {
     sb.append(LET).append(" (: post-group :) ").append(post[p]);
     sb.append(' ').append(ASSIGN).append(' ').append(preExpr[p]).append(' ');
   }
   sb.append(GROUP).append(' ').append(BY);
   final int sl = specs.length;
   for (int s = 0; s < sl; s++) sb.append(s == 0 ? " " : SEP).append(specs[s]);
   return sb.toString();
 }
Esempio n. 20
0
 @Override
 public void execute(final GUI gui) {
   if (!BaseXDialog.confirm(gui, DELETE_NODES)) return;
   final StringBuilder sb = new StringBuilder();
   final Nodes n = gui.context.marked;
   for (int i = 0; i < n.size(); ++i) {
     if (i > 0) sb.append(',');
     sb.append(openPre(n, i));
   }
   gui.context.marked = new Nodes(n.data);
   gui.context.copied = null;
   gui.context.focused = -1;
   gui.execute(new XQuery("delete nodes (" + sb + ')'));
 }
Esempio n. 21
0
 /**
  * Parses and returns the remaining string. Quotes at the beginning and end of the argument will
  * be stripped.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return remaining string
  * @throws QueryException query exception
  */
 private String remaining(final Cmd cmd) throws QueryException {
   if (single) {
     final StringBuilder sb = new StringBuilder();
     consumeWS();
     while (parser.more()) sb.append(parser.consume());
     String arg = finish(sb, cmd);
     if (arg != null) {
       // chop quotes; substrings are faster than replaces...
       if (arg.startsWith("\"")) arg = arg.substring(1);
       if (arg.endsWith("\"")) arg = arg.substring(0, arg.length() - 1);
     }
     return arg;
   }
   return string(cmd, false);
 }
Esempio n. 22
0
 /**
  * Parses and returns an xquery expression.
  *
  * @param cmd referring command; if specified, the result must not be empty
  * @return path
  * @throws QueryException query exception
  */
 private String xquery(final Cmd cmd) throws QueryException {
   consumeWS();
   final StringBuilder sb = new StringBuilder();
   if (!eoc()) {
     final QueryContext qc = new QueryContext(ctx);
     try {
       final QueryParser p = new QueryParser(parser.input, null, qc, null);
       p.pos = parser.pos;
       p.parseMain();
       sb.append(parser.input.substring(parser.pos, p.pos));
       parser.pos = p.pos;
     } finally {
       qc.close();
     }
   }
   return finish(sb, cmd);
 }
Esempio n. 23
0
 @Override
 StringBuilder toString(final StringBuilder sb, final String ind) {
   final int s = Integer.bitCount(used);
   for (int i = 0, j = 0; i < s; i++, j++) {
     while ((used & 1 << j) == 0) j++;
     final int e = i == s - 1 ? 2 : 0;
     sb.append(ind).append(ENDS[e]).append(String.format("%x", j)).append('\n');
     kids[j].toString(sb, ind + ENDS[e + 1]);
   }
   return sb;
 }
Esempio n. 24
0
 @Override
 public final String toString() {
   final StringBuilder sb = new StringBuilder();
   if (root != null) sb.append(root);
   for (final Expr s : steps) {
     if (sb.length() != 0) sb.append(s instanceof Bang ? " ! " : "/");
     if (s instanceof Step) sb.append(s);
     else sb.append(s);
   }
   return sb.toString();
 }
Esempio n. 25
0
  /**
   * Constructor.
   *
   * @param rq request
   * @param rs response
   * @param servlet calling servlet instance
   * @throws IOException I/O exception
   */
  public HTTPContext(
      final HttpServletRequest rq, final HttpServletResponse rs, final BaseXServlet servlet)
      throws IOException {

    req = rq;
    res = rs;
    params = new HTTPParams(this);

    method = rq.getMethod();

    final StringBuilder uri = new StringBuilder(req.getRequestURL());
    final String qs = req.getQueryString();
    if (qs != null) uri.append('?').append(qs);
    log('[' + method + "] " + uri, null);

    // set UTF8 as default encoding (can be overwritten)
    res.setCharacterEncoding(UTF8);
    segments = decode(toSegments(req.getPathInfo()));

    // adopt servlet-specific credentials or use global ones
    final GlobalOptions mprop = context().globalopts;
    user = servlet.user != null ? servlet.user : mprop.get(GlobalOptions.USER);
    pass = servlet.pass != null ? servlet.pass : mprop.get(GlobalOptions.PASSWORD);

    // overwrite credentials with session-specific data
    final String auth = req.getHeader(AUTHORIZATION);
    if (auth != null) {
      final String[] values = auth.split(" ");
      if (values[0].equals(BASIC)) {
        final String[] cred = org.basex.util.Base64.decode(values[1]).split(":", 2);
        if (cred.length != 2) throw new LoginException(NOPASSWD);
        user = cred[0];
        pass = cred[1];
      } else {
        throw new LoginException(WHICHAUTH, values[0]);
      }
    }
  }
Esempio n. 26
0
  /**
   * Splits the string and returns an array.
   *
   * @param str string to be split
   * @return array
   */
  private static String[] split(final String str) {
    final int l = str.length();
    final String[] split = new String[l];

    int s = 0;
    char delim = 0;
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < l; ++i) {
      final char c = str.charAt(i);
      if (delim == 0) {
        if (c == '\'' || c == '"') {
          delim = c;
        } else if (!XMLToken.isChar(c)
            && c != '@'
            && c != '='
            && c != '<'
            && c != '>'
            && c != '~') {
          if (sb.length() != 0) {
            split[s++] = sb.toString();
            sb.setLength(0);
          }
        } else {
          sb.append(c);
        }
      } else {
        if (c == delim) {
          delim = 0;
          if (sb.length() != 0) {
            split[s++] = sb.toString();
            sb.setLength(0);
          }
        } else {
          if (c != '\'' && c != '"') sb.append(c);
        }
      }
    }
    if (sb.length() != 0) split[s++] = sb.toString();
    return Array.copyOf(split, s);
  }
Esempio n. 27
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   final boolean str = query instanceof AStr;
   if (!str) sb.append("{ ");
   sb.append(query);
   if (!str) sb.append(" }");
   switch (mode) {
     case ALL:
       sb.append(' ' + ALL);
       break;
     case ALL_WORDS:
       sb.append(' ' + ALL + ' ' + WORDS);
       break;
     case ANY_WORD:
       sb.append(' ' + ANY + ' ' + WORD);
       break;
     case PHRASE:
       sb.append(' ' + PHRASE);
       break;
     default:
   }
   if (occ != null) sb.append(OCCURS + ' ' + occ[0] + ' ' + TO + ' ' + occ[1] + ' ' + TIMES);
   if (ftt != null) sb.append(ftt.opt);
   return sb.toString();
 }
Esempio n. 28
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   for (final Expr e : preds) sb.append('[').append(e).append(']');
   return sb.toString();
 }
Esempio n. 29
0
 @Override
 public String toString() {
   final StringBuilder sb = new StringBuilder();
   for (final UserFunc f : funcs) sb.append(f.toString());
   return sb.toString();
 }
Esempio n. 30
0
  /**
   * Returns whether the following token exists (using wildcards).
   *
   * @return result of check
   */
  private boolean moreWC() {
    final StringBuilder word = new StringBuilder();
    final int size = tokenList.size();
    boolean period = false, bs = false, more = false;

    for (; cpos < size; cpos++) {
      String cSrfc = tokenList.get(cpos).getSurface();
      final boolean cMark = tokenList.get(cpos).isMark();
      String nSrfc = null;
      boolean nMark = false;
      if (cpos < size - 1) {
        nSrfc = tokenList.get(cpos + 1).getSurface();
        nMark = tokenList.get(cpos + 1).isMark();
      }

      if (nSrfc != null) {
        if ("\\".equals(cSrfc)) bs = true;

        // delimiter
        if (cMark && !isFtChar(cSrfc) || "\\".equals(cSrfc) && nMark) {
          period = false;
          bs = false;
          if (word.length() != 0) {
            more = true;
            break;
          }
          if ("\\".equals(cSrfc) && nMark) cpos++;
          continue;
        }

        word.append(cSrfc);

        if (bs || "\\".equals(nSrfc)) {
          more = true;
          continue;
        }

        if (".".equals(cSrfc) || ".".equals(nSrfc)) {
          period = true;
          continue;
        }
        if (period) {
          if ("{".equals(cSrfc)) {
            cpos++;
            for (; cpos < size; cpos++) {
              cSrfc = tokenList.get(cpos).getSurface();
              word.append(cSrfc);
              if ("}".equals(cSrfc)) {
                more = true;
                break;
              }
            }
            cpos++;
            break;
          }
          continue;
        }
      } else {
        // last token.
        if (cMark) {
          if ("\\".equals(cSrfc)) continue;
          if (word.length() != 0) {
            word.append(cSrfc);
          }
          more = true;
          continue;
        }
      }

      if (period) {
        word.append(cSrfc);
      } else {
        if (bs)
          if (!isFtChar(cSrfc)) word.append(cSrfc);
          else word.setLength(0);
      }
      more = true;
      cpos++;
      break;
    }
    if (more) {
      currToken =
          word.length() == 0
              ? tokenList.get(cpos - 1)
              : new Morpheme(word.toString(), MEISHI_FEATURE);
    }
    return more;
  }