Coverage details for base.ConfigurationManager

LineHitsSource
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  
359public class ConfigurationManager implements IXMLSaveable, IXMLLoadable {
360    private static final transient Logger logger = Logger
373            .getLogger(ConfigurationManager.class.getName());
383 
39     public static final boolean debugMode = true;
40     
410    public final boolean enableJDBS = false;
423 
43     public static final String COPYRIGHT = "InternetCafe version Apha 1.1, Copyright (C) 2006 Guido Angelo Ingenito"
443            + "\n"
45             + "InternetCafe comes with ABSOLUTELY NO WARRANTY; for details click"
463            + "\n"
47             + "'License' from the 'Help' menu. This is free software, and you are welcome"
486            + "\n"
493            + "to redistribute it under the GPL (General Public License) conditions.";
500 
513    public final static String LICENSE_FILE = "LICENSE.txt";
520 
530    public final static String BACKUP_DETAILS_FILE = "BackupDetails.xml";
540 
553    public final static String RESOURCES_DIRECTORY = ((debugMode == true) ? ".."
560            : ".")
570            + File.separatorChar + "InternetCafeResources";
580 
590    public final static String CONFIGURATION_FILE = RESOURCES_DIRECTORY
600            + File.separatorChar + "configuration.xml";
610 
620    public static String USER_LIST_HTML_FILE_NAME = "UserList.html";
630 
640    public static String USER_LIST_CSS_FILE_NAME = "user.css";
650 
660    public static String USER_LIST_XSL_FILE_NAME = "user.xsl";
67  
680    public static String SESSION_LIST_HTML_FILE_NAME = "SessionList.html";
69  
700    public static String SESSION_LIST_CSS_FILE_NAME = "session.css";
716 
720    public static String SESSION_LIST_XSL_FILE_NAME = "session.xsl";
733 
740    private static ConfigurationManager instance;
756 
763    private boolean passwordProtect = false;
770 
786    private boolean displayTipOfDay = true;
793 
800    private boolean automaticPasswordProtected = true;
813 
820    private Class internetCafeLookAndFeel = UIManager.getLookAndFeel()
836            .getClass();
843 
850    private int logoutScheduleRate = 60; // * 10; // The system will try a to
866                                            // log
873 
88     // out after 10 minutes by default;
896    private Date lastSeenUserWorking = new Date();
903 
910    private ServerLoginDialog serverLoginDialog;
923 
930    private String internetCafeLogoPath = RESOURCES_DIRECTORY
943            + File.separatorChar + "ztl.jpg";
953 
963    private String internetCafeName = "ZTL Cafe";
970 
983    private String dataBasePath = RESOURCES_DIRECTORY + File.separatorChar
993            + "ztl.yap";
1003 
1010    private String userImageDirectoryPath = RESOURCES_DIRECTORY
1020            + File.separatorChar + "images" + File.separatorChar + "users";
103  
1040    private String documentImageDirectoryPath = RESOURCES_DIRECTORY
10512            + File.separatorChar + "images" + File.separatorChar + "documents";
1063 
1070    private String htmlDirectoryPath = RESOURCES_DIRECTORY + File.separatorChar
108             + "html";
1090 
1100    public static ConfigurationManager getInstance() {
1110        return (instance == null) ? (instance = new ConfigurationManager())
1120                : instance;
113     }
114  
115     /**
116      * This method reads from an XML document various configuration parameters
117      * for the Internet Cafe.
1186     *
1193     * @param document
1203     * An XML document that contains a list of configuration
12126     * parameters for the Internet Cafe.
1220     */
12323    public Object fromXml(Document document) {
12423        NodeList configurationNodeList = document
1256                .getElementsByTagName(ICXmlTags.IC_CONFIGURATION_TAG);
1266        Node configurationNode = configurationNodeList.item(0);
1273 
1283        for (int i = 0; i < configurationNode.getChildNodes().getLength(); i++) {
1290            try {
13023                if (configurationNode.getChildNodes().item(i).getNodeName()
13123                        .equals(ICXmlTags.IC_NAME_TAG)) {
1326                    internetCafeName = configurationNode.getChildNodes()
1336                            .item(i).getAttributes().getNamedItem(
1343                                    ICXmlTags.IC_VALUE_ATTRIBUTE)
1353                            .getNodeValue();
1360                }
13723 
13823                if (configurationNode.getChildNodes().item(i).getNodeName()
1396                        .equals(ICXmlTags.IC_LOGO_TAG)) {
1406                    internetCafeLogoPath = configurationNode.getChildNodes()
1413                            .item(i).getAttributes().getNamedItem(
1423                                    ICXmlTags.IC_VALUE_ATTRIBUTE)
143                             .getNodeValue();
14423                }
14523 
1466                if (configurationNode.getChildNodes().item(i).getNodeName()
1476                        .equals(ICXmlTags.IC_DATABASE_TAG)) {
1483                    dataBasePath = configurationNode.getChildNodes().item(i)
1493                            .getAttributes().getNamedItem(
150                                     ICXmlTags.IC_VALUE_ATTRIBUTE)
15123                            .getNodeValue();
15223                }
1536 
1543                if (configurationNode.getChildNodes().item(i).getNodeName()
1553                        .equals(ICXmlTags.IC_USER_IMAGE_DIRECTORY_TAG)) {
1563                    userImageDirectoryPath = configurationNode.getChildNodes()
1570                            .item(i).getAttributes().getNamedItem(
15823                                    ICXmlTags.IC_VALUE_ATTRIBUTE)
15923                            .getNodeValue();
1606                }
1613 
1623                if (configurationNode.getChildNodes().item(i).getNodeName()
1633                        .equals(ICXmlTags.IC_DOCUMENT_IMAGE_DIRECTORY_TAG)) {
1640                    documentImageDirectoryPath = configurationNode
16523                            .getChildNodes().item(i).getAttributes()
16623                            .getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE)
167                             .getNodeValue();
1686                }
1696 
1706                if (configurationNode.getChildNodes().item(i).getNodeName()
1713                        .equals(ICXmlTags.IC_DISPLAY_TIP_OF_DAY_TAG)) {
1723                    displayTipOfDay = new Boolean(configurationNode
1730                            .getChildNodes().item(i).getAttributes()
1740                            .getNamedItem(ICXmlTags.IC_VALUE_ATTRIBUTE)
1750                            .getNodeValue());
1760                }
177  
1780                if (configurationNode.getChildNodes().item(i).getNodeName()
1790                        .equals(ICXmlTags.IC_LOOK_AND_FEEL_TAG)) {
1800                    try {
1810                        internetCafeLookAndFeel = Class
1823                                .forName(configurationNode.getChildNodes()
183                                         .item(i).getAttributes().getNamedItem(
1840                                                ICXmlTags.IC_VALUE_ATTRIBUTE)
1850                                        .getNodeValue());
1860                    } catch (Exception ex) {
1870                        logger.error(ex.getMessage());
1880                        ex.printStackTrace();
1890                    }
1900                }
1910            } catch (Exception ex) {
1920                ex.printStackTrace();
1930            }
1946        }
1953 
1960        return this;
1973    }
1983 
1993    /**
2003     * This method writes to an XML document various configuration parameters of
2010     * the Internet Cafe.
2023     *
2036     * @param document
2043     * An XML document that will contain a list of configuration
2053     * parameters for the Internet Cafe.
2060     */
2073    public Node toXml(Document document) {
2083        Element configurationElement = document
2093                .createElement(ICXmlTags.IC_CONFIGURATION_TAG);
2100 
2116        Element nameElement = document.createElement(ICXmlTags.IC_NAME_TAG);
2123 
2136        nameElement
2143                .setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, internetCafeName);
2153        configurationElement.appendChild(nameElement);
2160 
2176        Element logoElement = document.createElement(ICXmlTags.IC_LOGO_TAG);
2183 
2196        logoElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
2203                internetCafeLogoPath);
2213        configurationElement.appendChild(logoElement);
2220 
2236        Element dbElement = document.createElement(ICXmlTags.IC_DATABASE_TAG);
2243 
2256        dbElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, dataBasePath);
2263        configurationElement.appendChild(dbElement);
2273 
2280        Element userImageDirectoryElement = document
2296                .createElement(ICXmlTags.IC_USER_IMAGE_DIRECTORY_TAG);
2303 
2316        userImageDirectoryElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE,
2323                userImageDirectoryPath);
2333        configurationElement.appendChild(userImageDirectoryElement);
2343 
2350        Element documentImageDirectoryElement = document
2363                .createElement(ICXmlTags.IC_DOCUMENT_IMAGE_DIRECTORY_TAG);
237  
2380        documentImageDirectoryElement.setAttribute(
239                 ICXmlTags.IC_VALUE_ATTRIBUTE, documentImageDirectoryPath);
2400        configurationElement.appendChild(documentImageDirectoryElement);
241  
2420        Element tipOfDayElement = document
2430                .createElement(ICXmlTags.IC_DISPLAY_TIP_OF_DAY_TAG);
244  
2450        tipOfDayElement.setAttribute(ICXmlTags.IC_VALUE_ATTRIBUTE, ""
246                 + displayTipOfDay);
2470        configurationElement.appendChild(tipOfDayElement);
248  
2490        Element internetCafeLookandFeelElement = document
2500                .createElement(ICXmlTags.IC_LOOK_AND_FEEL_TAG);
2510 
2520        internetCafeLookandFeelElement.setAttribute(
2530                ICXmlTags.IC_VALUE_ATTRIBUTE, internetCafeLookAndFeel
254                         .getCanonicalName());
2550        configurationElement.appendChild(internetCafeLookandFeelElement);
256  
2570        return configurationElement;
2580    }
2590 
260     /**
261      * @return Returns the internetCafeLogoPath.
2620     */
263     public String getInternetCafeLogoPath() {
2640        return internetCafeLogoPath;
2650    }
2660 
2670    /**
268      * @return Returns the internetCafeName.
2690     */
270     public String getInternetCafeName() {
2710        return internetCafeName;
272     }
2730 
2740    /**
275      * @param internetCafeLogoPath
276      * The internetCafeLogoPath to set.
2770     */
2780    public void setInternetCafeLogoPath(String internetCafeLogoPath) {
2790        this.internetCafeLogoPath = internetCafeLogoPath;
2800    }
2810 
2820    /**
283      * @param internetCafeName
284      * The internetCafeName to set.
2850     */
2860    public void setInternetCafeName(String internetCafeName) {
2870        this.internetCafeName = internetCafeName;
2880    }
2890 
290     /**
291      * @return Returns the dataBasePath.
2920     */
293     public String getDataBasePath() {
2940        return dataBasePath;
2950    }
2960 
2970    /**
298      * @param dataBasePath
299      * The dataBasePath to set.
3000     */
3010    public void setDataBasePath(String dataBasePath) {
3020        this.dataBasePath = dataBasePath;
3030    }
3040 
305     /**
306      * @return Returns the documentImageDirectoryPath.
3070     */
308     public String getDocumentImageDirectoryPath() {
3090        return documentImageDirectoryPath;
3100    }
3110 
3120    /**
313      * @param documentImageDirectoryPath
314      * The documentImageDirectoryPath to set.
3150     */
3160    public void setDocumentImageDirectoryPath(String documentImageDirectoryPath) {
3170        this.documentImageDirectoryPath = documentImageDirectoryPath;
3180    }
3190 
3200    /**
321      * @return Returns the userImageDirectoryPath.
3220     */
323     public String getUserImageDirectoryPath() {
3240        return userImageDirectoryPath;
325     }
3260 
3270    /**
3280     * @param userImageDirectoryPath
329      * The userImageDirectoryPath to set.
3300     */
3310    public void setUserImageDirectoryPath(String userImageDirectoryPath) {
3320        this.userImageDirectoryPath = userImageDirectoryPath;
3330    }
3340 
335     /**
3360     * @return Returns the passwordProtect.
3370     */
338     public boolean isPasswordProtect() {
3390        return passwordProtect;
340     }
341  
3420    /**
3430     * @param passwordProtect
3440     * The passwordProtect to set.
3450     */
3460    public void setPasswordProtect(boolean passwordProtect) {
3470        logger.debug("Password Protect Setted To:" + passwordProtect);
3480        this.passwordProtect = passwordProtect;
3490    }
350  
3510    /**
3520     * @return Returns the automaticPasswordProtected.
3530     */
354     public boolean isAutomaticPasswordProtected() {
3550        return automaticPasswordProtected;
356     }
357  
3580    /**
3590     * @param automaticPasswordProtected
3600     * The automaticPasswordProtected to set.
3610     */
362     public void setAutomaticPasswordProtect(boolean automaticPasswordProtected) {
3630        logger.debug("Automatic Password Protect Setted To:"
3640                + automaticPasswordProtected);
3650        this.automaticPasswordProtected = automaticPasswordProtected;
3660    }
367  
3680    /**
3690     * @return Returns the internetCafeLookAndFeel.
3700     */
371     public Class getInternetCafeLookAndFeel() {
3720        return internetCafeLookAndFeel;
373     }
3740 
3750    /**
3760     * @param internetCafeLookAndFeel
3770     * The internetCafeLookAndFeel to set.
3780     */
3790    public void setInternetCafeLookAndFeel(Class internetCafeLookAndFeel) {
3800        this.internetCafeLookAndFeel = internetCafeLookAndFeel;
3810    }
382  
3830    /**
3840     * @return Returns the logoutScheduleRate.
3850     */
386     public int getLogoutScheduleRate() {
3870        return logoutScheduleRate;
388     }
389  
3900    /**
3910     * @param logoutScheduleRate
3920     * The logoutScheduleRate to set.
3930     */
394     public void setLogoutScheduleRate(int logoutScheduleRate) {
3950        logger.debug("Logout Schedule Rate Setted To:" + logoutScheduleRate
3960                + "(s)");
3970        this.logoutScheduleRate = logoutScheduleRate;
3980    }
3990 
4000    /**
401      * @return Returns the lastSeenUserWorking.
4020     */
403     public Date getLastSeenUserWorking() {
4040        return lastSeenUserWorking;
405     }
406  
407     /**
408      * @param lastSeenUserWorking
4090     * The lastSeenUserWorking to set.
4100     */
4110    public void setLastSeenUserWorking(Date lastSeenUserWorking) {
4120        this.lastSeenUserWorking = lastSeenUserWorking;
4130    }
414  
415     /**
416      * @return Returns the serverLoginDialog.
4170     */
4180    public ServerLoginDialog getServerLoginDialog() {
4190        if (serverLoginDialog == null) {
4200            serverLoginDialog = new ServerLoginDialog();
4210            serverLoginDialog.setModal(true);
4220        }
423  
4240        return serverLoginDialog;
425     }
426  
427     /**
428      * @return Returns the displayTipOfDay.
4290     */
430     public boolean isDisplayTipOfDay() {
4310        return displayTipOfDay;
432     }
433  
434     /**
435      * @param displayTipOfDay
436      * The displayTipOfDay to set.
4370     */
4380    public void setDisplayTipOfDay(boolean displayTipOfDay) {
4390        this.displayTipOfDay = displayTipOfDay;
4400    }
441  
442     /**
443      * @return Returns the htmlDirectoryPath.
4440     */
445     public String getHtmlDirectoryPath() {
4460        return htmlDirectoryPath;
447     }
448  
449     /**
450      * @return Returns the enableJDBS.
451      */
452     public boolean isJDBSEnabled() {
4530        return enableJDBS;
454     }
455 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.