01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
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;
19: import java.util.logging.Logger;
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: * A command that saves an attachment to a temp folder.
29: *
30: * @author redsolo
31: */
32: public class SaveAttachmentTemporaryCommand extends
33: SaveAttachmentCommand {
34:
35: private static final Logger LOG = Logger
36: .getLogger("org.columba.mail.gui.message.attachment.command");
37:
38: /** The file that the attachment was saved too. */
39: private File tempAttachmentFile;
40:
41: private Semaphore commandSemaphore;
42:
43: /**
44: * @param reference Command reference.
45: */
46: public SaveAttachmentTemporaryCommand(ICommandReference reference) {
47: super (reference);
48: commandSemaphore = new Semaphore(true);
49: }
50:
51: /** {@inheritDoc} */
52: protected File getDestinationFile(MimeHeader header) {
53:
54: tempAttachmentFile = null;
55: String filename = getFilename(header);
56: if (filename != null) {
57: tempAttachmentFile = TempFileStore.createTempFile(filename);
58: }
59: return tempAttachmentFile;
60: }
61:
62: /** {@inheritDoc} */
63: public void execute(IWorkerStatusController worker)
64: throws Exception {
65: super .execute(worker);
66: commandSemaphore.release();
67: }
68:
69: /**
70: * Returns the temporary file that the attachment was saved to.
71: * If its null, then the file hasnt been saved.
72: * @return Returns the tempAttachmentFile.
73: */
74: public File getTempAttachmentFile() {
75: return tempAttachmentFile;
76: }
77:
78: /**
79: * Waits until the command has completed saving the file to the temporary folder.
80: */
81: public void waitForCommandToComplete() {
82: try {
83: commandSemaphore.waitUntilReleased();
84: } catch (InterruptedException e) {
85: LOG
86: .warning("The thread waiting for the Save Attachment Temporary command was interrupted.");
87: }
88: }
89: }
|