Line | Hits | Source |
---|---|---|
1 | /******************************************************************************* | |
2 | *InternetCafe is a software solution that helps the management of Cybercafes | |
3 | * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005. | |
4 | * Copyright (C) 2006 Guido Angelo Ingenito | |
5 | ||
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | ||
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | *******************************************************************************/ | |
20 | package base; | |
21 | ||
22 | import java.io.File; | |
23 | import java.util.Date; | |
24 | ||
25 | import javax.swing.UIManager; | |
26 | ||
27 | import org.apache.log4j.Logger; | |
28 | import org.w3c.dom.Document; | |
29 | import org.w3c.dom.Element; | |
30 | import org.w3c.dom.Node; | |
31 | import org.w3c.dom.NodeList; | |
32 | ||
33 | import ui.dialog.ServerLoginDialog; | |
34 | ||
35 | 9 | public class ConfigurationManager implements IXMLSaveable, IXMLLoadable { |
36 | 0 | private static final transient Logger logger = Logger |
37 | 3 | .getLogger(ConfigurationManager.class.getName()); |
38 | 3 | |
39 | public static final boolean debugMode = true; | |
40 | ||
41 | 0 | public final boolean enableJDBS = false; |
42 | 3 | |
43 | public static final String COPYRIGHT = "InternetCafe version Apha 1.1, Copyright (C) 2006 Guido Angelo Ingenito" | |
44 | 3 | + "\n" |
45 | + "InternetCafe comes with ABSOLUTELY NO WARRANTY; for details click" | |
46 | 3 | + "\n" |
47 | + "'License' from the 'Help' menu. This is free software, and you are welcome" | |
48 | 6 | + "\n" |
49 | 3 | + "to redistribute it under the GPL (General Public License) conditions."; |
50 | 0 | |
51 | 3 | public final static String LICENSE_FILE = "LICENSE.txt"; |
52 | 0 | |
53 | 0 | public final static String BACKUP_DETAILS_FILE = "BackupDetails.xml"; |
54 | 0 | |
55 | 3 | public final static String RESOURCES_DIRECTORY = ((debugMode == true) ? ".." |
56 | 0 | : ".") |
57 | 0 | + File.separatorChar + "InternetCafeResources"; |
58 | 0 | |
59 | 0 | public final static String CONFIGURATION_FILE = RESOURCES_DIRECTORY |
60 | 0 | + File.separatorChar + "configuration.xml"; |
61 | 0 | |
62 | 0 | public static String USER_LIST_HTML_FILE_NAME = "UserList.html"; |
63 | 0 | |
64 | 0 | public static String USER_LIST_CSS_FILE_NAME = "user.css"; |
65 | 0 | |
66 | 0 | public static String USER_LIST_XSL_FILE_NAME = "user.xsl"; |
67 | ||
68 | 0 | public static String SESSION_LIST_HTML_FILE_NAME = "SessionList.html"; |
69 | ||
70 | 0 | public static String SESSION_LIST_CSS_FILE_NAME = "session.css"; |
71 | 6 | |
72 | 0 | public static String SESSION_LIST_XSL_FILE_NAME = "session.xsl"; |
73 | 3 | |
74 | 0 | private static ConfigurationManager instance; |
75 | 6 | |
76 | 3 | private boolean passwordProtect = false; |
77 | 0 | |
78 | 6 | private boolean displayTipOfDay = true; |
79 | 3 | |
80 | 0 | private boolean automaticPasswordProtected = true; |
81 | 3 | |
82 | 0 | private Class internetCafeLookAndFeel = UIManager.getLookAndFeel() |
83 | 6 | .getClass(); |
84 | 3 | |
85 | 0 | private int logoutScheduleRate = 60; // * 10; // The system will try a to |
86 | 6 | // log |
87 | 3 | |
88 | // out after 10 minutes by default; | |
89 | 6 | private Date lastSeenUserWorking = new Date(); |
90 | 3 | |
91 | 0 | private ServerLoginDialog serverLoginDialog; |
92 | 3 | |
93 | 0 | private String internetCafeLogoPath = RESOURCES_DIRECTORY |
94 | 3 | + File.separatorChar + "ztl.jpg"; |
95 | 3 | |
96 | 3 | private String internetCafeName = "ZTL Cafe"; |
97 | 0 | |
98 | 3 | private String dataBasePath = RESOURCES_DIRECTORY + File.separatorChar |
99 | 3 | + "ztl.yap"; |
100 | 3 | |
101 | 0 | private String userImageDirectoryPath = RESOURCES_DIRECTORY |
102 | 0 | + File.separatorChar + "images" + File.separatorChar + "users"; |
103 | ||
104 | 0 | private String documentImageDirectoryPath = RESOURCES_DIRECTORY |
105 | 12 | + File.separatorChar + "images" + File.separatorChar + "documents"; |
106 | 3 | |
107 | 0 | private String htmlDirectoryPath = RESOURCES_DIRECTORY + File.separatorChar |
108 | + "html"; | |
109 | 0 | |
110 | 0 | public static ConfigurationManager getInstance() { |
111 | 0 | return (instance == null) ? (instance = new ConfigurationManager()) |
112 | 0 | : instance; |
113 | } | |
114 | ||
115 | /** | |
116 | * This method reads from an XML document various configuration parameters | |
117 | * for the Internet Cafe. | |
118 | 6 | * |
119 | 3 | * @param document |
120 | 3 | * An XML document that contains a list of configuration |
121 | 26 | * parameters for the Internet Cafe. |
122 | 0 | */ |
123 | 23 | public Object fromXml(Document document) { |
124 | 23 | NodeList configurationNodeList = document |
125 | 6 | .getElementsByTagName(ICXmlTags.IC_CONFIGURATION_TAG); |
126 | 6 | Node configurationNode = configurationNodeList.item(0); |
127 | 3 | |
128 | 3 | for (int i = 0; i < configurationNode.getChildNodes().getLength(); i++) { |
129 | 0 | try { |
130 | 23 | if (configurationNode.getChildNodes().item(i).getNodeName() |
131 | 23 | .equals(ICXmlTags.IC_NAME_TAG)) { |
132 | 6 | internetCafeName = configurationNode.getChildNodes() |
133 | 6 | .item(i).getAttributes().getNamedItem( |
134 | 3 | ICXmlTags.IC_VALUE_ATTRIBUTE) |
135 | 3 | .getNodeValue(); |
136 | 0 | } |
137 | 23 | |
138 | 23 | if (configurationNode.getChildNodes().item(i).getNodeName() |
139 | 6 | .equals(ICXmlTags.IC_LOGO_TAG)) { |
140 | 6 | internetCafeLogoPath = configurationNode.getChildNodes() |
141 | 3 | .item(i).getAttributes().getNamedItem( |
142 | 3 | ICXmlTags.IC_VALUE_ATTRIBUTE) |
143 | .getNodeValue(); | |
144 | 23 | } |
145 | 23 | |
146 | 6 | if (configurationNode.getChildNodes().item(i).getNodeName() |
147 | 6 | .equals(ICXmlTags.IC_DATABASE_TAG)) { |
148 | 3 | dataBasePath = configurationNode.getChildNodes().item(i) |
149 | 3 | .getAttributes().getNamedItem( |
150 | ICXmlTags.IC_VALUE_ATTRIBUTE) | |
151 | 23 | .getNodeValue(); |
152 | 23 | } |
153 | 6 | |
154 | 3 | if (configurationNode.getChildNodes().item(i).getNodeName() |
155 | 3 | .equals(ICXmlTags.IC_USER_IMAGE_DIRECTORY_TAG)) { |
156 | 3 | userImageDirectoryPath = configurationNode.getChildNodes() |
157 | 0 | .item(i).getAttributes().getNamedItem( |
158 | 23 | ICXmlTags.IC_VALUE_ATTRIBUTE) |
159 | 23 | .getNodeValue(); |
160 | 6 | } |
161 | 3 | |
162 | 3 | if (configurationNode.getChildNodes().item(i).getNodeName() |
163 | 3 | .equals(ICXmlTags.IC_DOCUMENT_IMAGE_DIRECTORY_TAG)) { |
164 | 0 | documentImageDirectoryPath = configurationNode |
165 | 23 | .getChildNodes().item(i).getAttributes() |
166 | 23 | .getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE) |
167 | .getNodeValue(); | |
168 | 6 | } |
169 | 6 | |
170 | 6 | if (configurationNode.getChildNodes().item(i).getNodeName() |
171 | 3 | .equals(ICXmlTags.IC_DISPLAY_TIP_OF_DAY_TAG)) { |
172 | 3 | displayTipOfDay = new Boolean(configurationNode |
173 | 0 | .getChildNodes().item(i).getAttributes() |
174 | 0 | .getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE) |
175 | 0 | .getNodeValue()); |
176 | 0 | } |
177 | ||
178 | 0 | if (configurationNode.getChildNodes().item(i).getNodeName() |
179 | 0 | .equals(ICXmlTags.IC_LOOK_AND_FEEL_TAG)) { |
180 | 0 | try { |
181 | 0 | internetCafeLookAndFeel = Class |
182 | 3 | .forName(configurationNode.getChildNodes() |
183 | .item(i).getAttributes().getNamedItem( | |
184 | 0 | ICXmlTags.IC_VALUE_ATTRIBUTE) |
185 | 0 | .getNodeValue()); |
186 | 0 | } catch (Exception ex) { |
187 | 0 | logger.error(ex.getMessage()); |
188 | 0 | ex.printStackTrace(); |
189 | 0 | } |
190 | 0 | } |
191 | 0 | } catch (Exception ex) { |
192 | 0 | ex.printStackTrace(); |
193 | 0 | } |
194 | 6 | } |
195 | 3 | |
196 | 0 | return this; |
197 | 3 | } |
198 | 3 | |
199 | 3 | /** |
200 | 3 | * This method writes to an XML document various configuration parameters of |
201 | 0 | * the Internet Cafe. |
202 | 3 | * |
203 | 6 | * @param document |
204 | 3 | * An XML document that will contain a list of configuration |
205 | 3 | * parameters for the Internet Cafe. |
206 | 0 | */ |
207 | 3 | public Node toXml(Document document) { |
208 | 3 | Element configurationElement = document |
209 | 3 | .createElement(ICXmlTags.IC_CONFIGURATION_TAG); |
210 | 0 | |
211 | 6 | Element nameElement = document.createElement(ICXmlTags.IC_NAME_TAG); |
212 | 3 | |
213 | 6 | nameElement |
214 | 3 | .setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, internetCafeName); |
215 | 3 | configurationElement.appendChild(nameElement); |
216 | 0 | |
217 | 6 | Element logoElement = document.createElement(ICXmlTags.IC_LOGO_TAG); |
218 | 3 | |
219 | 6 | logoElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, |
220 | 3 | internetCafeLogoPath); |
221 | 3 | configurationElement.appendChild(logoElement); |
222 | 0 | |
223 | 6 | Element dbElement = document.createElement(ICXmlTags.IC_DATABASE_TAG); |
224 | 3 | |
225 | 6 | dbElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, dataBasePath); |
226 | 3 | configurationElement.appendChild(dbElement); |
227 | 3 | |
228 | 0 | Element userImageDirectoryElement = document |
229 | 6 | .createElement(ICXmlTags.IC_USER_IMAGE_DIRECTORY_TAG); |
230 | 3 | |
231 | 6 | userImageDirectoryElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, |
232 | 3 | userImageDirectoryPath); |
233 | 3 | configurationElement.appendChild(userImageDirectoryElement); |
234 | 3 | |
235 | 0 | Element documentImageDirectoryElement = document |
236 | 3 | .createElement(ICXmlTags.IC_DOCUMENT_IMAGE_DIRECTORY_TAG); |
237 | ||
238 | 0 | documentImageDirectoryElement.setAttribute( |
239 | ICXmlTags.IC_VALUE_ATTRIBUTE, documentImageDirectoryPath); | |
240 | 0 | configurationElement.appendChild(documentImageDirectoryElement); |
241 | ||
242 | 0 | Element tipOfDayElement = document |
243 | 0 | .createElement(ICXmlTags.IC_DISPLAY_TIP_OF_DAY_TAG); |
244 | ||
245 | 0 | tipOfDayElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, "" |
246 | + displayTipOfDay); | |
247 | 0 | configurationElement.appendChild(tipOfDayElement); |
248 | ||
249 | 0 | Element internetCafeLookandFeelElement = document |
250 | 0 | .createElement(ICXmlTags.IC_LOOK_AND_FEEL_TAG); |
251 | 0 | |
252 | 0 | internetCafeLookandFeelElement.setAttribute( |
253 | 0 | ICXmlTags.IC_VALUE_ATTRIBUTE, internetCafeLookAndFeel |
254 | .getCanonicalName()); | |
255 | 0 | configurationElement.appendChild(internetCafeLookandFeelElement); |
256 | ||
257 | 0 | return configurationElement; |
258 | 0 | } |
259 | 0 | |
260 | /** | |
261 | * @return Returns the internetCafeLogoPath. | |
262 | 0 | */ |
263 | public String getInternetCafeLogoPath() { | |
264 | 0 | return internetCafeLogoPath; |
265 | 0 | } |
266 | 0 | |
267 | 0 | /** |
268 | * @return Returns the internetCafeName. | |
269 | 0 | */ |
270 | public String getInternetCafeName() { | |
271 | 0 | return internetCafeName; |
272 | } | |
273 | 0 | |
274 | 0 | /** |
275 | * @param internetCafeLogoPath | |
276 | * The internetCafeLogoPath to set. | |
277 | 0 | */ |
278 | 0 | public void setInternetCafeLogoPath(String internetCafeLogoPath) { |
279 | 0 | this.internetCafeLogoPath = internetCafeLogoPath; |
280 | 0 | } |
281 | 0 | |
282 | 0 | /** |
283 | * @param internetCafeName | |
284 | * The internetCafeName to set. | |
285 | 0 | */ |
286 | 0 | public void setInternetCafeName(String internetCafeName) { |
287 | 0 | this.internetCafeName = internetCafeName; |
288 | 0 | } |
289 | 0 | |
290 | /** | |
291 | * @return Returns the dataBasePath. | |
292 | 0 | */ |
293 | public String getDataBasePath() { | |
294 | 0 | return dataBasePath; |
295 | 0 | } |
296 | 0 | |
297 | 0 | /** |
298 | * @param dataBasePath | |
299 | * The dataBasePath to set. | |
300 | 0 | */ |
301 | 0 | public void setDataBasePath(String dataBasePath) { |
302 | 0 | this.dataBasePath = dataBasePath; |
303 | 0 | } |
304 | 0 | |
305 | /** | |
306 | * @return Returns the documentImageDirectoryPath. | |
307 | 0 | */ |
308 | public String getDocumentImageDirectoryPath() { | |
309 | 0 | return documentImageDirectoryPath; |
310 | 0 | } |
311 | 0 | |
312 | 0 | /** |
313 | * @param documentImageDirectoryPath | |
314 | * The documentImageDirectoryPath to set. | |
315 | 0 | */ |
316 | 0 | public void setDocumentImageDirectoryPath(String documentImageDirectoryPath) { |
317 | 0 | this.documentImageDirectoryPath = documentImageDirectoryPath; |
318 | 0 | } |
319 | 0 | |
320 | 0 | /** |
321 | * @return Returns the userImageDirectoryPath. | |
322 | 0 | */ |
323 | public String getUserImageDirectoryPath() { | |
324 | 0 | return userImageDirectoryPath; |
325 | } | |
326 | 0 | |
327 | 0 | /** |
328 | 0 | * @param userImageDirectoryPath |
329 | * The userImageDirectoryPath to set. | |
330 | 0 | */ |
331 | 0 | public void setUserImageDirectoryPath(String userImageDirectoryPath) { |
332 | 0 | this.userImageDirectoryPath = userImageDirectoryPath; |
333 | 0 | } |
334 | 0 | |
335 | /** | |
336 | 0 | * @return Returns the passwordProtect. |
337 | 0 | */ |
338 | public boolean isPasswordProtect() { | |
339 | 0 | return passwordProtect; |
340 | } | |
341 | ||
342 | 0 | /** |
343 | 0 | * @param passwordProtect |
344 | 0 | * The passwordProtect to set. |
345 | 0 | */ |
346 | 0 | public void setPasswordProtect(boolean passwordProtect) { |
347 | 0 | logger.debug("Password Protect Setted To:" + passwordProtect); |
348 | 0 | this.passwordProtect = passwordProtect; |
349 | 0 | } |
350 | ||
351 | 0 | /** |
352 | 0 | * @return Returns the automaticPasswordProtected. |
353 | 0 | */ |
354 | public boolean isAutomaticPasswordProtected() { | |
355 | 0 | return automaticPasswordProtected; |
356 | } | |
357 | ||
358 | 0 | /** |
359 | 0 | * @param automaticPasswordProtected |
360 | 0 | * The automaticPasswordProtected to set. |
361 | 0 | */ |
362 | public void setAutomaticPasswordProtect(boolean automaticPasswordProtected) { | |
363 | 0 | logger.debug("Automatic Password Protect Setted To:" |
364 | 0 | + automaticPasswordProtected); |
365 | 0 | this.automaticPasswordProtected = automaticPasswordProtected; |
366 | 0 | } |
367 | ||
368 | 0 | /** |
369 | 0 | * @return Returns the internetCafeLookAndFeel. |
370 | 0 | */ |
371 | public Class getInternetCafeLookAndFeel() { | |
372 | 0 | return internetCafeLookAndFeel; |
373 | } | |
374 | 0 | |
375 | 0 | /** |
376 | 0 | * @param internetCafeLookAndFeel |
377 | 0 | * The internetCafeLookAndFeel to set. |
378 | 0 | */ |
379 | 0 | public void setInternetCafeLookAndFeel(Class internetCafeLookAndFeel) { |
380 | 0 | this.internetCafeLookAndFeel = internetCafeLookAndFeel; |
381 | 0 | } |
382 | ||
383 | 0 | /** |
384 | 0 | * @return Returns the logoutScheduleRate. |
385 | 0 | */ |
386 | public int getLogoutScheduleRate() { | |
387 | 0 | return logoutScheduleRate; |
388 | } | |
389 | ||
390 | 0 | /** |
391 | 0 | * @param logoutScheduleRate |
392 | 0 | * The logoutScheduleRate to set. |
393 | 0 | */ |
394 | public void setLogoutScheduleRate(int logoutScheduleRate) { | |
395 | 0 | logger.debug("Logout Schedule Rate Setted To:" + logoutScheduleRate |
396 | 0 | + "(s)"); |
397 | 0 | this.logoutScheduleRate = logoutScheduleRate; |
398 | 0 | } |
399 | 0 | |
400 | 0 | /** |
401 | * @return Returns the lastSeenUserWorking. | |
402 | 0 | */ |
403 | public Date getLastSeenUserWorking() { | |
404 | 0 | return lastSeenUserWorking; |
405 | } | |
406 | ||
407 | /** | |
408 | * @param lastSeenUserWorking | |
409 | 0 | * The lastSeenUserWorking to set. |
410 | 0 | */ |
411 | 0 | public void setLastSeenUserWorking(Date lastSeenUserWorking) { |
412 | 0 | this.lastSeenUserWorking = lastSeenUserWorking; |
413 | 0 | } |
414 | ||
415 | /** | |
416 | * @return Returns the serverLoginDialog. | |
417 | 0 | */ |
418 | 0 | public ServerLoginDialog getServerLoginDialog() { |
419 | 0 | if (serverLoginDialog == null) { |
420 | 0 | serverLoginDialog = new ServerLoginDialog(); |
421 | 0 | serverLoginDialog.setModal(true); |
422 | 0 | } |
423 | ||
424 | 0 | return serverLoginDialog; |
425 | } | |
426 | ||
427 | /** | |
428 | * @return Returns the displayTipOfDay. | |
429 | 0 | */ |
430 | public boolean isDisplayTipOfDay() { | |
431 | 0 | return displayTipOfDay; |
432 | } | |
433 | ||
434 | /** | |
435 | * @param displayTipOfDay | |
436 | * The displayTipOfDay to set. | |
437 | 0 | */ |
438 | 0 | public void setDisplayTipOfDay(boolean displayTipOfDay) { |
439 | 0 | this.displayTipOfDay = displayTipOfDay; |
440 | 0 | } |
441 | ||
442 | /** | |
443 | * @return Returns the htmlDirectoryPath. | |
444 | 0 | */ |
445 | public String getHtmlDirectoryPath() { | |
446 | 0 | return htmlDirectoryPath; |
447 | } | |
448 | ||
449 | /** | |
450 | * @return Returns the enableJDBS. | |
451 | */ | |
452 | public boolean isJDBSEnabled() { | |
453 | 0 | return enableJDBS; |
454 | } | |
455 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |