KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > util > FilterUtils


1 package fr.improve.struts.taglib.layout.util;
2
3 /**
4  * Filter characters.
5  */

6 public class FilterUtils {
7     /**
8      * Filter simple and double quotes.
9      * Suppose the Javascript string is delimited by simple quotes.
10      */

11     public static String JavaDoc filterQuotes(String JavaDoc in_string) {
12         StringBuffer JavaDoc result = new StringBuffer JavaDoc(in_string);
13         for (int i=0; i < result.length(); i++) {
14             switch (result.charAt(i)) {
15                 case '\'':
16                     // just add an antislash to escpae the quote.
17
result.insert(i, '\\');
18                     i++;
19                     break;
20                 case '\"':
21                     // need to convert the double quote to ascii.
22
result.replace(i, i+1, "' + String.fromCharCode(34) + '");
23                     i+=30;
24                     break;
25             }
26         }
27         return result.toString();
28     }
29 }
30
Popular Tags