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 | ||
21 | package ui.command.IO; | |
22 | ||
23 | import java.io.File; | |
24 | import java.io.FileInputStream; | |
25 | import java.io.FileNotFoundException; | |
26 | import java.io.FileOutputStream; | |
27 | import java.io.InputStream; | |
28 | import java.io.OutputStream; | |
29 | ||
30 | 0 | import javax.xml.parsers.DocumentBuilderFactory; |
31 | 0 | import javax.xml.transform.Transformer; |
32 | 0 | import javax.xml.transform.TransformerFactory; |
33 | import javax.xml.transform.dom.DOMSource; | |
34 | import javax.xml.transform.stream.StreamResult; | |
35 | 0 | import javax.xml.transform.stream.StreamSource; |
36 | ||
37 | 0 | import org.w3c.dom.Document; |
38 | 0 | import org.w3c.dom.Element; |
39 | 0 | |
40 | import ui.Messages; | |
41 | 0 | import ui.command.Command; |
42 | 0 | import base.ConfigurationManager; |
43 | import base.ICXmlTags; | |
44 | 0 | import base.IXMLSaveable; |
45 | 0 | import base.InternetCafe; |
46 | import base.InternetCafeManager; | |
47 | ||
48 | public class ExportUserListCommand extends Command { | |
49 | 0 | |
50 | 0 | private final IXMLSaveable[] data; |
51 | 0 | private InputStream xsltSource = null; |
52 | 0 | private InputStream cssSource = null; |
53 | 0 | private File outputDir = null; |
54 | 0 | |
55 | 0 | public ExportUserListCommand() { |
56 | 0 | super(); |
57 | 0 | try { |
58 | 0 | xsltSource = new FileInputStream(ConfigurationManager.getInstance().getHtmlDirectoryPath()+File.separatorChar+ConfigurationManager.USER_LIST_XSL_FILE_NAME); |
59 | 0 | cssSource = new FileInputStream(ConfigurationManager.getInstance().getHtmlDirectoryPath()+File.separatorChar+ConfigurationManager.USER_LIST_CSS_FILE_NAME); |
60 | 0 | } catch (FileNotFoundException e) { |
61 | 0 | // TODO Auto-generated catch block |
62 | 0 | e.printStackTrace(); |
63 | 0 | } |
64 | 0 | |
65 | 0 | this.data = InternetCafeManager.getInstance().getUser(); |
66 | 0 | } |
67 | 0 | |
68 | @Override | |
69 | 0 | protected void prologo() { |
70 | 0 | InternetCafe.setStatusBarMessage(Messages.getString("command.exportuserlistcommand.exportinguserlist")); //$NON-NLS-1$ |
71 | 0 | |
72 | 0 | javax.swing.JFileChooser chooser = new javax.swing.JFileChooser(); |
73 | 0 | chooser.setDialogTitle(Messages.getString("command.exportuserlistcommand.message1")); //$NON-NLS-1$ |
74 | 0 | chooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY); |
75 | 0 | chooser.setApproveButtonText(Messages.getString("button.select")); //$NON-NLS-1$ |
76 | 0 | chooser.setMultiSelectionEnabled(true); |
77 | 0 | |
78 | 0 | if (chooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION){ |
79 | 0 | outputDir = chooser.getSelectedFile(); |
80 | 0 | |
81 | 0 | setStatus(EXECUTE_STATUS); |
82 | 0 | } else |
83 | 0 | setStatus(ABORT_STATUS); |
84 | 0 | } |
85 | 0 | |
86 | @Override | |
87 | 0 | protected void execution() throws Exception { |
88 | 0 | switch (getStatus()) { |
89 | 0 | case ABORT_STATUS: |
90 | 0 | break; |
91 | 0 | case VETOED_STATUS: |
92 | 0 | break; |
93 | 0 | case EXECUTE_STATUS: |
94 | 0 | if (outputDir != null) { |
95 | 0 | Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); |
96 | 0 | Element userListElement = document.createElement(ICXmlTags.IC_USER_LIST_TAG); |
97 | 0 | for (int i = 0; i < data.length; i++) |
98 | 0 | userListElement.appendChild(data[i].toXml(document)); |
99 | 0 | document.appendChild(userListElement); |
100 | 0 | Transformer transformer = TransformerFactory.newInstance().newTransformer(); |
101 | 0 | DOMSource xmlSource = new DOMSource(document); |
102 | 0 | |
103 | 0 | TransformerFactory factory = TransformerFactory.newInstance(); |
104 | 0 | transformer = factory.newTransformer(new StreamSource(xsltSource)); |
105 | 0 | |
106 | 0 | OutputStream htmlOutput = new FileOutputStream(""+outputDir+File.separatorChar+ConfigurationManager.USER_LIST_HTML_FILE_NAME); //$NON-NLS-1$ |
107 | 0 | |
108 | 0 | transformer.transform(xmlSource,new StreamResult(htmlOutput)); |
109 | 0 | htmlOutput.close(); |
110 | 0 | xsltSource.close(); |
111 | 0 | |
112 | 0 | FileOutputStream cssOutput = new FileOutputStream(""+outputDir+File.separatorChar + ConfigurationManager.USER_LIST_CSS_FILE_NAME); //$NON-NLS-1$ |
113 | 0 | byte[] buff = new byte[1024]; |
114 | 0 | int l = 0; |
115 | 0 | while((l = cssSource.read(buff)) > 0){ |
116 | 0 | cssOutput.write(buff,0,l); |
117 | 0 | } |
118 | 0 | cssOutput.close(); |
119 | 0 | cssSource.close(); |
120 | 0 | |
121 | 0 | setStatus(SUCCESS_STATUS); |
122 | 0 | } else |
123 | 0 | setStatus(ERROR_STATUS); |
124 | break; | |
125 | 0 | } |
126 | 0 | |
127 | 0 | } |
128 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |