/
ConfigurationManager.java
415 lines (383 loc) · 14.5 KB
/
ConfigurationManager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
99
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.core;
import java.util.Enumeration;
import java.util.Properties;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationConverter;
import org.apache.log4j.Logger;
import org.dspace.services.factory.DSpaceServicesFactory;
/**
* Class for reading the DSpace system configuration. The main configuration is
* read in as properties from a standard properties file.
* <P>
* To specify a different configuration, the system property
* <code>dspace.dir</code> should be set to the DSpace installation directory.
* <P>
* Other configuration files are read from the <code>config</code> directory
* of the DSpace installation directory.
*
*
* @author Robert Tansley
* @author Larry Stone - Interpolated values.
* @author Mark Diggory - General Improvements to detection, logging and loading.
* @author Tim Donohue - Refactored to wrap ConfigurationService
* @version $Revision$
* @deprecated Please use org.dspace.services.ConfigurationService. See examples below.
*/
public class ConfigurationManager
{
/** log4j category */
private static final Logger log = Logger.getLogger(ConfigurationManager.class);
protected ConfigurationManager()
{
}
/**
* Identify if DSpace is properly configured
* @return boolean true if configured, false otherwise
*/
public static boolean isConfigured()
{
return DSpaceServicesFactory.getInstance().getConfigurationService() != null;
}
/**
* Returns all properties in main configuration
*
* @return properties - all non-modular properties
*/
public static Properties getProperties()
{
return DSpaceServicesFactory.getInstance().getConfigurationService().getProperties();
}
/**
* Returns all properties for a given module
*
* @param module
* the name of the module
* @return properties - all module's properties
*/
public static Properties getProperties(String module)
{
// Find subset of Configurations which have been prefixed with the module name
Configuration subset = DSpaceServicesFactory.getInstance().getConfigurationService().getConfiguration().subset(module);
// Convert to a Properties object and return it
return ConfigurationConverter.getProperties(subset);
}
/**
* Get a configuration property
*
* @param property
* the name of the property
*
* @return the value of the property, or <code>null</code> if the property
* does not exist.
*/
public static String getProperty(String property)
{
return DSpaceServicesFactory.getInstance().getConfigurationService().getProperty(property);
}
/**
* Get a module configuration property value.
*
* @param module
* the name of the module, or <code>null</code> for regular configuration
* property
* @param property
* the name (key) of the property
* @return
* the value of the property, or <code>null</code> if the
* property does not exist
*/
public static String getProperty(String module, String property)
{
if (module == null)
{
return getProperty(property);
}
// Assume "module" properties are always prefixed with the module name
return getProperty(module + "." + property);
}
/**
* Get a configuration property as an integer
*
* @param property
* the name of the property
*
* @return the value of the property. <code>0</code> is returned if the
* property does not exist. To differentiate between this case and
* when the property actually is zero, use <code>getProperty</code>.
*/
public static int getIntProperty(String property)
{
return DSpaceServicesFactory.getInstance().getConfigurationService().getIntProperty(property);
}
/**
* Get a module configuration property as an integer
*
* @param module
* the name of the module
*
* @param property
* the name of the property
*
* @return the value of the property. <code>0</code> is returned if the
* property does not exist. To differentiate between this case and
* when the property actually is zero, use <code>getProperty</code>.
*/
public static int getIntProperty(String module, String property)
{
if (module == null)
{
return getIntProperty(property);
}
// Assume "module" properties are always prefixed with the module name
return getIntProperty(module + "." + property);
}
/**
* Get a configuration property as an integer, with default
*
* @param property
* the name of the property
*
* @param defaultValue
* value to return if property is not found or is not an Integer.
*
* @return the value of the property. <code>default</code> is returned if
* the property does not exist or is not an Integer. To differentiate between this case
* and when the property actually is false, use
* <code>getProperty</code>.
*/
public static int getIntProperty(String property, int defaultValue)
{
return DSpaceServicesFactory.getInstance().getConfigurationService().getIntProperty(property, defaultValue);
}
/**
* Get a module configuration property as an integer, with default
*
* @param module
* the name of the module
*
* @param property
* the name of the property
*
* @param defaultValue
* value to return if property is not found or is not an Integer.
*
* @return the value of the property. <code>default</code> is returned if
* the property does not exist or is not an Integer. To differentiate between this case
* and when the property actually is false, use
* <code>getProperty</code>.
*/
public static int getIntProperty(String module, String property, int defaultValue)
{
if (module == null)
{
return getIntProperty(property, defaultValue);
}
// Assume "module" properties are always prefixed with the module name
return getIntProperty(module + "." + property, defaultValue);
}
/**
* Get a configuration property as a long
*
* @param property
* the name of the property
*
* @return the value of the property. <code>0</code> is returned if the
* property does not exist. To differentiate between this case and
* when the property actually is zero, use <code>getProperty</code>.
*/
public static long getLongProperty(String property)
{
return DSpaceServicesFactory.getInstance().getConfigurationService().getLongProperty(property);
}
/**
* Get a module configuration property as a long
*
* @param module
* the name of the module
* @param property
* the name of the property
*
* @return the value of the property. <code>0</code> is returned if the
* property does not exist. To differentiate between this case and
* when the property actually is zero, use <code>getProperty</code>.
*/
public static long getLongProperty(String module, String property)
{
if (module == null)
{
return getLongProperty(property);
}
// Assume "module" properties are always prefixed with the module name
return getLongProperty(module + "." + property);
}
/**
* Get a configuration property as an long, with default
*
*
* @param property
* the name of the property
*
* @param defaultValue
* value to return if property is not found or is not a Long.
*
* @return the value of the property. <code>default</code> is returned if
* the property does not exist or is not an Integer. To differentiate between this case
* and when the property actually is false, use
* <code>getProperty</code>.
*/
public static long getLongProperty(String property, int defaultValue)
{
return DSpaceServicesFactory.getInstance().getConfigurationService().getLongProperty(property, defaultValue);
}
/**
* Get a configuration property as an long, with default
*
* @param module the module, or <code>null</code> for regular property
*
* @param property
* the name of the property
*
* @param defaultValue
* value to return if property is not found or is not a Long.
*
* @return the value of the property. <code>default</code> is returned if
* the property does not exist or is not an Integer. To differentiate between this case
* and when the property actually is false, use
* <code>getProperty</code>.
*/
public static long getLongProperty(String module, String property, int defaultValue)
{
if (module == null)
{
return getLongProperty(property, defaultValue);
}
// Assume "module" properties are always prefixed with the module name
return getLongProperty(module + "." + property, defaultValue);
}
/**
* Get a configuration property as a boolean. True is indicated if the value
* of the property is <code>TRUE</code> or <code>YES</code> (case
* insensitive.)
*
* @param property
* the name of the property
*
* @return the value of the property. <code>false</code> is returned if
* the property does not exist. To differentiate between this case
* and when the property actually is false, use
* <code>getProperty</code>.
*/
public static boolean getBooleanProperty(String property)
{
return DSpaceServicesFactory.getInstance().getConfigurationService().getBooleanProperty(property);
}
/**
* Get a module configuration property as a boolean. True is indicated if
* the value of the property is <code>TRUE</code> or <code>YES</code> (case
* insensitive.)
*
* @param module the module, or <code>null</code> for regular property
*
* @param property
* the name of the property
*
* @return the value of the property. <code>false</code> is returned if
* the property does not exist. To differentiate between this case
* and when the property actually is false, use
* <code>getProperty</code>.
*/
public static boolean getBooleanProperty(String module, String property)
{
if (module == null)
{
return getBooleanProperty(property);
}
// Assume "module" properties are always prefixed with the module name
return getBooleanProperty(module + "." + property);
}
/**
* Get a configuration property as a boolean, with default.
* True is indicated if the value
* of the property is <code>TRUE</code> or <code>YES</code> (case
* insensitive.)
*
* @param property
* the name of the property
*
* @param defaultValue
* value to return if property is not found.
*
* @return the value of the property. <code>default</code> is returned if
* the property does not exist. To differentiate between this case
* and when the property actually is false, use
* <code>getProperty</code>.
*/
public static boolean getBooleanProperty(String property, boolean defaultValue)
{
return DSpaceServicesFactory.getInstance().getConfigurationService().getBooleanProperty(property, defaultValue);
}
/**
* Get a module configuration property as a boolean, with default.
* True is indicated if the value
* of the property is <code>TRUE</code> or <code>YES</code> (case
* insensitive.)
*
* @param module module, or <code>null</code> for regular property
*
* @param property
* the name of the property
*
* @param defaultValue
* value to return if property is not found.
*
* @return the value of the property. <code>default</code> is returned if
* the property does not exist. To differentiate between this case
* and when the property actually is false, use
* <code>getProperty</code>.
*/
public static boolean getBooleanProperty(String module, String property, boolean defaultValue)
{
if (module == null)
{
return getBooleanProperty(property, defaultValue);
}
// Assume "module" properties are always prefixed with the module name
return getBooleanProperty(module + "." + property, defaultValue);
}
/**
* Returns an enumeration of all the keys in the DSpace configuration
* <P>
* As ConfigurationManager is now deprecated, older code using this method
* should consider using ConfigurationService.getPropertyKeys() directly.
*
* @return an enumeration of all the keys in the DSpace configuration
*/
public static Enumeration<?> propertyNames()
{
// Get a list of all property keys, and convert into an Enumeration
return java.util.Collections.enumeration(DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyKeys());
}
/**
* Returns an enumeration of all the keys in a module configuration
* <P>
* As ConfigurationManager is now deprecated, older code using this method
* should consider using ConfigurationService.getPropertyKeys(String prefix) directly.
*
* @param module module, or <code>null</code> for regular property
*
* @return an enumeration of all the keys in the module configuration,
* or <code>null</code> if the module does not exist.
*/
public static Enumeration<?> propertyNames(String module)
{
// Get property keys beginning with this prefix, and convert into an Enumeration
return java.util.Collections.enumeration(DSpaceServicesFactory.getInstance().getConfigurationService().getPropertyKeys(module));
}
}