1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.fckeditor.handlers;
22
23 import java.io.BufferedInputStream;
24 import java.io.InputStream;
25 import java.util.Properties;
26
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public class PropertiesLoader {
50 private static final Logger logger = LoggerFactory
51 .getLogger(PropertiesLoader.class);
52 private static final String DEFAULT_FILENAME = "default.properties";
53 private static final String LOCAL_PROPERTIES = "/fckeditor.properties";
54 private static Properties properties = new Properties();
55
56 static {
57
58
59 InputStream in = PropertiesLoader.class
60 .getResourceAsStream(DEFAULT_FILENAME);
61
62 if (in == null) {
63 logger.error("{} not found", DEFAULT_FILENAME);
64 throw new RuntimeException(DEFAULT_FILENAME + " not found");
65 } else {
66 if (!(in instanceof BufferedInputStream))
67 in = new BufferedInputStream(in);
68
69 try {
70 properties.load(in);
71 in.close();
72 logger.debug("{} loaded", DEFAULT_FILENAME);
73 } catch (Exception e) {
74 logger.error("Error while processing {}", DEFAULT_FILENAME);
75 throw new RuntimeException("Error while processing "
76 + DEFAULT_FILENAME, e);
77 }
78 }
79
80
81 InputStream in2 = PropertiesLoader.class
82 .getResourceAsStream(LOCAL_PROPERTIES);
83
84 if (in2 == null) {
85 logger.info("{} not found", LOCAL_PROPERTIES);
86 } else {
87
88 if (!(in2 instanceof BufferedInputStream))
89 in2 = new BufferedInputStream(in2);
90
91 try {
92 properties.load(in2);
93 in2.close();
94 logger.debug("{} loaded", LOCAL_PROPERTIES);
95 } catch (Exception e) {
96 logger.error("Error while processing {}", LOCAL_PROPERTIES);
97 throw new RuntimeException("Error while processing "
98 + LOCAL_PROPERTIES, e);
99 }
100
101 }
102 }
103
104
105
106
107
108
109 public static String getProperty(final String key) {
110 return properties.getProperty(key);
111 }
112
113
114
115
116
117
118 public static void setProperty(final String key, final String value) {
119 properties.setProperty(key, value);
120 }
121
122
123
124
125 public static String getEditorToolbarSet() {
126 return properties.getProperty("fckeditor.toolbarSet");
127 }
128
129
130
131
132 public static String getEditorWidth() {
133 return properties.getProperty("fckeditor.width");
134 }
135
136
137
138
139 public static String getEditorHeight() {
140 return properties.getProperty("fckeditor.height");
141 }
142
143
144
145
146 public static String getEditorBasePath() {
147 return properties.getProperty("fckeditor.basePath");
148 }
149
150
151
152
153 public static String getFileResourceTypePath() {
154 return properties.getProperty("connector.resourceType.file.path");
155 }
156
157
158
159
160 public static String getFlashResourceTypePath() {
161 return properties.getProperty("connector.resourceType.flash.path");
162 }
163
164
165
166
167 public static String getImageResourceTypePath() {
168 return properties.getProperty("connector.resourceType.image.path");
169 }
170
171
172
173
174 public static String getMediaResourceTypePath() {
175 return properties.getProperty("connector.resourceType.media.path");
176 }
177
178
179
180
181
182 public static String getFileResourceTypeAllowedExtensions() {
183 return properties
184 .getProperty("connector.resourceType.file.extensions.allowed");
185 }
186
187
188
189
190
191 public static String getFileResourceTypeDeniedExtensions() {
192 return properties
193 .getProperty("connector.resourceType.file.extensions.denied");
194 }
195
196
197
198
199
200 public static String getFlashResourceTypeAllowedExtensions() {
201 return properties
202 .getProperty("connector.resourceType.flash.extensions.allowed");
203 }
204
205
206
207
208
209 public static String getFlashResourceTypeDeniedExtensions() {
210 return properties
211 .getProperty("connector.resourceType.flash.extensions.denied");
212 }
213
214
215
216
217
218 public static String getImageResourceTypeAllowedExtensions() {
219 return properties
220 .getProperty("connector.resourceType.image.extensions.allowed");
221 }
222
223
224
225
226
227 public static String getImageResourceTypeDeniedExtensions() {
228 return properties
229 .getProperty("connector.resourceType.image.extensions.denied");
230 }
231
232
233
234
235
236 public static String getMediaResourceTypeAllowedExtensions() {
237 return properties
238 .getProperty("connector.resourceType.media.extensions.allowed");
239 }
240
241
242
243
244
245 public static String getMediaResourceTypeDeniedExtensions() {
246 return properties
247 .getProperty("connector.resourceType.media.extensions.denied");
248 }
249
250
251
252
253 public static String getUserFilesPath() {
254 return properties.getProperty("connector.userFilesPath");
255 }
256
257
258
259
260 public static String getUserFilesAbsolutePath() {
261 return properties.getProperty("connector.userFilesAbsolutePath");
262 }
263
264
265
266
267 public static boolean isForceSingleExtension() {
268 return Boolean.valueOf(properties
269 .getProperty("connector.forceSingleExtension"));
270 }
271
272
273
274
275 public static boolean isSecureImageUploads() {
276 return Boolean.valueOf(properties
277 .getProperty("connector.secureImageUploads"));
278 }
279
280
281
282
283 public static String getConnectorImpl() {
284 return properties.getProperty("connector.impl");
285 }
286
287
288
289
290 public static String getUserActionImpl() {
291 return properties.getProperty("connector.userActionImpl");
292 }
293
294
295
296
297 public static String getUserPathBuilderImpl() {
298 return properties.getProperty("connector.userPathBuilderImpl");
299 }
300
301
302
303
304 public static String getLocaleResolverImpl() {
305 return properties.getProperty("localization.localeResolverImpl");
306 }
307 }