Coverage details for ui.command.IO.ExportUserAsVCardCommand

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 ui.command.IO;
21  
220import java.io.File;
23 import java.io.FileWriter;
24 import java.io.Writer;
250 
260import org.apache.log4j.Logger;
27  
28 import ui.Messages;
29 import ui.command.Command;
30 import base.InternetCafe;
310import base.user.User;
320import base.user.jcard.JCard;
330 
34  
35  public class ExportUserAsVCardCommand extends Command {
36   
370 private static final transient Logger logger = Logger.getLogger(ExportUserAsVCardCommand.class.getName());
380 
390 private final User user;
400 private File vCardFile = null;
410 
420    public ExportUserAsVCardCommand(User user) {
430        this.user = user;
440    }
450 
460    /*
470     * (non-Javadoc)
480     *
490     * @see ui.command.Command#prologo()
500     */
510    @Override
520    protected void prologo() {
530        InternetCafe
540                .setStatusBarMessage(Messages
550                        .getString("command.exportuserasvcardcommand.exportinguserasvcard")); //$NON-NLS-1$
560        javax.swing.JFileChooser repositoryChooser = new javax.swing.JFileChooser();
570        repositoryChooser.setDialogTitle(Messages
580                .getString("command.exportuserasvcardcommand.message1")); //$NON-NLS-1$
590        repositoryChooser
600                .setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
610        repositoryChooser.setApproveButtonText(Messages
620                .getString("button.select")); //$NON-NLS-1$
630        repositoryChooser.setMultiSelectionEnabled(true);
640 
650        if (repositoryChooser.showOpenDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION) {
660            File outputDirectory = repositoryChooser.getSelectedFile();
670            File vCardFile = new File(
680                    outputDirectory.getAbsolutePath()
690                            + File.separatorChar
700                            + user.getName()
710                            + " " + user.getSurname() + "." + Messages.getString("common.filetype.vcard")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
720            logger.debug("Output directory: " + outputDirectory); //$NON-NLS-1$
730            logger.debug("vCard file: " + vCardFile); //$NON-NLS-1$
740            setStatus(EXECUTE_STATUS);
750        } else
760            setStatus(ABORT_STATUS);
770    }
780 
79     /*
80      * (non-Javadoc)
810     *
820     * @see ui.command.Command#execution()
830     */
840    @Override
850    protected void execution() throws Exception {
860        switch (getStatus()) {
870        case ERROR_STATUS:
880            break;
890        case VETOED_STATUS:
900            break;
910        case EXECUTE_STATUS:
920            JCard jcard = new JCard();
930            Writer writer = new FileWriter(vCardFile);
940            jcard.newJCard(this.user).write(writer);
950            writer.close();
960            setStatus(SUCCESS_STATUS);
970            break;
98         }
990    }
1000}

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.