KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > gui > message > command > SaveAttachmentTemporaryCommand


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//limitations under the License.
9
//
10
//The Original Code is "The Columba Project"
11
//
12
//The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
//
15
//All Rights Reserved.
16
package org.columba.mail.gui.message.command;
17
18 import java.io.File JavaDoc;
19 import java.util.logging.Logger JavaDoc;
20
21 import org.columba.api.command.ICommandReference;
22 import org.columba.api.command.IWorkerStatusController;
23 import org.columba.core.base.Semaphore;
24 import org.columba.core.util.TempFileStore;
25 import org.columba.ristretto.message.MimeHeader;
26
27
28 /**
29  * A command that saves an attachment to a temp folder.
30  *
31  * @author redsolo
32  */

33 public class SaveAttachmentTemporaryCommand extends SaveAttachmentCommand {
34
35     private static final Logger JavaDoc LOG = Logger.getLogger("org.columba.mail.gui.message.attachment.command");
36
37     /** The file that the attachment was saved too. */
38     private File JavaDoc tempAttachmentFile;
39
40     private Semaphore commandSemaphore;
41
42     /**
43      * @param reference Command reference.
44      */

45     public SaveAttachmentTemporaryCommand(ICommandReference reference) {
46         super(reference);
47         commandSemaphore = new Semaphore(true);
48     }
49
50     /** {@inheritDoc} */
51     protected File JavaDoc getDestinationFile(MimeHeader header) {
52
53         tempAttachmentFile = null;
54         String JavaDoc filename = getFilename(header);
55         if (filename != null) {
56             tempAttachmentFile = TempFileStore.createTempFile(filename);
57         }
58         return tempAttachmentFile;
59     }
60
61     /** {@inheritDoc} */
62     public void execute(IWorkerStatusController worker) throws Exception JavaDoc {
63         super.execute(worker);
64         commandSemaphore.release();
65     }
66
67     /**
68      * Returns the temporary file that the attachment was saved to.
69      * If its null, then the file hasnt been saved.
70      * @return Returns the tempAttachmentFile.
71      */

72     public File JavaDoc getTempAttachmentFile() {
73         return tempAttachmentFile;
74     }
75
76     /**
77      * Waits until the command has completed saving the file to the temporary folder.
78      */

79     public void waitForCommandToComplete() {
80         try {
81             commandSemaphore.waitUntilReleased();
82         } catch (InterruptedException JavaDoc e) {
83             LOG.warning("The thread waiting for the Save Attachment Temporary command was interrupted.");
84         }
85     }
86 }
87
Popular Tags