01: /*
02: * This program is free software; you can redistribute it and/or modify
03: * it under the terms of the GNU General Public License as published by
04: * the Free Software Foundation; either version 2 of the License, or
05: * (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: * GNU Library General Public License for more details.
11: *
12: * You should have received a copy of the GNU General Public License
13: * along with this program; if not, write to the Free Software
14: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15: */
16: package dlog4j.util;
17:
18: import org.apache.commons.lang.StringUtils;
19:
20: /**
21: * @author Liudong
22: * 用于格式化日志内容以及评论内容的工具类
23: */
24: public class HtmlUtil {
25:
26: /**
27: * 转换日志或者评论内容成适合页面显示
28: * @param content
29: * @param useFaces
30: * @param useUbb
31: * @return
32: */
33: public static String makeHtml(String content, boolean useFaces,
34: boolean useUbb) {
35: if (useFaces) {
36: }
37: if (useUbb) {
38:
39: }
40: return convertToHtml(content);
41: }
42:
43: public static String convertToHtml(String content) {
44: content = StringUtils.replace(content, "\t",
45: " ");//替换跳格
46: content = StringUtils.replace(content, " ", " ");//替换空格
47: content = StringUtils.replace(content, "\n", "<br>");//替换换行
48: return content;
49: }
50:
51: public static void main(String[] args) {
52:
53: System.out.println(convertToHtml("测 试 空 格"));
54:
55: }
56: }
|