1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.r2.common.util;
18
19 import org.kuali.student.r2.common.dto.RichTextInfo;
20
21
22
23
24
25 public class RichTextHelper {
26
27 public static RichTextInfo buildRichTextInfo(String plain, String formatted) {
28 if (plain == null) {
29 return null;
30 }
31 RichTextInfo info = new RichTextInfo();
32 info.setFormatted(formatted);
33 info.setPlain(plain);
34 return info;
35 }
36
37 public RichTextInfo toRichTextInfo(String plain, String formatted) {
38 if (plain == null) {
39 return null;
40 }
41 RichTextInfo info = new RichTextInfo();
42 info.setFormatted(formatted);
43 info.setPlain(plain);
44 return info;
45 }
46
47 public RichTextInfo fromFormatted(String plain) {
48 return toRichTextInfo(plain, formatted2Plain(plain));
49 }
50
51 public RichTextInfo fromPlain(String plain) {
52 return toRichTextInfo(plain, plain2Formatted(plain));
53 }
54
55 public String formatted2Plain(String forematted) {
56 if (forematted == null) {
57 return null;
58 }
59
60 return forematted.replaceAll("<br>", "\n");
61 }
62
63 public String plain2Formatted(String plain) {
64 if (plain == null) {
65 return null;
66 }
67
68 return plain.replaceAll("\n", "<br>");
69 }
70 }