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