|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.qedeq.kernel.config; |
|
19 |
| |
|
20 |
| import java.io.File; |
|
21 |
| import java.io.IOException; |
|
22 |
| import java.net.URL; |
|
23 |
| import java.util.List; |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| public class QedeqConfig { |
|
33 |
| |
|
34 |
| |
|
35 |
| private static final String DEFAULT_LOCAL_MODULES_DIRECTORY |
|
36 |
| = "local"; |
|
37 |
| |
|
38 |
| |
|
39 |
| private static final String DEFAULT_LOCAL_BUFFER |
|
40 |
| = "buffer"; |
|
41 |
| |
|
42 |
| |
|
43 |
| private static final String DEFAULT_GENERATED |
|
44 |
| = "generated"; |
|
45 |
| |
|
46 |
| |
|
47 |
| private static final String DEFAULT_LOG_FILE |
|
48 |
| = "log/log.txt"; |
|
49 |
| |
|
50 |
| |
|
51 |
| private final ConfigAccess configAccess; |
|
52 |
| |
|
53 |
| |
|
54 |
| private final File basisDirectory; |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
28
| public QedeqConfig(final File configFile, final String description, final File basisDirectory)
|
|
66 |
| throws IOException { |
|
67 |
28
| configAccess = new ConfigAccess(configFile, description);
|
|
68 |
28
| this.basisDirectory = basisDirectory;
|
|
69 |
| } |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
28
| public final void store() throws IOException {
|
|
77 |
28
| configAccess.store();
|
|
78 |
| } |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
11
| public final String getGenerationDirectory() {
|
|
86 |
11
| final String location = getKeyValue("generationLocation");
|
|
87 |
11
| if (location == null) {
|
|
88 |
11
| return QedeqConfig.DEFAULT_GENERATED;
|
|
89 |
| } |
|
90 |
0
| return location;
|
|
91 |
| } |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
0
| public final void setGenerationDirectory(final String location) {
|
|
99 |
0
| setKeyValue("generationLocation", location);
|
|
100 |
| } |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
464
| public final String getBufferDirectory() {
|
|
108 |
464
| final String location = getKeyValue("bufferLocation");
|
|
109 |
464
| if (location == null) {
|
|
110 |
464
| return QedeqConfig.DEFAULT_LOCAL_BUFFER;
|
|
111 |
| } |
|
112 |
0
| return location;
|
|
113 |
| } |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
0
| public final void setBufferDirectory(final String location) {
|
|
123 |
0
| setKeyValue("bufferLocation", location);
|
|
124 |
| } |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
8
| public final String getLogFile() {
|
|
132 |
8
| final String location = getKeyValue("logLocation");
|
|
133 |
8
| if (location == null) {
|
|
134 |
8
| return QedeqConfig.DEFAULT_LOG_FILE;
|
|
135 |
| } |
|
136 |
0
| return location;
|
|
137 |
| } |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
4
| public final String[] getModuleHistory() {
|
|
145 |
4
| return configAccess.getStringProperties("moduleHistory.");
|
|
146 |
| } |
|
147 |
| |
|
148 |
| |
|
149 |
| |
|
150 |
| |
|
151 |
| |
|
152 |
| |
|
153 |
5
| public final void saveModuleHistory(final List modules) {
|
|
154 |
5
| configAccess.removeProperties(("moduleHistory."));
|
|
155 |
5
| for (int i = 0; i < modules.size(); i++) {
|
|
156 |
39
| setKeyValue("moduleHistory." + (i + 101),
|
|
157 |
| modules.get(i).toString()); |
|
158 |
| } |
|
159 |
| } |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
| |
|
164 |
| |
|
165 |
| |
|
166 |
56
| public final String[] getPreviouslyCheckedModules() {
|
|
167 |
56
| return configAccess.getStringProperties("checkedModule.");
|
|
168 |
| } |
|
169 |
| |
|
170 |
| |
|
171 |
| |
|
172 |
| |
|
173 |
| |
|
174 |
| |
|
175 |
28
| public final void setLoadedModules(final URL[] moduleAddresses) {
|
|
176 |
28
| configAccess.removeProperties("checkedModule.");
|
|
177 |
28
| for (int i = 0; i < moduleAddresses.length; i++) {
|
|
178 |
342
| setKeyValue("checkedModule." + (i + 1), moduleAddresses[i].toExternalForm());
|
|
179 |
| } |
|
180 |
| } |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| |
|
186 |
| |
|
187 |
478
| public final File getBasisDirectory() {
|
|
188 |
478
| return basisDirectory;
|
|
189 |
| } |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
463
| public final File getRelativeToBasis(final String path) {
|
|
198 |
463
| return new File(getBasisDirectory(), path);
|
|
199 |
| } |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
| |
|
204 |
| |
|
205 |
| |
|
206 |
58
| public boolean isAutoReloadLastSessionChecked() {
|
|
207 |
58
| return "true".equals(
|
|
208 |
| getKeyValue("sessionAutoReload", "true")); |
|
209 |
| } |
|
210 |
| |
|
211 |
| |
|
212 |
| |
|
213 |
| |
|
214 |
| |
|
215 |
| |
|
216 |
| |
|
217 |
2
| public final void setAutoReloadLastSessionChecked(final boolean mode) {
|
|
218 |
2
| setKeyValue("sessionAutoReload", (mode ? "true" : "false"));
|
|
219 |
| } |
|
220 |
| |
|
221 |
| |
|
222 |
| |
|
223 |
| |
|
224 |
| |
|
225 |
| |
|
226 |
| |
|
227 |
2
| public final boolean isOldHtml() {
|
|
228 |
2
| return "true".equals(getKeyValue("oldHtml", "true"));
|
|
229 |
| } |
|
230 |
| |
|
231 |
| |
|
232 |
| |
|
233 |
| |
|
234 |
| |
|
235 |
| |
|
236 |
2
| public final void setOldHtml(final boolean mode) {
|
|
237 |
2
| setKeyValue("oldHtml", (mode ? "true" : "false"));
|
|
238 |
| } |
|
239 |
| |
|
240 |
| |
|
241 |
| |
|
242 |
| |
|
243 |
| |
|
244 |
| |
|
245 |
| |
|
246 |
2
| public final String getLocalModulesDirectory() {
|
|
247 |
2
| final String location = getKeyValue("localModulesDirectory");
|
|
248 |
2
| if (location == null) {
|
|
249 |
2
| return QedeqConfig.DEFAULT_LOCAL_MODULES_DIRECTORY;
|
|
250 |
| } |
|
251 |
0
| return location;
|
|
252 |
| } |
|
253 |
| |
|
254 |
| |
|
255 |
| |
|
256 |
| |
|
257 |
| |
|
258 |
| |
|
259 |
| |
|
260 |
| |
|
261 |
0
| public final void setLocalModulesDirectory(final String location) {
|
|
262 |
0
| setKeyValue("localModulesDirectory", location);
|
|
263 |
| } |
|
264 |
| |
|
265 |
| |
|
266 |
| |
|
267 |
| |
|
268 |
| |
|
269 |
| |
|
270 |
| |
|
271 |
489
| protected String getKeyValue(final String key) {
|
|
272 |
489
| return configAccess.getString(key);
|
|
273 |
| } |
|
274 |
| |
|
275 |
| |
|
276 |
| |
|
277 |
| |
|
278 |
| |
|
279 |
| |
|
280 |
| |
|
281 |
| |
|
282 |
| |
|
283 |
470
| protected String getKeyValue(final String key, final String defaultValue) {
|
|
284 |
470
| return configAccess.getString(key, defaultValue);
|
|
285 |
| } |
|
286 |
| |
|
287 |
| |
|
288 |
| |
|
289 |
| |
|
290 |
| |
|
291 |
| |
|
292 |
| |
|
293 |
393
| protected void setKeyValue(final String key, final String value) {
|
|
294 |
393
| configAccess.setString(key, value);
|
|
295 |
| } |
|
296 |
| |
|
297 |
| } |