Source Code Cross Referenced for AbstractMailboxImporter.java in  » Mail-Clients » columba-1.4 » org » columba » mail » folder » mailboximport » 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.mailboximport 
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:
017:        package org.columba.mail.folder.mailboximport;
018:
019:        import java.io.File;
020:
021:        import javax.swing.JOptionPane;
022:
023:        import org.columba.api.command.IWorkerStatusController;
024:        import org.columba.api.plugin.IExtensionInterface;
025:        import org.columba.core.gui.frame.FrameManager;
026:        import org.columba.core.resourceloader.IconKeys;
027:        import org.columba.core.resourceloader.ImageLoader;
028:        import org.columba.mail.folder.IMailbox;
029:        import org.columba.ristretto.io.CharSequenceSource;
030:        import org.columba.ristretto.io.SourceInputStream;
031:
032:        /**
033:         * This is the base class for mailbox importers.
034:         */
035:        public abstract class AbstractMailboxImporter implements 
036:                IExtensionInterface {
037:            public static final int TYPE_FILE = 0;
038:            public static final int TYPE_DIRECTORY = 1;
039:
040:            protected IMailbox destinationFolder;
041:            protected File[] sourceFiles;
042:            protected int counter = 0;
043:
044:            public AbstractMailboxImporter(IMailbox destinationFolder,
045:                    File[] sourceFiles) {
046:                this ();
047:                setDestinationFolder(destinationFolder);
048:                setSourceFiles(sourceFiles);
049:            }
050:
051:            /**
052:             * Default constructor
053:             */
054:            public AbstractMailboxImporter() {
055:            }
056:
057:            /**
058:             * Override this method to specify type.
059:             * the wizard dialog will open the correct file/directory dialog automatically
060:             */
061:            public int getType() {
062:                return TYPE_FILE;
063:            }
064:
065:            /**
066:             * Override this method to do the actual import work. In here, the messages
067:             * should be read and passed to the folder using saveMessage.
068:             */
069:            public abstract void importMailboxFile(File file,
070:                    IWorkerStatusController worker, IMailbox destFolder)
071:                    throws Exception;
072:
073:            /**
074:             * Override this method to provide an adequate description to the user.
075:             */
076:            public abstract String getDescription();
077:
078:            /*********** intern methods (no need to overwrite these) ****************/
079:            /**
080:             * Sets the source files/directories.
081:             */
082:            public void setSourceFiles(File[] files) {
083:                this .sourceFiles = files;
084:            }
085:
086:            /**
087:             * Set the destination folder.
088:             */
089:            public void setDestinationFolder(IMailbox folder) {
090:                destinationFolder = folder;
091:            }
092:
093:            /**
094:             * Returns the number of successfully imported messages so far.
095:             */
096:            public int getCount() {
097:                return counter;
098:            }
099:
100:            /**
101:             * This method calls your overridden importMailbox(File)-method
102:             * and handles exceptions.
103:             */
104:            public void run(IWorkerStatusController worker) {
105:                //TODO (@author fdietz): i18n
106:                worker.setDisplayText("Importing messages...");
107:
108:                importMailbox(worker);
109:
110:                if (getCount() == 0) {
111:                    //TODO (@author fdietz): i18n
112:                    JOptionPane
113:                            .showMessageDialog(
114:                                    FrameManager.getInstance().getActiveFrame(),
115:                                    "Message import failed! No messages were added to the folder.\n"
116:                                            + "This means that the parser didn't throw any exception even if "
117:                                            + "it didn't recognize the mailbox format or the messagebox simply "
118:                                            + "didn't contain any messages.",
119:                                    "Warning", JOptionPane.WARNING_MESSAGE);
120:
121:                    return;
122:                } else {
123:                    //TODO (@author fdietz): i18n
124:                    JOptionPane.showMessageDialog(null,
125:                            "Message import was successful!", "Information",
126:                            JOptionPane.INFORMATION_MESSAGE, ImageLoader
127:                                    .getIcon(IconKeys.DIALOG_INFO));
128:                }
129:            }
130:
131:            /**
132:             * Import all mailbox files in Columba. This method makes use of the
133:             * importMailbox method you have to override and simply iterates over all
134:             * given files/directories.
135:             *
136:             * @param worker
137:             */
138:            public void importMailbox(IWorkerStatusController worker) {
139:                File[] listing = getSourceFiles();
140:
141:                for (int i = 0; i < listing.length; i++) {
142:                    if (worker.cancelled()) {
143:                        return;
144:                    }
145:
146:                    try {
147:                        importMailboxFile(listing[i], worker,
148:                                getDestinationFolder());
149:                    } catch (Exception ex) {
150:                        //TODO (@author fdietz): i18n
151:                        int result = JOptionPane
152:                                .showConfirmDialog(
153:                                        FrameManager.getInstance()
154:                                                .getActiveFrame(),
155:                                        "An error occured while importing a message. Try again?",
156:                                        "Retry message import?",
157:                                        JOptionPane.YES_NO_CANCEL_OPTION,
158:                                        JOptionPane.WARNING_MESSAGE);
159:                        if (result == JOptionPane.YES_OPTION) {
160:                            i--;
161:                        } else if (result == JOptionPane.CANCEL_OPTION) {
162:                            worker.cancel();
163:                        }
164:                    }
165:                }
166:            }
167:
168:            /**
169:             * Use this method to save a message in the specified destination folder.
170:             */
171:            protected void saveMessage(String rawString,
172:                    IWorkerStatusController worker, IMailbox destFolder)
173:                    throws Exception {
174:                /*
175:                 * *20031231, karlpeder* Using InputStream instead of rawString
176:                 * directly. Ensures size is set correctly by addMessage (bug #843657)
177:                 */
178:
179:                SourceInputStream in = new SourceInputStream(
180:                        new CharSequenceSource(rawString));
181:                destFolder.addMessage(in);
182:                in.close();
183:
184:                counter++;
185:
186:                //TODO (@author fdietz): i18n
187:                worker.setDisplayText("Importing messages: " + getCount());
188:            }
189:
190:            /**
191:             * Returns the folder new messages will be added to.
192:             */
193:            public IMailbox getDestinationFolder() {
194:                return destinationFolder;
195:            }
196:
197:            /**
198:             * Returns the source files/directories new messages will be read from.
199:             */
200:            public File[] getSourceFiles() {
201:                return sourceFiles;
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.