1:
16: package ;
17: import ;
18:
28: public class MailtoLinkEncoder {
29:
35: public static String encode(String eMailAdress) throws Exception {
36: StringBuffer encoded = new StringBuffer();
37: char[] array = eMailAdress.toCharArray();
38: Random r = new Random();
39: int encoding;
40: String dec = new String();
41: String hex = new String();
42: for(int i=0;i<array.length;++i) {
43: encoding = r.nextInt(3);
44: if(array[i]== '-')
45: {
46: dec="-";
47: hex="-";
48: }
49: else if(array[i]== '.')
50: {
51: dec=".";
52: hex=".";
53: } else if(array[i]== '0')
54: {
55: dec="0";
56: hex="0";
57: } else if(array[i]== '1')
58: {
59: dec="1";
60: hex="1";
61: } else if(array[i]== '2')
62: {
63: dec="2";
64: hex="2";
65: } else if(array[i]== '3')
66: {
67: dec="3";
68: hex="3";
69: } else if(array[i]== '4')
70: {
71: dec="4";
72: hex="4";
73: } else if(array[i]== '5')
74: {
75: dec="5";
76: hex="5";
77: } else if(array[i]== '6')
78: {
79: dec="6";
80: hex="6";
81: } else if(array[i]== '7')
82: {
83: dec="7";
84: hex="7";
85: } else if(array[i]== '8')
86: {
87: dec="8";
88: hex="8";
89: } else if(array[i]== '9')
90: {
91: dec="9";
92: hex="9";
93: } else if(array[i]== '@')
94: {
95: dec="@";
96: hex="@";
97: } else if(array[i]== 'A')
98: {
99: dec="A";
100: hex="A";
101: } else if(array[i]== 'B')
102: {
103: dec="B";
104: hex="B";
105: } else if(array[i]== 'C')
106: {
107: dec="C";
108: hex="C";
109: } else if(array[i]== 'D')
110: {
111: dec="D";
112: hex="D";
113: } else if(array[i]== 'E')
114: {
115: dec="E";
116: hex="E";
117: } else if(array[i]== 'F')
118: {
119: dec="F";
120: hex="F";
121: } else if(array[i]== 'G')
122: {
123: dec="G";
124: hex="G";
125: } else if(array[i]== 'H')
126: {
127: dec="H";
128: hex="H";
129: } else if(array[i]== 'C')
130: {
131: dec="C";
132: hex="C";
133: } else if(array[i]== 'I')
134: {
135: dec="I";
136: hex="I";
137: } else if(array[i]== 'J')
138: {
139: dec="J";
140: hex="J";
141: } else if(array[i]== 'K')
142: {
143: dec="K";
144: hex="K";
145: } else if(array[i]== 'L')
146: {
147: dec="L";
148: hex="L";
149: } else if(array[i]== 'M')
150: {
151: dec="M";
152: hex="M";
153: } else if(array[i]== 'N')
154: {
155: dec="N";
156: hex="N";
157: } else if(array[i]== 'O')
158: {
159: dec="O";
160: hex="O";
161: } else if(array[i]== 'P')
162: {
163: dec="P";
164: hex="P";
165: } else if(array[i]== 'Q')
166: {
167: dec="Q";
168: hex="Q";
169: } else if(array[i]== 'R')
170: {
171: dec="R";
172: hex="R";
173: } else if(array[i]== 'S')
174: {
175: dec="S";
176: hex="S";
177: } else if(array[i]== 'T')
178: {
179: dec="T";
180: hex="T";
181: } else if(array[i]== 'U')
182: {
183: dec="U";
184: hex="U";
185: } else if(array[i]== 'V')
186: {
187: dec="V";
188: hex="V";
189: } else if(array[i]== 'W')
190: {
191: dec="W";
192: hex="W";
193: } else if(array[i]== 'X')
194: {
195: dec="X";
196: hex="X";
197: } else if(array[i]== 'Y')
198: {
199: dec="Y";
200: hex="Y";
201: } else if(array[i]== 'Z')
202: {
203: dec="Z";
204: hex="Z";
205: } else if(array[i]== '_')
206: {
207: dec="_";
208: hex="_";
209: } else if(array[i]== 'a')
210: {
211: dec="a";
212: hex="a";
213: } else if(array[i]== 'b')
214: {
215: dec="b";
216: hex="b";
217: } else if(array[i]== 'c')
218: {
219: dec="c";
220: hex="c";
221: } else if(array[i]== 'd')
222: {
223: dec="d";
224: hex="d";
225: } else if(array[i]== 'e')
226: {
227: dec="e";
228: hex="e";
229: } else if(array[i]== 'f')
230: {
231: dec="f";
232: hex="f";
233: } else if(array[i]== 'g')
234: {
235: dec="g";
236: hex="g";
237: } else if(array[i]== 'h')
238: {
239: dec="h";
240: hex="h";
241: } else if(array[i]== 'i')
242: {
243: dec="i";
244: hex="i";
245: } else if(array[i]== 'j')
246: {
247: dec="j";
248: hex="j";
249: } else if(array[i]== 'k')
250: {
251: dec="k";
252: hex="k";
253: } else if(array[i]== 'l')
254: {
255: dec="l";
256: hex="l";
257: } else if(array[i]== 'm')
258: {
259: dec="m";
260: hex="m";
261: } else if(array[i]== 'n')
262: {
263: dec="n";
264: hex="n";
265: } else if(array[i]== 'o')
266: {
267: dec="o";
268: hex="o";
269: } else if(array[i]== 'p')
270: {
271: dec="p";
272: hex="p";
273: } else if(array[i]== 'q')
274: {
275: dec="q";
276: hex="q";
277: } else if(array[i]== 'r')
278: {
279: dec="r";
280: hex="r";
281: } else if(array[i]== 's')
282: {
283: dec="s";
284: hex="s";
285: } else if(array[i]== 't')
286: {
287: dec="t";
288: hex="t";
289: } else if(array[i]== 'u')
290: {
291: dec="u";
292: hex="u";
293: } else if(array[i]== 'v')
294: {
295: dec="v";
296: hex="v";
297: } else if(array[i]== 'w')
298: {
299: dec="w";
300: hex="w";
301: } else if(array[i]== 'x')
302: {
303: dec="x";
304: hex="x";
305: } else if(array[i]== 'y')
306: {
307: dec="y";
308: hex="y";
309: } else if(array[i]== 'z')
310: {
311: dec="z";
312: hex="z";
313: } else {
314: throw new Exception("This is no valid E-Mail address!");
315: }
316:
317: if(encoding==0) {
318: encoded.append(dec);
319: } else if(encoding==1) {
320: encoded.append(hex);
321: } else {
322: encoded.append(array[i]);
323: }
324: }
325: return new String(encoded);
326: }
327: }