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