コード例 #1
0
  protected String trimLine(String line, boolean allowLeadingSpaces) {
    if (line.trim().length() == 0) {
      return StringPool.BLANK;
    }

    line = StringUtil.trimTrailing(line);

    if (allowLeadingSpaces || !line.startsWith(StringPool.SPACE) || line.startsWith(" *")) {

      return line;
    }

    if (!line.startsWith(StringPool.FOUR_SPACES)) {
      while (line.startsWith(StringPool.SPACE)) {
        line = StringUtil.replaceFirst(line, StringPool.SPACE, StringPool.BLANK);
      }
    } else {
      int pos = 0;

      String temp = line;

      while (temp.startsWith(StringPool.FOUR_SPACES)) {
        line = StringUtil.replaceFirst(line, StringPool.FOUR_SPACES, StringPool.TAB);

        pos++;

        temp = line.substring(pos);
      }
    }

    return line;
  }
コード例 #2
0
  protected String stripIds(String content) {
    int index = content.indexOf("[](id=");

    if (index == -1) {
      return content;
    }

    StringBundler sb = new StringBundler();

    do {
      int x = content.indexOf(StringPool.EQUAL, index);
      int y = content.indexOf(StringPool.CLOSE_PARENTHESIS, x);

      if (y != -1) {
        sb.append(StringUtil.trimTrailing(content.substring(0, index)));

        content = content.substring(y + 1);
      } else {
        if (_log.isWarnEnabled()) {
          String msg = content.substring(index);

          // Get the invalid id text from the content

          int spaceIndex = content.indexOf(StringPool.SPACE);

          if (spaceIndex != -1) {
            msg = content.substring(index, spaceIndex);
          }

          _log.warn("Missing ')' for web content containing header id " + msg);
        }

        // Since no close parenthesis remains in the content, stop
        // stripping out IDs and simply include all of the remaining
        // content

        break;
      }
    } while ((index = content.indexOf("[](id=")) != -1);

    sb.append(content);

    return sb.toString();
  }