Source Code Cross Referenced for FolderFactory.java in  » Mail-Clients » columba-1.4 » org » columba » mail » folder » 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 
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;
018:
019:        import java.util.Enumeration;
020:        import java.util.LinkedList;
021:        import java.util.List;
022:        import java.util.regex.Matcher;
023:        import java.util.regex.Pattern;
024:
025:        import org.columba.api.plugin.ExtensionMetadata;
026:        import org.columba.api.plugin.IExtension;
027:        import org.columba.api.plugin.IExtensionHandler;
028:        import org.columba.api.plugin.PluginHandlerNotFoundException;
029:        import org.columba.core.plugin.PluginManager;
030:        import org.columba.mail.config.AccountItem;
031:        import org.columba.mail.config.IFolderItem;
032:        import org.columba.mail.config.MailConfig;
033:        import org.columba.mail.folder.imap.IMAPFolder;
034:        import org.columba.mail.folder.imap.IMAPRootFolder;
035:        import org.columba.mail.gui.tree.FolderTreeModel;
036:        import org.columba.mail.plugin.IExtensionHandlerKeys;
037:
038:        /**
039:         * Factory for creating subfolders. Implemented as a singelton. Use
040:         * {@link #getInstance()}.
041:         *
042:         * @author Timo Stich <tstich@users.sourceforge.net>
043:         */
044:        public class FolderFactory {
045:            // Groups are separated by at least one WS character
046:            private static final Pattern groupPattern = Pattern
047:                    .compile("([^\\s]+)\\s*");
048:
049:            private static FolderFactory instance;
050:
051:            private IExtensionHandler handler;
052:
053:            // parent directory for mail folders
054:            // for example: ".columba/mail/"
055:            private String path = MailConfig.getInstance().getConfigDirectory()
056:                    .getPath();
057:
058:            protected FolderFactory() throws PluginHandlerNotFoundException {
059:                // Get the handler
060:                handler = PluginManager.getInstance().getExtensionHandler(
061:                        IExtensionHandlerKeys.ORG_COLUMBA_MAIL_FOLDER);
062:
063:            }
064:
065:            /**
066:             * Singleton - pattern
067:             *
068:             * @return the instance of the factory
069:             */
070:            public static FolderFactory getInstance() {
071:                if (instance == null) {
072:                    try {
073:                        instance = new FolderFactory();
074:                    } catch (PluginHandlerNotFoundException phnfe) {
075:                        throw new RuntimeException(phnfe);
076:                    }
077:                }
078:                return instance;
079:            }
080:
081:            /**
082:             * Gets a list of all possible child foldertypes.
083:             *
084:             * @param parent
085:             * @return a list that contains Strings of foldertypes
086:             */
087:            public List getPossibleChilds(IMailFolder parent) {
088:                List list = new LinkedList();
089:
090:                // which parents are possible ?
091:                IFolderItem item = parent.getConfiguration();
092:                String parentType = item.get("type");
093:
094:                // the group of the given parent
095:                String parentGroup = getGroup(parentType);
096:
097:                // iterate through all foldertypes to find suitable ones
098:                Enumeration e = handler.getExtensionEnumeration();
099:                while (e.hasMoreElements()) {
100:                    IExtension extension = (IExtension) e.nextElement();
101:                    ExtensionMetadata metadata = (ExtensionMetadata) extension
102:                            .getMetadata();
103:                    String possibleParents = metadata
104:                            .getAttribute("possible_parents");
105:                    String id = metadata.getId();
106:
107:                    if (possibleParents != null) {
108:                        Matcher matcher = groupPattern.matcher(possibleParents);
109:
110:                        while (matcher.find()) {
111:                            if (matcher.group(1).equals(parentGroup)
112:                                    || matcher.group(1).equals("all")) {
113:                                list.add(id);
114:                            }
115:                        }
116:                    }
117:                }
118:
119:                return list;
120:            }
121:
122:            /**
123:             * Creates the default child for the given parent.
124:             *
125:             * @param parent
126:             *            the parent folder
127:             * @return the childfolder
128:             * @throws Exception
129:             */
130:            public IMailFolder createDefaultChild(IMailFolder parent,
131:                    String name) throws FolderCreationException {
132:                List possibleChilds = getPossibleChilds(parent);
133:
134:                if (possibleChilds.size() > 0) {
135:                    String childType = (String) possibleChilds.get(0);
136:                    return createChild(parent, name, childType);
137:                } else {
138:                    return null;
139:                }
140:            }
141:
142:            /**
143:             * Creates a subfolder for the given folder with the given type.
144:             *
145:             * @param parent
146:             *            the parentfolder
147:             * @param childType
148:             *            the type of the child (e.g. CachedMHFolder )
149:             * @return the childfolder
150:             * @throws Exception
151:             */
152:            public IMailFolder createChild(IMailFolder parent, String name,
153:                    String childType) throws FolderCreationException {
154:                IMailFolder child;
155:                try {
156:                    IExtension extension = handler.getExtension(childType);
157:
158:                    child = (IMailFolder) extension
159:                            .instanciateExtension(new Object[] { name,
160:                                    childType, path });
161:
162:                    // Add child to parent
163:                    parent.addSubfolder(child);
164:                } catch (Exception e) {
165:                    throw new FolderCreationException(e);
166:                }
167:                return child;
168:            }
169:
170:            public IMailFolder createVirtualFolder(IMailFolder parent,
171:                    String name) throws FolderCreationException {
172:                IMailFolder child;
173:                try {
174:                    IExtension extension = handler
175:                            .getExtension("VirtualFolder");
176:
177:                    child = (IMailFolder) extension
178:                            .instanciateExtension(new Object[] { name });
179:
180:                    // Add child to parent
181:                    parent.addSubfolder(child);
182:                } catch (Exception e) {
183:                    throw new FolderCreationException(e);
184:                }
185:                return child;
186:            }
187:
188:            public IMAPFolder createIMAPRootFolder(AccountItem account)
189:                    throws FolderCreationException {
190:
191:                try {
192:                    IExtension extension = handler
193:                            .getExtension("IMAPRootFolder");
194:
195:                    IMAPRootFolder child = (IMAPRootFolder) extension
196:                            .instanciateExtension(new Object[] { account, path });
197:
198:                    // get root folder
199:                    IMailFolder parent = (IMailFolder) FolderTreeModel
200:                            .getInstance().getRoot();
201:
202:                    // Add child to parent
203:                    parent.addSubfolder(child);
204:
205:                    // create mandatory IMAP Inbox folder
206:                    IExtension extension2 = handler.getExtension("IMAPFolder");
207:                    IMAPFolder inbox = (IMAPFolder) extension2
208:                            .instanciateExtension(new Object[] { "INBOX",
209:                                    "IMAPFolder", path });
210:
211:                    // associate inbox with root folder
212:                    child.setInbox(inbox);
213:
214:                    // notify folder tree model
215:                    FolderTreeModel.getInstance().nodeStructureChanged(parent);
216:
217:                    return inbox;
218:                } catch (Exception e) {
219:                    throw new FolderCreationException(e);
220:                }
221:            }
222:
223:            public String getGroup(String parentType) {
224:                // iterate through all foldertypes to find suitable ones
225:                Enumeration e = handler.getExtensionEnumeration();
226:                while (e.hasMoreElements()) {
227:                    IExtension extension = (IExtension) e.nextElement();
228:                    ExtensionMetadata metadata = (ExtensionMetadata) extension
229:                            .getMetadata();
230:                    String id = metadata.getId();
231:                    String group = metadata.getAttribute("group");
232:
233:                    if (id.equals(parentType))
234:                        return group;
235:                }
236:
237:                return null;
238:
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.