KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > commons > utils > HtmlUtil


1 /**
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

5 package org.exoplatform.commons.utils;
6
7 /**
8  * Created by The eXo Platform SARL .
9  * Author : Tuan Nguyen
10  * tuan08@users.sourceforge.net
11  * Date: July 4, 2003
12  * Time: 9:10:02 PM
13  **/

14 public class HtmlUtil {
15
16   static public String JavaDoc showXmlTags(String JavaDoc s) {
17     char[] buf = s.toCharArray() ;
18     StringBuffer JavaDoc b = new StringBuffer JavaDoc() ;
19     for (int i = 0; i < buf.length; i++) {
20       if(buf[i] == '<') {
21         b.append("&lt;") ;
22       } else if (buf[i] == '>') {
23         b.append("&gt;") ;
24       } else {
25         b.append(buf[i]) ;
26       }
27     }
28     return b.toString() ;
29   }
30   
31   static public String JavaDoc convertNewLineToBR(String JavaDoc s) {
32     if(s == null) return "" ;
33     char[] buf = s.toCharArray() ;
34     StringBuffer JavaDoc b = new StringBuffer JavaDoc() ;
35     for (int i = 0; i < buf.length; i++) {
36       if(buf[i] == '\n') {
37         b.append("<br/>") ;
38       } else {
39         b.append(buf[i]) ;
40       }
41     }
42     return b.toString() ;
43   }
44 }
Popular Tags