1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.caleigo.core;
19
20 import org.caleigo.security.*;
21
22 /***
23 * @author Klas Ehnrot
24 *
25 * Dynamically adds the user properties to
26 */
27 public class UserProxyData implements IProxyData
28 {
29
30 private String propertyName;
31
32 /***
33 * Parses the incoming value and converts it into a UserProxyData.
34 * Expecting a string formatted as :
35 * #USER.propertyName where #USER. is the static directive and
36 * propertyName is the name of the property to lookup in UserConfig.
37 *
38 * @param value the data
39 * @return UserProxyData
40 */
41 public static UserProxyData parse(String value)
42 {
43 if (value.startsWith("#USER.") && value.indexOf('#', 1) != -1)
44 {
45 String propertyName =
46 value.substring(6, value.indexOf('#', 1)).trim();
47
48
49
50
51
52 return new UserProxyData(propertyName);
53
54 }
55
56 return null;
57 }
58
59 /***
60 * Used to convert an object to a Date Object, either the java.util.Date object or
61 * a DateProxyData object.
62 *
63 * @param data The data representing a Date
64 * @return Object The created data object
65 */
66 public static Object convertToStringObject(Object data)
67 {
68
69 if (data instanceof UserProxyData)
70 return data;
71 else if (data != null)
72 {
73 data = data.toString();
74 UserProxyData userProxyData = UserProxyData.parse((String) data);
75 if (userProxyData != null)
76 {
77 return userProxyData;
78 }
79 return data;
80 }
81 else
82 return null;
83 }
84
85 public UserProxyData(String propertyName)
86 {
87 this.propertyName = propertyName;
88 }
89
90 /***
91 * Implementation of the IProxy interface getData
92 * Goes through UserInfo and lookups the propertyName
93 *
94 * @see org.caleigo.core.IProxyData#getData()
95 */
96 public Object getData()
97 {
98
99
100 UserInfo userInfo = null;
101 try
102 {
103 userInfo = UserInfo.getCurrentUserInfo();
104
105 }
106 catch (LoginCanceledException e)
107 {
108 return "#USER." + propertyName + "#";
109 }
110 catch (IllegalStateException e)
111 {
112 return "#USER." + propertyName + "#";
113 }
114
115
116 if (propertyName.toLowerCase().equals("userid"))
117 {
118 return userInfo.getUserID();
119 }
120
121
122 Object data = userInfo.getProperty(this.propertyName);
123 if (data != null)
124 {
125 return data.toString();
126 }
127
128
129
130 data = userInfo.getProperty("entity");
131 if (data != null)
132 {
133 IEntity entity = (IEntity) data;
134 data = entity.getData(this.propertyName);
135 if (data != null)
136 return data.toString();
137 }
138
139 return "#USER." + propertyName + "#";
140 }
141
142 /***
143 * Implementation of the IProxy Interface getDataType
144 *
145 * @return Returns a DataType.STRING
146 * @see org.caleigo.core.IProxyData#getDataType()
147 */
148 public DataType getDataType()
149 {
150 return DataType.STRING;
151 }
152
153 }