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.desktop.encode;
06:
07: class HTMLEncoder implements TypeEncoder {
08: public String encode(String text) {
09:
10: StringBuffer escaped = new StringBuffer();
11: //
12: // XXX(susu): this portion of the code has been borrowed from
13: // JAXP 1.1 source
14: //
15: for (int i = 0; i < text.length(); i++) {
16: char c = text.charAt(i);
17: switch (c) {
18: // XXX only a few of these are necessary; we
19: // do what "Canonical XML" expects
20: case '<':
21: escaped.append("<");
22: continue;
23: case '>':
24: escaped.append(">");
25: continue;
26: case '&':
27: escaped.append("&");
28: continue;
29: case '"':
30: escaped.append(""");
31: continue;
32: default:
33: escaped.append(c);
34: continue;
35: }
36: }
37: return escaped.toString();
38: }
39: }
|