1
22
23 package com.liferay.portal.util;
24
25 import com.liferay.portal.configuration.ConfigurationImpl;
26 import com.liferay.portal.kernel.configuration.Configuration;
27 import com.liferay.portal.kernel.configuration.Filter;
28 import com.liferay.portal.kernel.util.GetterUtil;
29 import com.liferay.portal.model.CompanyConstants;
30 import com.liferay.portal.security.auth.CompanyThreadLocal;
31 import com.liferay.util.SystemProperties;
32
33 import java.util.HashMap;
34 import java.util.Map;
35 import java.util.Properties;
36
37
43 public class PropsUtil {
44
45 public static void addProperties(Properties properties) {
46 _instance._addProperties(properties);
47 }
48
49 public static boolean contains(String key) {
50 return _instance._contains(key);
51 }
52
53 public static String get(String key) {
54 return _instance._get(key);
55 }
56
57 public static String get(String key, Filter filter) {
58 return _instance._get(key, filter);
59 }
60
61 public static String[] getArray(String key) {
62 return _instance._getArray(key);
63 }
64
65 public static String[] getArray(String key, Filter filter) {
66 return _instance._getArray(key, filter);
67 }
68
69 public static Properties getProperties() {
70 return _instance._getProperties();
71 }
72
73 public static Properties getProperties(
74 String prefix, boolean removePrefix) {
75
76 return _instance._getProperties(prefix, removePrefix);
77 }
78
79 public static void removeProperties(Properties properties) {
80 _instance._removeProperties(properties);
81 }
82
83 public static void set(String key, String value) {
84 _instance._set(key, value);
85 }
86
87 private PropsUtil() {
88 _configuration = new ConfigurationImpl(
89 PropsUtil.class.getClassLoader(), PropsFiles.PORTAL);
90
91
96 SystemProperties.set(
97 PropsKeys.RESOURCE_REPOSITORIES_ROOT,
98 _get(PropsKeys.RESOURCE_REPOSITORIES_ROOT));
99
100 SystemProperties.set(
101 "ehcache.disk.store.dir",
102 _get(PropsKeys.RESOURCE_REPOSITORIES_ROOT));
103
104 if (GetterUtil.getBoolean(
105 SystemProperties.get("company-id-properties"))) {
106
107 _configurations = new HashMap<Long, Configuration>();
108 }
109 }
110
111 private void _addProperties(Properties properties) {
112 _getConfiguration().addProperties(properties);
113 }
114
115 private boolean _contains(String key) {
116 return _getConfiguration().contains(key);
117 }
118
119 private String _get(String key) {
120 return _getConfiguration().get(key);
121 }
122
123 private String _get(String key, Filter filter) {
124 return _getConfiguration().get(key, filter);
125 }
126
127 private String[] _getArray(String key) {
128 return _getConfiguration().getArray(key);
129 }
130
131 private String[] _getArray(String key, Filter filter) {
132 return _getConfiguration().getArray(key, filter);
133 }
134
135 private Configuration _getConfiguration() {
136 if (_configurations == null) {
137 return _configuration;
138 }
139
140 long companyId = CompanyThreadLocal.getCompanyId();
141
142 if (companyId > CompanyConstants.SYSTEM) {
143 Configuration configuration = _configurations.get(companyId);
144
145 if (configuration == null) {
146 configuration = new ConfigurationImpl(
147 PropsUtil.class.getClassLoader(), PropsFiles.PORTAL,
148 companyId);
149
150 _configurations.put(companyId, configuration);
151 }
152
153 return configuration;
154 }
155 else {
156 return _configuration;
157 }
158 }
159
160 private Properties _getProperties() {
161 return _getConfiguration().getProperties();
162 }
163
164 private Properties _getProperties(String prefix, boolean removePrefix) {
165 return _getConfiguration().getProperties(prefix, removePrefix);
166 }
167
168 private void _removeProperties(Properties properties) {
169 _getConfiguration().removeProperties(properties);
170 }
171
172 private void _set(String key, String value) {
173 _getConfiguration().set(key, value);
174 }
175
176 private static PropsUtil _instance = new PropsUtil();
177
178 private Configuration _configuration;
179 private Map<Long, Configuration> _configurations;
180
181 }