KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > xtags > util > StringHelper


1 /*
2  * Copyright 1999,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.taglibs.xtags.util;
18
19 import org.dom4j.Attribute;
20 import org.dom4j.Element;
21 import org.dom4j.io.SAXReader;
22
23 /** A Helper class of useful String methods.
24   *
25   * @author James Strachan
26   */

27 public class StringHelper {
28
29     /** Encodes the given XML / HTML so that it will appear in a HTML browser.
30       * so the "<" character is replaced with "&lt;" etc.
31       */

32     public static String JavaDoc encodeHTML(String JavaDoc input) {
33         int size = input.length();
34         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(size);
35         for (int i = 0; i < size; i++ ) {
36             char c = input.charAt(i);
37             switch (c) {
38                 case '<':
39                     buffer.append("&lt;");
40                     break;
41                 case '>':
42                     buffer.append("&gt;");
43                     break;
44                 case '"':
45                     buffer.append("&quot;");
46                     break;
47                 default:
48                     buffer.append(c);
49             }
50         }
51         return buffer.toString();
52     }
53 }
54
Popular Tags