Newer
Older
/**
* OLAT - Online Learning and Training<br>
* http://www.olat.org
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Copyright (c) since 2004 at Multimedia- & E-Learning Services (MELS),<br>
* University of Zurich, Switzerland.
* <hr>
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* This file has been modified by the OpenOLAT community. Changes are licensed
* under the Apache 2.0 license as the original file.
*/
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package org.olat.user;
import java.util.Hashtable;
import java.util.Map;
import org.olat.core.id.OLATResourceable;
import org.olat.core.id.UserConstants;
import org.olat.core.logging.AssertException;
/**
* Description: <br>
* The HomePageConfig class represents a configuration for a Homepage. It is
* persisted as an xml file in the ???. Loading and saving of
* configuration files is managed through the HomePageConfigManagerImpl.
* <p>
* A HomePageConfig has a class wide <code>CURRENTVERSION</code>, an integer
* denoting the most actual code version of the HomePageConfig. The attribute
* <code>version</code> is the version number of an instance.
* <p>
* <b><code>CURRENTVERSION vs. version</code> </b>
* <ul>
* <li><code>version == CURRENTVERSION</code><br>
* an up to date HomePageConfig</li>
* <li><code>version < CURRENTVERSION</code><br>
* demands for resolving version differences, as the loaded HomePageConfig may
* contain outdated configuration information</li>
* </ul>
* <P>
*
* Initial Date: July 15, 2005 <br>
* @author Alexander Schneider
*/
public class HomePageConfig implements OLATResourceable{
transient private final static int CURRENTVERSION = 4;
transient private final static String RESOURCEABLETYPENAME = "HOMEPAGECONFIG";
transient public final static String KEY_RESOURCEABLEID = "RESOURCEABLEID";
transient public final static String KEY_USERNAME = "USERNAME";
transient public static final String KEY_TEXTABOUTME = "TEXTABOUTME";
// use the user property names defined in UserConstants instead!
@Deprecated
transient public final static String KEY_EMAIL = "EMAIL";
@Deprecated
transient public final static String KEY_GENDER = "GENDER";
@Deprecated
transient public final static String KEY_BIRTHDAY = "BIRTHDAY";
@Deprecated
transient public final static String KEY_TELMOBILE = "TELMOBILE";
@Deprecated
transient public static final String KEY_TELPRIVATE = "TELPRIVATE";
@Deprecated
transient public static final String KEY_TELOFFICE = "TELOFFICE";
@Deprecated
transient public static final String KEY_ADDRESS = "ADDRESS";
@Deprecated
transient public static final String KEY_INSTITIUTIONALNAME = "INSTITUTIONALNAME";
@Deprecated
transient public static final String KEY_INSTITUTIONEMAIL = "INSTITUTIONEMAIL";
/**
* config file version from file
*/
private int version = -1;
/**
* holds the configuration
*/
private Map<String,Object> configuration = new Hashtable<>();
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
public HomePageConfig() {
// empty, for XSTream
}
/**
* @return version of this loaded/created instance
*/
public int getVersion() {
return version;
}
/**
* initialize with default values
*/
public void initDefaults() {
// version 1
// removed, see version 4 comment
// version 2
configuration.put(KEY_USERNAME, "");
// version 3
configuration.put(KEY_RESOURCEABLEID, "");
// version 4
// no default values for flags, they are set in the user preferences
// configuration. See olat_userconfig.xml in the spring config dir
this.version = CURRENTVERSION;
}
/**
* resolve issues of changed configuration version. Such as:
* <ul>
* <li>add new default values <br>
* <b>>>add the them </b></li>
* <li>no longer exisiting key value pairs <br>
* <b>>>remove from configuration </b></li>
* <li>changing of value meanings/types <br>
* <b>>>convert the existing entries </b></li>
* </ul>
*/
public void resolveVersionIssues() {
if (version < CURRENTVERSION) {
// from version 1 -> 2
if (version == 1) {
configuration.put(KEY_USERNAME, "");
this.version = 2;
}
if (version == 2){
configuration.put(KEY_RESOURCEABLEID, "");
this.version = 3;
}
if (version == 3){
configuration.put(KEY_RESOURCEABLEID, "");
this.version = 4;
// migrate values to new style
setEnabled(UserConstants.EMAIL, isEnabled("EMAIL"));
configuration.remove("EMAIL");
setEnabled(UserConstants.GENDER, isEnabled("GENDER"));
configuration.remove("GENDER");
setEnabled(UserConstants.BIRTHDAY, isEnabled("BIRTHDAY"));
configuration.remove("BIRTHDAY");
setEnabled(UserConstants.TELMOBILE, isEnabled("TELMOBILE"));
configuration.remove("TELMOBILE");
setEnabled(UserConstants.TELOFFICE, isEnabled("TELOFFICE"));
configuration.remove("TELOFFICE");
setEnabled(UserConstants.TELPRIVATE, isEnabled("TELPRIVATE"));
configuration.remove("TELPRIVATE");
setEnabled(UserConstants.INSTITUTIONALNAME, isEnabled("INSTITUTIONALNAME"));
configuration.remove("INSTITUTIONALNAME");
setEnabled(UserConstants.INSTITUTIONALEMAIL, isEnabled("INSTITUTIONALEMAIL"));
configuration.remove("INSTITUTIONALEMAIL");
boolean addressEnabled = isEnabled("ADDRESS");
setEnabled(UserConstants.STREET, addressEnabled);
setEnabled(UserConstants.EXTENDEDADDRESS, addressEnabled);
setEnabled(UserConstants.POBOX, addressEnabled);
setEnabled(UserConstants.ZIPCODE, addressEnabled);
setEnabled(UserConstants.CITY, addressEnabled);
setEnabled(UserConstants.REGION, addressEnabled);
setEnabled(UserConstants.COUNTRY, addressEnabled);
configuration.remove("ADDRESS");
}
/*
* after resolving the issues, the version number is merged to the
* CURRENTVERSION !! leave this!
*/
this.version = CURRENTVERSION;
} else if (version > CURRENTVERSION) {
// this is an error
}
}
/**
* Enable or disable the visibility of a user property
* @param propertyName The name of the user property
* @param enabled true: enable visibility; false, disable
*/
public void setEnabled(String propertyName, boolean enabled) {
configuration.put(propertyName, new Boolean(enabled));
}
/**
* Check if the visibility of user property is enabled
* @param propertyName The name of the user property
* @return true: enable visibility; false, disable
*/
public boolean isEnabled(String propertyName) {
Boolean bool = (Boolean) configuration.get(propertyName);
if (bool == null) return false;
else return bool.booleanValue();
}
/**
*
* @param id
*/
public void setResourceableId(Long id){
configuration.put(KEY_RESOURCEABLEID, id);
}
/**
* @return id
*
*/
public Long getResourceableId() {
Long id = (Long) configuration.get(KEY_RESOURCEABLEID);
return id;
}
/**
* @return typeName
*/
public String getResourceableTypeName() {
return RESOURCEABLETYPENAME;
}
/**
*
* @param userName
*/
public void setUserName(String userName){
configuration.put(KEY_USERNAME, userName);
}
/**
* @return text about me
*/
public String getUserName() {
String userName = (String) configuration.get(KEY_USERNAME);
if (userName.equals("")) throw new AssertException("No username defined in " + HomePageConfigManager.HOMEPAGECONFIG_XML);
return userName;
}
/**
*
* @param textAboutMe
*/
public void setTextAboutMe(String textAboutMe) {
configuration.put(KEY_TEXTABOUTME, textAboutMe);
}
/**
* @return text about me
*/
public String getTextAboutMe() {
return (String) configuration.get(KEY_TEXTABOUTME);
}
/**
* @return boolean
*/
public boolean hasResourceableId() {
return !"".equals(configuration.get(KEY_RESOURCEABLEID));
}
}