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 FormNameEncoder implements TypeEncoder {
08:
09: /** The html object names have to be unique within a document. An
10: * example where a problem will arise if the above condition is not
11: * met is, if you have two bookmark channels in the users desktop,
12: * and if the templates come from the provider directory
13: * ( i.e. BookmarkProvider) then the html form name is same for both
14: * the channels and opening a new url by typing in to the channel's
15: * text field will fail because the javascript target name is ambiguous.
16: * To avoid this, the html form is named after the channel name.
17: * HTML special characters in the channel name is encoded using this
18: * static method.
19: **/
20:
21: public String encode(String text) {
22:
23: StringBuffer escaped = new StringBuffer();
24: for (int i = 0; i < text.length(); i++) {
25: char c = text.charAt(i);
26: switch (c) {
27: case '!':
28: case '#':
29: case '%':
30: case '\'':
31: case ')':
32: case '+':
33: case '-':
34: case '/':
35: case ';':
36: case '=':
37: case '?':
38: case '\\':
39: case '^':
40: case '`':
41: case '|':
42: case '~':
43: case '"':
44: case '$':
45: case '&':
46: case '(':
47: case '*':
48: case ',':
49: case '.':
50: case ':':
51: case '<':
52: case '>':
53: case '@':
54: case '[':
55: case ']':
56: case '{':
57: case '}':
58: case ' ':
59: escaped.append("_");
60: continue;
61: default:
62: escaped.append(c);
63: continue;
64: }
65: }
66: return escaped.toString();
67: }
68: }
|