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 ui.command.IO; | |
21 | ||
22 | import java.io.File; | |
23 | import java.io.PrintStream; | |
24 | ||
25 | import javax.swing.JOptionPane; | |
26 | import javax.xml.parsers.DocumentBuilderFactory; | |
27 | import javax.xml.transform.Transformer; | |
28 | import javax.xml.transform.TransformerFactory; | |
29 | import javax.xml.transform.dom.DOMSource; | |
30 | import javax.xml.transform.stream.StreamResult; | |
31 | ||
32 | import org.apache.log4j.Logger; | |
33 | import org.w3c.dom.Document; | |
34 | ||
35 | import ui.Messages; | |
36 | import ui.command.Command; | |
37 | import ui.command.CommandExecutor; | |
38 | import base.ConfigurationManager; | |
39 | import base.InternetCafe; | |
40 | 0 | import base.InternetCafeManager; |
41 | 0 | |
42 | 0 | public class ExitCommand extends Command { |
43 | 0 | |
44 | 0 | private static final transient Logger logger = Logger |
45 | 0 | .getLogger(ExitCommand.class.getName()); |
46 | 0 | |
47 | 0 | private boolean saveChanges = true; |
48 | 0 | |
49 | 0 | public void prologo() { |
50 | 0 | InternetCafe.setStatusBarMessage(Messages.getString("command.exitcommand.exiting")); //$NON-NLS-1$ |
51 | 0 | Object[] options = { Messages.getString("command.option.exit.yesdiscard"), //$NON-NLS-1$ |
52 | 0 | Messages.getString("command.option.exit.yessaving"), Messages.getString("command.option.exit.cancel") }; //$NON-NLS-1$ //$NON-NLS-2$ |
53 | 0 | int result = JOptionPane.showOptionDialog(null, |
54 | 0 | Messages.getString("command.exitcommand.message1"), Messages.getString("common.exit"), //$NON-NLS-1$ //$NON-NLS-2$ |
55 | 0 | JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, |
56 | 0 | null, options, options[1]); |
57 | 0 | if (result == JOptionPane.YES_OPTION) { |
58 | 0 | saveChanges = false; |
59 | 0 | setStatus(EXECUTE_STATUS); |
60 | 0 | } else if (result == JOptionPane.NO_OPTION) { |
61 | 0 | saveChanges = true; |
62 | 0 | setStatus(EXECUTE_STATUS); |
63 | 0 | } else |
64 | 0 | setStatus(ABORT_STATUS); |
65 | 0 | } |
66 | 0 | |
67 | 0 | public void execution() throws Exception { |
68 | 0 | switch (getStatus()) { |
69 | 0 | case ABORT_STATUS: |
70 | 0 | break; |
71 | 0 | case VETOED_STATUS: |
72 | 0 | break; |
73 | 0 | case EXECUTE_STATUS: |
74 | 0 | if (saveChanges) { |
75 | 0 | try { |
76 | 0 | // Save the current configuration... |
77 | 0 | File configurationFile = new File( |
78 | 0 | ConfigurationManager.CONFIGURATION_FILE); |
79 | 0 | if (configurationFile.exists()) { |
80 | 0 | configurationFile.delete(); |
81 | 0 | configurationFile.createNewFile(); |
82 | 0 | } |
83 | 0 | Document doc = DocumentBuilderFactory.newInstance() |
84 | 0 | .newDocumentBuilder().newDocument(); |
85 | 0 | doc.appendChild(ConfigurationManager.getInstance().toXml( |
86 | 0 | doc)); |
87 | 0 | String fileName = configurationFile.getAbsolutePath(); |
88 | 0 | if (!fileName.endsWith("."+Messages.getString("common.filetype.xml"))) //$NON-NLS-1$ //$NON-NLS-2$ |
89 | 0 | fileName += "."+Messages.getString("common.filetype.xml"); //$NON-NLS-1$ //$NON-NLS-2$ |
90 | 0 | Transformer transformer = TransformerFactory.newInstance() |
91 | 0 | .newTransformer(); |
92 | 0 | DOMSource source = new DOMSource(doc); |
93 | 0 | StreamResult streamResult = new StreamResult( |
94 | 0 | new PrintStream(fileName)); |
95 | 0 | transformer.transform(source, streamResult); |
96 | 0 | |
97 | 0 | // We must save all to the database |
98 | 0 | InternetCafeManager.getInstance().store(); |
99 | 0 | |
100 | 0 | //If JDBS is integrated we must call its ExitCommand |
101 | 0 | CommandExecutor.getInstance().executeCommand(new base.jdbs.ui.command.ExitCommand(),true); |
102 | 0 | |
103 | 0 | setStatus(SUCCESS_STATUS); |
104 | 0 | System.exit(0); |
105 | 0 | } catch (Exception ex) { |
106 | 0 | logger.error(ex.getMessage()); |
107 | 0 | ex.printStackTrace(); |
108 | 0 | setStatus(ERROR_STATUS); |
109 | ||
110 | 0 | } |
111 | 0 | } else{ |
112 | 0 | setStatus(SUCCESS_STATUS); |
113 | 0 | System.exit(0); |
114 | } | |
115 | 0 | break; |
116 | 0 | } |
117 | 0 | } |
118 | 0 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |