private void compareDecodes(String orig) {
   String htmlparserDecoded = Translate.decode(orig);
   String apacheDecoded = StringEscapeUtils.unescapeHtml(orig);
   System.out.format("ORIGINAL:(%s)\n", orig);
   System.out.format("htmlparser:(%s)\n", htmlparserDecoded);
   System.out.format("apache:(%s)\n", apacheDecoded);
 }
Exemple #2
0
  /**
   * Format the given string to appear "as is" within a JavaDoc comment. This method is more
   * complicated than it needs to be, since you might say why not just use PRE tags surrounding the
   * text. Unfortunately, PRE is a block level tag that breaks the flow of text, preventing inline
   * operation. Instead we manually format the whitespace (actually just spaces and newlines) within
   * the string to preserve the format.
   */
  protected String format(String s) {
    int base;
    int offset;
    StringBuffer ret;

    ret = new StringBuffer(512);

    base = 0;
    offset = 0;
    while (-1 != (offset = s.indexOf('\n', base))) {
      ret.append(Translate.encode(s.substring(base, offset)));
      ret.append("<br>\n");
      base = offset + 1;
    }
    if (base != s.length()) ret.append(Translate.encode(s.substring(base)));

    s = ret.toString();
    ret.setLength(0);
    for (int i = 0; i < s.length(); i++)
      if (' ' == s.charAt(i)) ret.append("&nbsp;");
      else ret.append(s.charAt(i));

    return (ret.toString());
  }