01: /* Names.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Tue Aug 2 15:03:50 2005, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zk.ui.sys;
20:
21: import java.util.Set;
22: import java.util.HashSet;
23: import java.util.Collections;
24:
25: /**
26: * Utilities about variable's names.
27: *
28: * @author tomyeh
29: */
30: public class Names {
31: private Names() {
32: }
33:
34: private static final Set _reves;
35: static {
36: Set reves = new HashSet();
37: final String[] rs = new String[] { "arg", "desktop", "event",
38: "page", "self", "session", "spaceOwner" };
39: for (int j = rs.length; --j >= 0;)
40: reves.add(rs[j]);
41: _reves = Collections.unmodifiableSet(reves);
42: }
43:
44: /** Returns a set of readonly reserved words.
45: */
46: public static final Set getReservedNames() {
47: return _reves;
48: }
49:
50: /** Returns whether the specified is valid.
51: * It also invokes {@link #isReserved}.
52: */
53: public static final boolean isValid(String name) {
54: if (ComponentsCtrl.isAutoId(name) || isReserved(name))
55: return false;
56:
57: for (int j = name.length(); --j >= 0;) {
58: final char cc = name.charAt(j);
59: if ((cc < '0' || cc > '9') && (cc < 'a' || cc > 'z')
60: && (cc < 'A' || cc > 'Z') && cc != '_')
61: return false;
62: }
63: return true;
64: }
65:
66: /** Returns whether the specified name is reserved.
67: * If true, you cannot use it in zscript (and EL).
68: */
69: public static final boolean isReserved(String name) {
70: return _reves.contains(name);
71: }
72: }
|