KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > applications > webtalk > controller > Utilities


1 /*
2  * Utilities.java
3  *
4  * Created on September 14, 2003, 1:12 PM
5  */

6
7 package com.quikj.application.communicator.applications.webtalk.controller;
8
9 /**
10  *
11  * @author bhm
12  */

13 public class Utilities
14 {
15     /* Common utility functions needed by multiple classes */
16     
17     private static String JavaDoc ESCAPE_EQUAL = "&eq;";
18     private static String JavaDoc ESCAPE_ESCAPE = "&";
19     
20     public static String JavaDoc escapeEqual(String JavaDoc input)
21     {
22         // Replace = with &eq
23
// Replace & with &amp
24

25         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(input);
26         
27         int index = 0;
28         while (index < buf.length())
29         {
30             int replace_at = buf.toString().indexOf('&', index);
31             
32             if (replace_at == -1)
33             {
34                 break;
35             }
36             
37             buf = buf.replace(replace_at, replace_at + 1, ESCAPE_ESCAPE);
38             
39             index = replace_at + ESCAPE_ESCAPE.length();
40         }
41         
42         index = 0;
43         while (index < buf.length())
44         {
45             int replace_at = buf.toString().indexOf('=', index);
46             
47             if (replace_at == -1)
48             {
49                 break;
50             }
51             
52             buf = buf.replace(replace_at, replace_at + 1, ESCAPE_EQUAL);
53             
54             index = replace_at + ESCAPE_EQUAL.length();
55         }
56         
57         return buf.toString();
58     }
59     
60     public static String JavaDoc deEscapeEqual(String JavaDoc input)
61     {
62         // Replace &eq with =
63
// Replace &amp with &
64

65         StringBuffer JavaDoc buf = new StringBuffer JavaDoc(input);
66         
67         int index = 0;
68         while (index < buf.length())
69         {
70             int replace_at = buf.toString().indexOf(ESCAPE_EQUAL, index);
71             
72             if (replace_at == -1)
73             {
74                 break;
75             }
76             
77             buf = buf.replace(replace_at, replace_at + ESCAPE_EQUAL.length(),
78             "=");
79             
80             index = replace_at + 1;
81         }
82         
83         index = 0;
84         while (index < buf.length())
85         {
86             int replace_at = buf.toString().indexOf(ESCAPE_ESCAPE, index);
87             
88             if (replace_at == -1)
89             {
90                 break;
91             }
92             
93             buf = buf.replace(replace_at, replace_at + ESCAPE_ESCAPE.length(),
94             "&");
95             
96             index = replace_at + 1;
97         }
98         
99         return buf.toString();
100     }
101     
102
103     
104 }
105
Popular Tags