Source Code Cross Referenced for AddressBookManager.java in  » Mail-Clients » pooka » net » suberic » pooka » 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 » pooka » net.suberic.pooka 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.suberic.pooka;
002:
003:        import javax.mail.*;
004:        import java.util.*;
005:        import net.suberic.util.*;
006:
007:        /**
008:         * This class manages the a list of AddressBooks.
009:         */
010:
011:        public class AddressBookManager implements  ValueChangeListener {
012:
013:            private Vector addressBookList;
014:            private Vector valueChangeListenerList = new Vector();
015:
016:            public AddressBookManager() {
017:                addressBookList = createAddressBookList();
018:                Pooka.getResources()
019:                        .addValueChangeListener(this , "AddressBook");
020:            }
021:
022:            //-----------------------
023:            // public interface.
024:
025:            /**
026:             * As defined in net.suberic.util.ValueChangeListener.
027:             * 
028:             * This listens for changes to the "AddressBook" property and calls
029:             * refreshAddressBooks() when it gets one.
030:             */
031:            public void valueChanged(String changedValue) {
032:                if (changedValue.equals("AddressBook"))
033:                    refreshAddressBooks();
034:            }
035:
036:            /**
037:             * This returns a Vector with all the currently registered AddressBook
038:             * objects.
039:             */
040:            public java.util.Vector getAddressBookList() {
041:                return new Vector(addressBookList);
042:            }
043:
044:            /**
045:             * This adds the addressBook with the given addressBookName to the 
046:             * allAddressBooks list.
047:             */
048:            public void addAddressBook(String addressBookName) {
049:                if (getAddressBook(addressBookName) == null) {
050:                    appendToAddressBookString(addressBookName);
051:                }
052:            }
053:
054:            /**
055:             * This adds the addressBooks with the given addressBookNames to the 
056:             * allAddressBooks list.
057:             */
058:            public void addAddressBook(String[] addressBookName) {
059:                if (addressBookName != null && addressBookName.length > 0) {
060:                    StringBuffer addressBookString = new StringBuffer();
061:                    for (int i = 0; i < addressBookName.length; i++) {
062:                        if (getAddressBook(addressBookName[i]) == null)
063:                            addressBookString.append(addressBookName[i] + ":");
064:                    }
065:                    if (addressBookString.length() > 0)
066:                        appendToAddressBookString(new String(addressBookString
067:                                .deleteCharAt(addressBookString.length() - 1)));
068:                }
069:            }
070:
071:            /**
072:             * This removes the addressBook with the given addressBookName.
073:             */
074:            public void removeAddressBook(String addressBookName) {
075:                if (getAddressBook(addressBookName) != null)
076:                    removeFromAddressBookString(new String[] { addressBookName });
077:            }
078:
079:            /**
080:             * This removes the addressBooks with the given addressBookNames.
081:             */
082:            public void removeAddressBook(String[] addressBookNames) {
083:                // this is probably not necessary at all, but what the hell?
084:
085:                if (addressBookNames == null || addressBookNames.length < 1)
086:                    return;
087:
088:                Vector matches = new Vector();
089:                for (int i = 0; i < addressBookNames.length; i++) {
090:                    if (getAddressBook(addressBookNames[i]) != null)
091:                        matches.add(addressBookNames[i]);
092:
093:                }
094:
095:                if (matches.size() < 1)
096:                    return;
097:
098:                String[] removedAddressBooks = new String[matches.size()];
099:
100:                for (int i = 0; i < matches.size(); i++)
101:                    removedAddressBooks[i] = (String) matches.elementAt(i);
102:
103:                removeFromAddressBookString(removedAddressBooks);
104:            }
105:
106:            /**
107:             * This removes the given AddressBook.
108:             */
109:            public void removeAddressBook(AddressBook addressBook) {
110:                if (addressBook != null)
111:                    removeAddressBook(addressBook.getAddressBookID());
112:            }
113:
114:            /**
115:             * This removes the given AddressBooks.
116:             */
117:            public void removeAddressBook(AddressBook[] addressBook) {
118:                if (addressBook != null && addressBook.length > 0) {
119:                    String[] addressBookNames = new String[addressBook.length];
120:                    for (int i = 0; i < addressBook.length; i++) {
121:                        if (addressBook[i] != null)
122:                            addressBookNames[i] = addressBook[i]
123:                                    .getAddressBookID();
124:                    }
125:
126:                    removeAddressBook(addressBookNames);
127:                }
128:            }
129:
130:            /**
131:             * This compares the addressBookList object with the AddressBook property, and
132:             * updates the addressBookList appropriately.
133:             */
134:            public void refreshAddressBooks() {
135:                Vector newAddressBookList = new Vector();
136:
137:                StringTokenizer tokens = new StringTokenizer(Pooka.getProperty(
138:                        "AddressBook", ""), ":");
139:
140:                String addressBookID;
141:                while (tokens.hasMoreTokens()) {
142:                    addressBookID = tokens.nextToken();
143:                    AddressBook currentAddressBook = getAddressBook(addressBookID);
144:                    if (currentAddressBook != null) {
145:                        newAddressBookList.add(currentAddressBook);
146:                    } else {
147:                        currentAddressBook = createAddressBook(addressBookID);
148:                        if (currentAddressBook != null) {
149:                            newAddressBookList.add(currentAddressBook);
150:
151:                            if (Pooka.getProperty("AddressBook._default", "")
152:                                    .equalsIgnoreCase(""))
153:                                Pooka.setProperty("AddressBook._default",
154:                                        addressBookID);
155:                        }
156:
157:                    }
158:                }
159:
160:                if (!newAddressBookList.equals(addressBookList)) {
161:                    addressBookList = newAddressBookList;
162:                    fireAddressBookListChangedEvent();
163:                }
164:            }
165:
166:            /**
167:             * Creates an address book.
168:             */
169:            public AddressBook createAddressBook(String id) {
170:                String type = Pooka.getProperty("AddressBook." + id + ".type",
171:                        "");
172:                if (type.equalsIgnoreCase("file")) {
173:                    AddressBook returnValue = new net.suberic.pooka.vcard.VcardAddressBook();
174:                    returnValue.configureAddressBook(id);
175:                    return returnValue;
176:                }
177:
178:                return null;
179:            }
180:
181:            /**
182:             * This returns the AddressBook which corresponds to the given name.
183:             */
184:            public AddressBook getAddressBook(String name) {
185:                if (addressBookList == null)
186:                    return null;
187:
188:                for (int i = 0; i < addressBookList.size(); i++) {
189:                    AddressBook currentBook = (AddressBook) addressBookList
190:                            .elementAt(i);
191:                    if (currentBook != null
192:                            && currentBook.getAddressBookID().equals(name))
193:                        return currentBook;
194:                }
195:
196:                return null;
197:            }
198:
199:            /**
200:             * This adds a ValueChangeListener to the local listener list.
201:             */
202:            public void addValueChangeListener(ValueChangeListener vcl) {
203:                if (!valueChangeListenerList.contains(vcl))
204:                    valueChangeListenerList.add(vcl);
205:            }
206:
207:            /**
208:             * This removes a ValueChangeListener from the local listener list.
209:             */
210:            public void removeValueChangeListener(ValueChangeListener vcl) {
211:                valueChangeListenerList.remove(vcl);
212:            }
213:
214:            /**
215:             * This notifies all listeners that the AddressBookList has changed.
216:             */
217:
218:            public void fireAddressBookListChangedEvent() {
219:                for (int i = 0; i < valueChangeListenerList.size(); i++)
220:                    ((ValueChangeListener) valueChangeListenerList.elementAt(i))
221:                            .valueChanged("AddressBook");
222:            }
223:
224:            //---------------------------
225:            // the background stuff.
226:
227:            /**
228:             * This loads and creates all the AddressBooks using the "AddressBook" 
229:             * property of the main Pooka VariableBundle.
230:             */
231:            private Vector createAddressBookList() {
232:                Vector allAddressBooks = new Vector();
233:                String addressBookID = null;
234:
235:                StringTokenizer tokens = new StringTokenizer(Pooka.getProperty(
236:                        "AddressBook", ""), ":");
237:
238:                while (tokens.hasMoreTokens()) {
239:                    addressBookID = (String) tokens.nextToken();
240:                    allAddressBooks.add(createAddressBook(addressBookID));
241:                }
242:
243:                return allAddressBooks;
244:            }
245:
246:            /**
247:             * This appends the newAddressBookString to the "AddressBook" property.
248:             */
249:            private void appendToAddressBookString(String newAddressBookString) {
250:                String oldValue = Pooka.getProperty("AddressBook");
251:                String newValue;
252:                if (oldValue.length() > 0
253:                        && oldValue.charAt(oldValue.length() - 1) != ':') {
254:                    newValue = oldValue + ":" + newAddressBookString;
255:                } else {
256:                    newValue = oldValue + newAddressBookString;
257:                }
258:
259:                Pooka.setProperty("AddressBook", newValue);
260:            }
261:
262:            /**
263:             * This removes the addressBook names in the addressBookNames array from the 
264:             * "AddressBook" property.
265:             */
266:            private void removeFromAddressBookString(String[] addressBookNames) {
267:                StringTokenizer tokens = new StringTokenizer(Pooka.getProperty(
268:                        "AddressBook", ""), ":");
269:
270:                boolean first = true;
271:                StringBuffer newValue = new StringBuffer();
272:                String addressBookID;
273:
274:                while (tokens.hasMoreTokens()) {
275:                    addressBookID = tokens.nextToken();
276:                    boolean keep = true;
277:
278:                    for (int i = 0; keep == true && i < addressBookNames.length; i++) {
279:                        if (addressBookID.equals(addressBookNames[i]))
280:                            keep = false;
281:                    }
282:                    if (keep) {
283:                        if (!first)
284:                            newValue.append(":");
285:
286:                        newValue.append(addressBookID);
287:                        first = false;
288:                    }
289:
290:                }
291:
292:                Pooka.setProperty("AddressBook", newValue.toString());
293:            }
294:
295:            /**
296:             * Gets the default Address Book, if there is one.
297:             */
298:            public AddressBook getDefault() {
299:                String defaultName = Pooka.getProperty("AddressBook._default",
300:                        "");
301:                if (!defaultName.equals("")) {
302:                    AddressBook defaultBook = getAddressBook(defaultName);
303:                    return defaultBook;
304:                } else
305:                    return null;
306:
307:            }
308:
309:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.