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 | 0 | import java.io.File; |
23 | import java.io.FileWriter; | |
24 | import java.io.Writer; | |
25 | 0 | |
26 | 0 | import org.apache.log4j.Logger; |
27 | ||
28 | import ui.Messages; | |
29 | import ui.command.Command; | |
30 | import base.InternetCafe; | |
31 | 0 | import base.user.User; |
32 | 0 | import base.user.jcard.JCard; |
33 | 0 | |
34 | ||
35 | public class ExportUserAsVCardCommand extends Command { | |
36 | ||
37 | 0 | private static final transient Logger logger = Logger.getLogger(ExportUserAsVCardCommand.class.getName()); |
38 | 0 | |
39 | 0 | private final User user; |
40 | 0 | private File vCardFile = null; |
41 | 0 | |
42 | 0 | public ExportUserAsVCardCommand(User user) { |
43 | 0 | this.user = user; |
44 | 0 | } |
45 | 0 | |
46 | 0 | /* |
47 | 0 | * (non-Javadoc) |
48 | 0 | * |
49 | 0 | * @see ui.command.Command#prologo() |
50 | 0 | */ |
51 | 0 | @Override |
52 | 0 | protected void prologo() { |
53 | 0 | InternetCafe |
54 | 0 | .setStatusBarMessage(Messages |
55 | 0 | .getString("command.exportuserasvcardcommand.exportinguserasvcard")); //$NON-NLS-1$ |
56 | 0 | javax.swing.JFileChooser repositoryChooser = new javax.swing.JFileChooser(); |
57 | 0 | repositoryChooser.setDialogTitle(Messages |
58 | 0 | .getString("command.exportuserasvcardcommand.message1")); //$NON-NLS-1$ |
59 | 0 | repositoryChooser |
60 | 0 | .setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY); |
61 | 0 | repositoryChooser.setApproveButtonText(Messages |
62 | 0 | .getString("button.select")); //$NON-NLS-1$ |
63 | 0 | repositoryChooser.setMultiSelectionEnabled(true); |
64 | 0 | |
65 | 0 | if (repositoryChooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION) { |
66 | 0 | File outputDirectory = repositoryChooser.getSelectedFile(); |
67 | 0 | File vCardFile = new File( |
68 | 0 | outputDirectory.getAbsolutePath() |
69 | 0 | + File.separatorChar |
70 | 0 | + user.getName() |
71 | 0 | + " " + user.getSurname() + "." + Messages.getString("common.filetype.vcard")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
72 | 0 | logger.debug("Output directory: " + outputDirectory); //$NON-NLS-1$ |
73 | 0 | logger.debug("vCard file: " + vCardFile); //$NON-NLS-1$ |
74 | 0 | setStatus(EXECUTE_STATUS); |
75 | 0 | } else |
76 | 0 | setStatus(ABORT_STATUS); |
77 | 0 | } |
78 | 0 | |
79 | /* | |
80 | * (non-Javadoc) | |
81 | 0 | * |
82 | 0 | * @see ui.command.Command#execution() |
83 | 0 | */ |
84 | 0 | @Override |
85 | 0 | protected void execution() throws Exception { |
86 | 0 | switch (getStatus()) { |
87 | 0 | case ERROR_STATUS: |
88 | 0 | break; |
89 | 0 | case VETOED_STATUS: |
90 | 0 | break; |
91 | 0 | case EXECUTE_STATUS: |
92 | 0 | JCard jcard = new JCard(); |
93 | 0 | Writer writer = new FileWriter(vCardFile); |
94 | 0 | jcard.newJCard(this.user).write(writer); |
95 | 0 | writer.close(); |
96 | 0 | setStatus(SUCCESS_STATUS); |
97 | 0 | break; |
98 | } | |
99 | 0 | } |
100 | 0 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |