01: /***************************************************************
02: * This file is part of the [fleXive](R) project.
03: *
04: * Copyright (c) 1999-2007
05: * UCS - unique computing solutions gmbh (http://www.ucs.at)
06: * All rights reserved
07: *
08: * The [fleXive](R) project is free software; you can redistribute
09: * it and/or modify it under the terms of the GNU General Public
10: * License as published by the Free Software Foundation;
11: * either version 2 of the License, or (at your option) any
12: * later version.
13: *
14: * The GNU General Public License can be found at
15: * http://www.gnu.org/copyleft/gpl.html.
16: * A copy is found in the textfile GPL.txt and important notices to the
17: * license from the author are found in LICENSE.txt distributed with
18: * these libraries.
19: *
20: * This library is distributed in the hope that it will be useful,
21: * but WITHOUT ANY WARRANTY; without even the implied warranty of
22: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23: * GNU General Public License for more details.
24: *
25: * For further information about UCS - unique computing solutions gmbh,
26: * please see the company website: http://www.ucs.at
27: *
28: * For further information about [fleXive](R), please see the
29: * project website: http://www.flexive.org
30: *
31: *
32: * This copyright notice MUST APPEAR in all copies of the file!
33: ***************************************************************/package com.flexive.war.beans.admin.content;
34:
35: import com.flexive.faces.messages.FxFacesMsgErr;
36: import com.flexive.faces.FxJsfUtils;
37: import com.flexive.shared.content.FxData;
38:
39: import java.util.Hashtable;
40:
41: /**
42: * Helper class for the ContentEditor.
43: * <p/>
44: * It generates a unique id for a xpath that gets accepted by jsf components.
45: *
46: * @author Gregor Schober (gregor.schober@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
47: */
48: public class CeIdGenerator extends Hashtable<String, Object> {
49:
50: /**
51: * Constructor.
52: */
53: protected CeIdGenerator() {
54: super (0);
55: }
56:
57: /**
58: * Fake put - does nothing expect returning the id for the given object.
59: *
60: * @param object the object
61: * @param ignore this parameter is discarded
62: * @return the description of the assignment id, or null if the assignment id could not be resolved
63: */
64: public String put(Object object, String ignore) {
65: // Do not put anything
66: return get(object);
67: }
68:
69: /**
70: * Returns the id of the object, which is generated from its XPath.
71: *
72: * @param object the object
73: * @return the description, or null if the assignment id could not be resolved
74: */
75: public String get(Object object) {
76: // Id String may only contain [a-z]|[A-Z]|'-'|'_' to be accepted by jsf components
77: try {
78: if (object instanceof FxData) {
79: String result = ((FxData) object).getXPathFull();
80: return FxJsfUtils.encodeJSFIdentifier(result);
81: }
82: return null;
83: } catch (Throwable t) {
84: new FxFacesMsgErr(t).addToContext();
85: return null;
86: }
87: }
88:
89: /**
90: * Decodes the id of an object.
91: *
92: * @param id the encoded id
93: * @return the decoded id
94: */
95: public static String decodeToXPath(String id) {
96: return FxJsfUtils.decodeJSFIdentifier(id);
97: }
98:
99: }
|