Source Code Cross Referenced for AccountList.java in  » Mail-Clients » columba-1.4 » org » columba » mail » config » 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.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // The contents of this file are subject to the Mozilla Public License Version
002:        // 1.1
003:        //(the "License"); you may not use this file except in compliance with the
004:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005:        //
006:        //Software distributed under the License is distributed on an "AS IS" basis,
007:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008:        //for the specific language governing rights and
009:        //limitations under the License.
010:        //
011:        //The Original Code is "The Columba Project"
012:        //
013:        //The Initial Developers of the Original Code are Frederik Dietz and Timo
014:        // Stich.
015:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016:        //
017:        //All Rights Reserved.
018:
019:        package org.columba.mail.config;
020:
021:        import java.io.File;
022:        import java.io.IOException;
023:        import java.net.URL;
024:
025:        import org.columba.core.config.DefaultItem;
026:        import org.columba.core.io.DiskIO;
027:        import org.columba.core.xml.XmlElement;
028:        import org.columba.core.xml.XmlIO;
029:
030:        public class AccountList extends DefaultItem {
031:
032:            protected int nextUid;
033:
034:            protected AccountItem defaultAccount;
035:
036:            public AccountList(XmlElement root) {
037:                super (root);
038:
039:                AccountItem item;
040:
041:                nextUid = -1;
042:
043:                int uid;
044:
045:                for (int i = 0; i < count(); i++) {
046:                    item = get(i);
047:                    uid = item.getInteger("uid");
048:
049:                    if (uid > nextUid) {
050:                        nextUid = uid;
051:                    }
052:                }
053:
054:                nextUid++;
055:            }
056:
057:            public AccountItem get(int index) {
058:                XmlElement e = getChildElement(index);
059:
060:                //XmlElement.printNode(e,"");
061:
062:                /*
063:                 * if ((index >= 0) && (index < list.size())) return (AccountItem)
064:                 * list.get(index);
065:                 *
066:                 * return null;
067:                 */
068:                return new AccountItem(e);
069:            }
070:
071:            public AccountItem uidGet(int uid) {
072:                XmlElement e;
073:
074:                for (int i = 0; i < count(); i++) {
075:                    e = getChildElement(i);
076:
077:                    int u = Integer.parseInt(e.getAttribute("uid"));
078:
079:                    if (uid == u) {
080:                        return new AccountItem(e);
081:                    }
082:                }
083:
084:                return null;
085:            }
086:
087:            /*
088:             * search for SecurityItem based on To headerfield
089:             *
090:             */
091:            public SecurityItem getPGPItem(String to) {
092:                for (int i = 0; i < count(); i++) {
093:                    AccountItem item = (AccountItem) get(i);
094:                    SecurityItem pgpItem = item.getPGPItem();
095:                    String id = pgpItem.get("id");
096:
097:                    to = to.toLowerCase();
098:                    id = id.toLowerCase();
099:
100:                    if (to.indexOf(id) != -1) {
101:                        return pgpItem;
102:                    } else if (id.indexOf(to) != -1) {
103:                        return pgpItem;
104:                    }
105:                }
106:
107:                return null;
108:            }
109:
110:            /**
111:             * Get account using the email address to identify it.
112:             *
113:             * @param address
114:             *            email address
115:             * @return account item
116:             */
117:            public AccountItem getAccount(String address) {
118:
119:                for (int i = 0; i < count(); i++) {
120:                    AccountItem item = get(i);
121:                    Identity identity = item.getIdentity();
122:                    String str = identity.getAddress().toString();
123:                    if (address.indexOf(str) != -1) {
124:                        // found match
125:                        return item;
126:                    }
127:                }
128:                return null;
129:            }
130:
131:            public AccountItem hostGetAccount(String host, String address) {
132:                XmlElement account;
133:                XmlElement server;
134:                XmlElement identity;
135:
136:                if (address == null) {
137:                    return get(0);
138:                }
139:
140:                for (int i = 0; i < count(); i++) {
141:                    account = getChildElement(i);
142:
143:                    server = account.getElement("popserver");
144:
145:                    if (server == null) {
146:                        server = account.getElement("imapserver");
147:                    }
148:
149:                    if (server.getAttribute("host").equals(host)) {
150:                        return new AccountItem(account);
151:                    }
152:                }
153:
154:                for (int i = 0; i < count(); i++) {
155:                    account = getChildElement(i);
156:
157:                    identity = account.getElement("identity");
158:
159:                    if (identity.getAttribute("address").indexOf(address) != -1) {
160:                        return new AccountItem(account);
161:                    }
162:                }
163:
164:                return null;
165:            }
166:
167:            public AccountItem addEmptyAccount(String type) {
168:                // path to account templates for POP3/IMAP
169:                String hstr = "org/columba/mail/config/account_template.xml";
170:                URL url = DiskIO.getResourceURL(hstr);
171:                XmlIO xmlIo = new XmlIO();
172:                // load xml document
173:                xmlIo.load(url);
174:                XmlElement root = xmlIo.getRoot();
175:                // get pop3 or imap account xml node
176:                XmlElement emptyAccount = root.getElement("/template/" + type
177:                        + "/account");
178:
179:                if (emptyAccount != null) {
180:                    AccountItem newAccount = new AccountItem(
181:                            (XmlElement) emptyAccount.clone());
182:                    newAccount.setInteger("uid", getNextUid());
183:                    add(newAccount);
184:
185:                    // Default signature
186:                    File dir = MailConfig.getInstance().getConfigDirectory();
187:                    File signatureFile = new File(dir, "signature_"
188:                            + newAccount.getName() + ".txt");
189:
190:                    String sigURL = "org/columba/mail/config/default_signature.txt";
191:                    try {
192:                        DiskIO.copyResource(sigURL, signatureFile);
193:
194:                        newAccount.getIdentity().setSignature(signatureFile);
195:                    } catch (IOException e) {
196:                        //Do nothing
197:                    }
198:
199:                    return newAccount;
200:                }
201:
202:                return null;
203:            }
204:
205:            public void add(AccountItem item) {
206:                getRoot().addSubElement(item.getRoot());
207:
208:                if (item.getInteger("uid") >= nextUid) {
209:                    nextUid = item.getInteger("uid") + 1;
210:                }
211:
212:                if (count() == 1) {
213:                    setDefaultAccount(item.getInteger("uid"));
214:                }
215:            }
216:
217:            public AccountItem remove(int index) {
218:                return new AccountItem(getRoot().removeElement(index));
219:            }
220:
221:            public int count() {
222:                return getRoot().count();
223:            }
224:
225:            protected int getNextUid() {
226:                return nextUid++;
227:            }
228:
229:            /** ************************** default account ******************* */
230:            public void setDefaultAccount(int uid) {
231:                setInteger("default", uid);
232:                defaultAccount = null;
233:            }
234:
235:            public int getDefaultAccountUid() {
236:                return getInteger("default");
237:            }
238:
239:            public AccountItem getDefaultAccount() {
240:                if (defaultAccount == null) {
241:                    defaultAccount = uidGet(getDefaultAccountUid());
242:                    // fall back to first account as default
243:                    if (defaultAccount == null) {
244:                        defaultAccount = get(0);
245:                    }
246:                }
247:
248:                return defaultAccount;
249:            }
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.