KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > IMAPTstFactory


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

17 package org.columba.mail.folder;
18
19 import org.columba.core.io.DiskIO;
20 import org.columba.core.xml.XmlIO;
21 import org.columba.mail.config.AccountItem;
22 import org.columba.mail.folder.imap.IMAPFolder;
23 import org.columba.mail.folder.imap.IMAPRootFolder;
24
25 public class IMAPTstFactory implements MailboxTstFactory {
26     
27     IMAPRootFolder cyrusRoot;
28     IMAPFolder inbox;
29     String JavaDoc namebase;
30     
31     public IMAPTstFactory() {
32         XmlIO accountXml = new XmlIO(DiskIO.getResourceURL("org/columba/mail/folder/cyrusaccount.xml"));
33         accountXml.load();
34         
35         AccountItem accountItem = new AccountItem(accountXml.getRoot().getElement("account"));
36         
37         
38         cyrusRoot = new IMAPRootFolder( accountItem, FolderTstHelper.homeDirectory + "/folders/");
39
40         try {
41             inbox = new IMAPFolder("INBOX","IMAPFolder", FolderTstHelper.homeDirectory + "/folders/");
42             cyrusRoot.add(inbox);
43         } catch (Exception JavaDoc e) {
44             e.printStackTrace();
45         }
46         
47         // An individual 3 digit number
48
namebase = Integer.toString((int)(System.currentTimeMillis() % 1000));
49     }
50     
51     /**
52      * @see org.columba.mail.folder.MailboxTstFactory#createFolder(int)
53      */

54     public AbstractMessageFolder createFolder(int folderId) {
55         try {
56             IMAPFolder folder = new IMAPFolder(namebase + Integer.toString(folderId),"IMAPFolder", FolderTstHelper.homeDirectory + "/folders/");
57             inbox.addSubfolder( folder );
58         /*
59         ((AbstractFolder)MailInterface.treeModel.getRoot()).add(cyrusRoot);
60         ((AbstractFolder) MailInterface.treeModel.getRoot())
61         .getConfiguration().getRoot().addElement(
62                 cyrusRoot.getConfiguration().getRoot());
63         MailInterface.treeModel.nodeStructureChanged(cyrusRoot.getParent());
64         */

65             return folder;
66         } catch (Exception JavaDoc e) {
67             e.printStackTrace();
68         }
69         return null;
70     }
71 }
72
Popular Tags