01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.wireless.encode;
06:
07: import com.sun.portal.desktop.encode.*;
08:
09: public class WMLEncoder implements TypeEncoder {
10:
11: private static final String msEuroString = new String("\u0080");
12: private static final char msEuroChar = msEuroString.charAt(0);
13:
14: /**
15: * escapes wml-reserved characters
16: */
17: public String encode(String text) {
18:
19: StringBuffer escaped = new StringBuffer();
20: //
21: // XXX(susu): this portion of the code has been borrowed from
22: // JAXP 1.1 source
23: //
24: for (int i = 0; i < text.length(); i++) {
25: char c = text.charAt(i);
26: if (c == msEuroChar) {
27: escaped.append("€");
28: } else {
29:
30: switch (c) {
31: // XXX only a few of these are necessary; we
32: // do what "Canonical XML" expects
33: case '<':
34: escaped.append("<");
35: continue;
36: case '>':
37: escaped.append(">");
38: continue;
39: case '&':
40: escaped.append("&");
41: continue;
42: case '\'':
43: escaped.append("'");
44: continue;
45: case '"':
46: escaped.append(""");
47: continue;
48: case '$':
49: escaped.append("$$");
50: continue;
51: default:
52: escaped.append(c);
53: continue;
54: }
55: }
56: }
57: return escaped.toString();
58: }
59: }
|