KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > dlog4j > util > HtmlUtil


1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * 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 JavaDoc makeHtml(String JavaDoc content, boolean useFaces, boolean useUbb){
34         if(useFaces){
35         }
36         if(useUbb){
37             
38         }
39         return convertToHtml(content);
40     }
41     
42     public static String JavaDoc convertToHtml(String JavaDoc content){
43         content = StringUtils.replace(content,"\t","    ");//替换跳格
44
content = StringUtils.replace(content," "," ");//替换空格
45
content = StringUtils.replace(content,"\n","<br>");//替换换行
46
return content;
47     }
48
49     public static void main(String JavaDoc[] args) {
50         
51         System.out.println(convertToHtml("测 试 空 格"));
52         
53     }
54 }
55
Popular Tags