| 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.awt.Dimension; | |
| 23 | import java.awt.Toolkit; | |
| 24 | import java.io.File; | |
| 25 | import java.io.FileInputStream; | |
| 26 | import java.io.PrintStream; | |
| 27 | ||
| 28 | import javax.swing.UIManager; | |
| 29 | import javax.xml.parsers.DocumentBuilder; | |
| 30 | import javax.xml.parsers.DocumentBuilderFactory; | |
| 31 | import javax.xml.transform.Transformer; | |
| 32 | import javax.xml.transform.TransformerFactory; | |
| 33 | import javax.xml.transform.dom.DOMSource; | |
| 34 | import javax.xml.transform.stream.StreamResult; | |
| 35 | ||
| 36 | import org.apache.log4j.Logger; | |
| 37 | import org.apache.log4j.xml.DOMConfigurator; | |
| 38 | import org.w3c.dom.Document; | |
| 39 | ||
| 40 | import ui.ICToolBar; | |
| 41 | import ui.frame.ICMainFrame; | |
| 42 | import ui.frame.MessageFrame; | |
| 43 | import ui.panel.StatusBarPanel; | |
| 44 | import ui.util.GeneralUtil; | |
| 45 | import ui.util.LogoutDaemon; | |
| 46 | 0 | import base.jdbs.JDBSConstant; |
| 47 | 0 | import base.jdbs.ui.dialog.RepositorySetupDialog; |
| 48 | 0 | import base.user.User; |
| 49 | 0 | |
| 50 | 0 | public class InternetCafe { |
| 51 | 0 | private static final transient Logger logger = Logger |
| 52 | 0 | .getLogger(InternetCafe.class.getName()); |
| 53 | 0 | |
| 54 | 0 | private static InternetCafe instance = null; |
| 55 | 0 | |
| 56 | 0 | private static StatusBarPanel statusBar; |
| 57 | ||
| 58 | 0 | private static ICToolBar toolBar; |
| 59 | ||
| 60 | 0 | boolean packFrame = false; |
| 61 | 0 | |
| 62 | 0 | private ICMainFrame frame; |
| 63 | 0 | |
| 64 | 0 | // Construct the application |
| 65 | 0 | public InternetCafe() { |
| 66 | 0 | // Validate frames that have preset sizes |
| 67 | 0 | // Pack frames that have useful preferred size info, e.g. from their |
| 68 | 0 | // layout |
| 69 | 0 | if (packFrame) { |
| 70 | 0 | getMainFrame().pack(); |
| 71 | 0 | } else { |
| 72 | 0 | getMainFrame().validate(); |
| 73 | 0 | } |
| 74 | 0 | |
| 75 | 0 | // Set the application Look And Feel |
| 76 | try { | |
| 77 | 0 | UIManager.setLookAndFeel(base.ConfigurationManager.getInstance().getInternetCafeLookAndFeel().getCanonicalName()); |
| 78 | 0 | } catch (Exception ex) { |
| 79 | 0 | // TODO Auto-generated catch block |
| 80 | 0 | logger.error(ex.getMessage()); |
| 81 | 0 | ex.printStackTrace(); |
| 82 | 0 | } |
| 83 | 0 | |
| 84 | // Center the window | |
| 85 | 0 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
| 86 | 0 | Dimension frameSize = getMainFrame().getSize(); |
| 87 | 0 | |
| 88 | 0 | frameSize.height = screenSize.height; |
| 89 | 0 | frameSize.width = screenSize.width; |
| 90 | 0 | getMainFrame().setLocation((screenSize.width - frameSize.width) / 2, |
| 91 | 0 | (screenSize.height - frameSize.height) / 2); |
| 92 | 0 | getMainFrame().setVisible(true); |
| 93 | 0 | } |
| 94 | 0 | |
| 95 | 0 | public static synchronized InternetCafe getInstance() { |
| 96 | 0 | return (instance == null) ? (instance = new InternetCafe()) : instance; |
| 97 | 0 | } |
| 98 | 0 | |
| 99 | 0 | public ICMainFrame getMainFrame() { |
| 100 | 0 | if (frame == null) { |
| 101 | 0 | frame = new ICMainFrame(); |
| 102 | 0 | } |
| 103 | 0 | |
| 104 | 0 | return frame; |
| 105 | 0 | } |
| 106 | 0 | |
| 107 | 0 | public static synchronized StatusBarPanel getStatusBar() { |
| 108 | 0 | if (statusBar == null) { |
| 109 | 0 | statusBar = new StatusBarPanel(); |
| 110 | 0 | } |
| 111 | 0 | |
| 112 | 0 | return statusBar; |
| 113 | 0 | } |
| 114 | 0 | |
| 115 | public static ICToolBar getToolBar() { | |
| 116 | 0 | if (toolBar == null) { |
| 117 | 0 | toolBar = new ICToolBar(); |
| 118 | 0 | } |
| 119 | 0 | |
| 120 | 0 | return toolBar; |
| 121 | 0 | } |
| 122 | 0 | |
| 123 | 0 | /** |
| 124 | 0 | * @param message |
| 125 | 0 | * A new message to show on the status bar. |
| 126 | 0 | */ |
| 127 | 0 | public static synchronized void setStatusBarMessage(String message) { |
| 128 | 0 | getStatusBar().setMessage(message); |
| 129 | 0 | } |
| 130 | 0 | |
| 131 | 0 | protected static void initInternetCafe() { |
| 132 | 0 | try { |
| 133 | 0 | // This will setUp the message logging... MUST BE PLACED HERE |
| 134 | 0 | MessageFrame.getInstance(); |
| 135 | 0 | logger.info(ConfigurationManager.COPYRIGHT); |
| 136 | 0 | logger.debug("Setting Up configuration..."); |
| 137 | 0 | |
| 138 | 0 | File resourcesDirectory = new File( |
| 139 | 0 | base.ConfigurationManager.RESOURCES_DIRECTORY); |
| 140 | 0 | |
| 141 | 0 | if (!resourcesDirectory.exists() |
| 142 | 0 | || !resourcesDirectory.isDirectory()) { |
| 143 | 0 | resourcesDirectory.mkdir(); |
| 144 | 0 | } |
| 145 | 0 | |
| 146 | 0 | File configurationFile = new File( |
| 147 | 0 | base.ConfigurationManager.CONFIGURATION_FILE); |
| 148 | 0 | |
| 149 | 0 | if (configurationFile.exists()) { // Read It! |
| 150 | 0 | logger.debug("Reading Internet Cafe's Configuration File..."); |
| 151 | 0 | |
| 152 | 0 | DocumentBuilderFactory factory = DocumentBuilderFactory |
| 153 | 0 | .newInstance(); |
| 154 | 0 | |
| 155 | 0 | factory.setIgnoringComments(true); |
| 156 | 0 | factory.setValidating(false); |
| 157 | 0 | factory.setIgnoringElementContentWhitespace(true); |
| 158 | 0 | |
| 159 | 0 | DocumentBuilder docBuilder = factory.newDocumentBuilder(); |
| 160 | 0 | |
| 161 | 0 | Document document = docBuilder.parse(new FileInputStream( |
| 162 | 0 | configurationFile)); |
| 163 | 0 | |
| 164 | 0 | base.ConfigurationManager.getInstance().fromXml(document); |
| 165 | 0 | } else { // Write It! |
| 166 | 0 | |
| 167 | 0 | Document doc = DocumentBuilderFactory.newInstance() |
| 168 | 0 | .newDocumentBuilder().newDocument(); |
| 169 | 0 | |
| 170 | 0 | doc.appendChild(base.ConfigurationManager.getInstance().toXml(doc)); |
| 171 | 0 | |
| 172 | 0 | String fileName = configurationFile.getAbsolutePath(); |
| 173 | 0 | |
| 174 | 0 | if (!fileName.endsWith(".xml")) { |
| 175 | 0 | fileName += ".xml"; |
| 176 | 0 | } |
| 177 | 0 | |
| 178 | 0 | Transformer transformer = TransformerFactory.newInstance() |
| 179 | 0 | .newTransformer(); |
| 180 | 0 | DOMSource source = new DOMSource(doc); |
| 181 | 0 | StreamResult streamResult = new StreamResult(new PrintStream( |
| 182 | 0 | fileName)); |
| 183 | 0 | |
| 184 | 0 | transformer.transform(source, streamResult); |
| 185 | 0 | } |
| 186 | 0 | } catch (Exception ex) { |
| 187 | 0 | logger.error(ex.getMessage()); |
| 188 | 0 | ex.printStackTrace(); |
| 189 | 0 | } |
| 190 | 0 | } |
| 191 | 0 | |
| 192 | protected static void initLogin(){ | |
| 193 | try { | |
| 194 | 0 | Thread configurationThread = new Thread() { |
| 195 | 0 | public void run() { |
| 196 | ||
| 197 | 0 | InternetCafeManager.getInstance().retrieve(); |
| 198 | 0 | |
| 199 | // InternetCafeManager.getInstance().getServer().start(); | |
| 200 | if (base.ConfigurationManager.getInstance().isPasswordProtect()) { | |
| 201 | base.ConfigurationManager.getInstance() | |
| 202 | .getServerLoginDialog().setVisible(true); | |
| 203 | } | |
| 204 | ||
| 205 | 0 | if (base.ConfigurationManager.getInstance() |
| 206 | 0 | .isAutomaticPasswordProtected()) { |
| 207 | 0 | new LogoutDaemon(base.ConfigurationManager.getInstance() |
| 208 | 0 | .getLogoutScheduleRate()); |
| 209 | 0 | } |
| 210 | 0 | |
| 211 | 0 | } |
| 212 | 0 | }; |
| 213 | 0 | |
| 214 | 0 | configurationThread.start(); |
| 215 | 0 | configurationThread.join(); |
| 216 | 0 | } catch (InterruptedException e) { |
| 217 | 0 | logger.error(e.getMessage()); |
| 218 | 0 | e.printStackTrace(); |
| 219 | 0 | } |
| 220 | 0 | } |
| 221 | 0 | |
| 222 | protected static void initJDBS(User user) { | |
| 223 | try { | |
| 224 | 0 | // First of all we must load the JDBS configurations. |
| 225 | 0 | File configurationFile = new File( |
| 226 | 0 | JDBSConstant.JDBS_CONFIGURATION_FILE); |
| 227 | ||
| 228 | 0 | if (configurationFile.exists()) { // Read It! |
| 229 | 0 | logger.info("Configuration file : " + configurationFile |
| 230 | 0 | + " found. Loading configurations from it..."); |
| 231 | 0 | base.jdbs.ConfigurationManager.loadConfiguration(); |
| 232 | 0 | } else { |
| 233 | 0 | logger.info("Setting up the JDBS's user..."); |
| 234 | 0 | |
| 235 | 0 | base.jdbs.ConfigurationManager.getInstance().setUser(user); |
| 236 | 0 | |
| 237 | 0 | logger.info("Setting up the JDBS's repository..."); |
| 238 | 0 | RepositorySetupDialog repositorySetupDialog = new RepositorySetupDialog(); |
| 239 | 0 | repositorySetupDialog.setModal(true); |
| 240 | 0 | GeneralUtil.centerComponent(repositorySetupDialog); |
| 241 | 0 | repositorySetupDialog.setVisible(true); |
| 242 | 0 | |
| 243 | 0 | base.jdbs.ConfigurationManager.saveConfiguration(); |
| 244 | 0 | } |
| 245 | 0 | } catch (Exception e) { |
| 246 | 0 | logger.error(e.getMessage()); |
| 247 | 0 | e.printStackTrace(); |
| 248 | 0 | } |
| 249 | 0 | |
| 250 | 0 | if (base.jdbs.ConfigurationManager.getInstance().getRepository().getLocation() |
| 251 | 0 | .exists()) { |
| 252 | 0 | logger.info("Indexing the JDBS's repository..."); |
| 253 | 0 | base.jdbs.ConfigurationManager.getInstance().getRepository() |
| 254 | 0 | .indexRepository(); |
| 255 | } | |
| 256 | 0 | } |
| 257 | 0 | |
| 258 | //Main method | |
| 259 | public static void main(String[] arg) { | |
| 260 | //Log4j init | |
| 261 | 0 | DOMConfigurator.configure("log4jConfiguration.xml"); |
| 262 | 0 | |
| 263 | 0 | initInternetCafe(); |
| 264 | 0 | initLogin(); |
| 265 | 0 | if(ConfigurationManager.getInstance().isJDBSEnabled())initJDBS(base.ConfigurationManager.getInstance().getServerLoginDialog().getLoggedInUser()); |
| 266 | 0 | |
| 267 | 0 | new InternetCafe(); |
| 268 | 0 | } |
| 269 | 0 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |