public static SafeHtml withLineBreaks(final String string) {
        if (string == null) {
            return SafeHtmlUtils.fromString("");
        } else {
            String str = string;
            while (str.startsWith("\n")) {
                str = str.substring(1);
            }
            while (str.endsWith("\n")) {
                str = str.substring(0, str.length() - 1);
            }
            // One ...<br> tag at the end of each line
            final SafeHtmlBuilder builder = new SafeHtmlBuilder();
            int lineBreakIdx;
            int lineNo = 1;
            while (!str.isEmpty()) {
                lineBreakIdx = str.indexOf("\n");
                final String line;
                if (lineBreakIdx == -1) {
                    line = str;
                    str = "";
                } else {
                    line = str.substring(0, lineBreakIdx);
                    if (str.length() > lineBreakIdx + 1) {
                        // Remove the line just appended
                        str = str.substring(lineBreakIdx + 1);
                    } else {
                        str = "";
                    }
                }

                if (lineNo++ != 1) {
                    builder.appendHtmlConstant("<br>");
                }
                if (!line.isEmpty()) {
                    builder.appendEscaped(line);
                }
            }
            return builder.toSafeHtml();
        }
    }
Replaces \n with &lt;br&gt;
Any reserved chars in string will be escaped.
Will always return a {@link SafeHtml} object.
stroom-core-client-widget/src/main/java/stroom/widget/util/client/SafeHtmlUtil.java