Source Code Cross Referenced for CopyMessageCommand.java in  » Mail-Clients » columba-1.4 » org » columba » mail » folder » command » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Mail Clients » columba 1.4 » org.columba.mail.folder.command 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //The contents of this file are subject to the Mozilla Public License Version 1.1
002:        //(the "License"); you may not use this file except in compliance with the
003:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004:        //
005:        //Software distributed under the License is distributed on an "AS IS" basis,
006:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007:        //for the specific language governing rights and
008:        //limitations under the License.
009:        //
010:        //The Original Code is "The Columba Project"
011:        //
012:        //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014:        //
015:        //All Rights Reserved.
016:        package org.columba.mail.folder.command;
017:
018:        import java.io.IOException;
019:        import java.io.InputStream;
020:        import java.text.MessageFormat;
021:        import java.util.logging.Logger;
022:
023:        import javax.swing.JOptionPane;
024:
025:        import org.columba.api.command.ICommandReference;
026:        import org.columba.api.command.IWorkerStatusController;
027:        import org.columba.core.command.Command;
028:        import org.columba.core.command.StatusObservableImpl;
029:        import org.columba.core.command.Worker;
030:        import org.columba.core.gui.frame.FrameManager;
031:        import org.columba.mail.command.IMailFolderCommandReference;
032:        import org.columba.mail.folder.IMailbox;
033:        import org.columba.mail.util.MailResourceLoader;
034:        import org.columba.ristretto.message.Attributes;
035:        import org.columba.ristretto.message.Flags;
036:
037:        /**
038:         * Copy a set of messages from a source to a destination folder.
039:         * <p>
040:         * A dialog asks the user the destination folder.
041:         *
042:         * @author fdietz
043:         *
044:         */
045:        public class CopyMessageCommand extends Command {
046:
047:            /** JDK 1.4+ logging framework logger, used for logging. */
048:            private static final Logger LOG = Logger
049:                    .getLogger("org.columba.mail.folder.command");
050:
051:            protected IMailbox destFolder;
052:
053:            protected IMailFolderCommandReference r;
054:
055:            /**
056:             * Constructor for CopyMessageCommand.
057:             *
058:             * @param frameMediator
059:             * @param references
060:             */
061:            public CopyMessageCommand(ICommandReference reference) {
062:                super (reference);
063:            }
064:
065:            protected void doExecute(IWorkerStatusController worker,
066:                    String statusMessage, String errorRetryMessage,
067:                    String errorIgnoreMessage, String errorCopyMessage,
068:                    String errorTitle, String canceledMessage) throws Exception {
069:                // get references
070:                r = (IMailFolderCommandReference) getReference();
071:
072:                // get destination foldedr
073:                destFolder = (IMailbox) r.getDestinationFolder();
074:
075:                Object[] uids = r.getUids();
076:
077:                // get source folder
078:                IMailbox srcFolder = (IMailbox) r.getSourceFolder();
079:
080:                // register for status events
081:                ((StatusObservableImpl) srcFolder.getObservable())
082:                        .setWorker(worker);
083:
084:                // setting lastSelection for srcFolder to null
085:                srcFolder.setLastSelection(null);
086:
087:                LOG.fine("src=" + srcFolder + " dest=" + destFolder);
088:
089:                // update status message
090:                worker.setDisplayText(MessageFormat.format(MailResourceLoader
091:                        .getString("statusbar", "message", statusMessage),
092:                        new Object[] { destFolder.getName() }));
093:
094:                // initialize progress bar with total number of messages
095:                worker.setProgressBarMaximum(uids.length);
096:
097:                if (srcFolder.getRootFolder()
098:                        .equals(destFolder.getRootFolder())) {
099:                    // folders have same root folder
100:                    // -> for example: two IMAP folders on the same server
101:                    // -----> this means we use server-side copying which
102:                    // -----> is much faster than using inputstreams here
103:                    //
104:                    // also used for local folders, which saves some parsing work
105:                    srcFolder.innerCopy(destFolder, uids);
106:                } else {
107:                    // two different root folders
108:                    // -> get inputstream from source-folder and add it to
109:                    // -> destination-folder as inputstream
110:                    // -----> moving of raw message source
111:                    // (works also for copying from local to IMAP folders, etc.
112:                    for (int j = 0; (j < uids.length) && !worker.cancelled(); j++) {
113:                        if (!srcFolder.exists(uids[j])) {
114:                            continue;
115:                        }
116:
117:                        try {
118:                            // add source to destination folder
119:                            Attributes attributes = srcFolder
120:                                    .getAttributes(uids[j]);
121:                            Flags flags = srcFolder.getFlags(uids[j]);
122:                            InputStream messageSourceStream = srcFolder
123:                                    .getMessageSourceStream(uids[j]);
124:                            destFolder.addMessage(messageSourceStream,
125:                                    attributes, flags);
126:                            messageSourceStream.close();
127:                        } catch (IOException ioe) {
128:                            String[] options = new String[] {
129:                                    MailResourceLoader.getString("statusbar",
130:                                            "message", errorRetryMessage),
131:                                    MailResourceLoader.getString("statusbar",
132:                                            "message", errorIgnoreMessage),
133:                                    MailResourceLoader.getString("", "global",
134:                                            "cancel") };
135:
136:                            int result = JOptionPane
137:                                    .showOptionDialog(FrameManager
138:                                            .getInstance().getActiveFrame(),
139:                                            MailResourceLoader.getString(
140:                                                    "statusbar", "message",
141:                                                    errorCopyMessage),
142:                                            MailResourceLoader.getString(
143:                                                    "statusbar", "message",
144:                                                    errorTitle),
145:                                            JOptionPane.YES_NO_CANCEL_OPTION,
146:                                            JOptionPane.ERROR_MESSAGE, null,
147:                                            options, options[0]);
148:                            switch (result) {
149:                            case JOptionPane.YES_OPTION:
150:
151:                                //retry copy
152:                                j--;
153:
154:                                break;
155:
156:                            case JOptionPane.CANCEL_OPTION:
157:                                worker.cancel();
158:
159:                            default:
160:
161:                                continue;
162:                            }
163:                        }
164:
165:                        // update progress bar
166:                        worker.setProgressBarValue(j);
167:                    }
168:                }
169:
170:                //reset progress bar
171:                worker.setProgressBarValue(0);
172:
173:                if (worker.cancelled()) {
174:                    worker.setDisplayText(MailResourceLoader.getString(
175:                            "statusbar", "message", canceledMessage));
176:                } else {
177:                    // We are done - clear the status message with a delay
178:                    worker.clearDisplayTextWithDelay();
179:                }
180:
181:            }
182:
183:            /**
184:             * @see org.columba.api.command.Command#execute(Worker)
185:             */
186:            public void execute(IWorkerStatusController worker)
187:                    throws Exception {
188:                doExecute(worker, "copy_messages", "err_copy_messages_retry",
189:                        "err_copy_messages_ignore", "err_copy_messages_msg",
190:                        "err_copy_messages_title", "copy_messages_cancelled");
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.