01: package org.contineo.core;
02:
03: import java.util.Properties;
04:
05: import org.apache.commons.lang.StringUtils;
06:
07: /**
08: * This class is a utility to handle relevant system properties
09: *
10: * @author Alessandro Gasparini
11: * @version 1.0
12: */
13: public final class SystemProperty {
14:
15: private static Properties properties = System.getProperties();
16:
17: public static final String CONTINEO_HOME = "CONTINEO_HOME";
18:
19: public static final String CONTINEO_APP_ROOTDIR = "contineo.app.rootdir";
20:
21: public static final String CONTINEO_PLUGINSDIR = "contineo.app.pluginsdir";
22:
23: /**
24: * Utility class, don't instantiate.
25: */
26: private SystemProperty() {
27: }
28:
29: /**
30: * @param name
31: * @param value
32: */
33: public static void setProperty(String name, String value) {
34: SystemProperty.properties.put(name, value);
35: System.setProperty(name, value);
36: }
37:
38: /**
39: * @param name
40: */
41: public static String getProperty(String name) {
42: return (String) SystemProperty.properties.get(name);
43: }
44:
45: /**
46: * @param name
47: * @param defaultValue
48: */
49: public static String getProperty(String name, String defaultValue) {
50: String value = getProperty(name);
51: if (StringUtils.isEmpty(value)) {
52: return defaultValue;
53: }
54: return value;
55: }
56:
57: public static Properties getProperties() {
58: return SystemProperty.properties;
59: }
60:
61: /**
62: * The home directory of the application, where the data are stored
63: */
64: public static String getContineoHome() {
65: return getProperty(CONTINEO_HOME);
66: }
67:
68: /**
69: * The root application path, where the binaries are stored
70: */
71: public static String getApplicationRoot() {
72: return getProperty(CONTINEO_APP_ROOTDIR);
73: }
74:
75: /**
76: * The directory where all pugins are placed
77: */
78: public static String getPluginsDir() {
79: return getProperty(CONTINEO_PLUGINSDIR);
80: }
81: }
|