01: // The contents of this file are subject to the Mozilla Public License Version
02: // 1.1
03: //(the "License"); you may not use this file except in compliance with the
04: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05: //
06: //Software distributed under the License is distributed on an "AS IS" basis,
07: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: //for the specific language governing rights and
09: //limitations under the License.
10: //
11: //The Original Code is "The Columba Project"
12: //
13: //The Initial Developers of the Original Code are Frederik Dietz and Timo
14: // Stich.
15: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16: //
17: //All Rights Reserved.
18: package org.columba.addressbook.model;
19:
20: import java.util.Iterator;
21: import java.util.Map;
22:
23: import org.columba.addressbook.folder.IContactFolder;
24:
25: public class ContactModelFactory {
26:
27: public static IGroupModelPartial createGroupPartial(
28: IGroupModel group, IContactFolder folder) {
29: if (group == null)
30: throw new IllegalArgumentException("group == null");
31: if (folder == null)
32: throw new IllegalArgumentException("folder == null");
33:
34: IGroupModelPartial groupPartial = new GroupModelPartial(folder
35: .getId(), group.getName(), group.getDescription());
36:
37: // retrieve list of all group members
38: String[] members = group.getMembers();
39: Map<String, IContactModelPartial> map = folder
40: .getContactItemMap(members);
41:
42: Iterator<IContactModelPartial> it = map.values().iterator();
43: while (it.hasNext()) {
44: IContactModelPartial partial = it.next();
45:
46: groupPartial.addContact(partial);
47: }
48:
49: return groupPartial;
50: }
51:
52: public static IContactModelPartial createContactModelPartial(
53: IContactModel model, String id) {
54: if (model == null)
55: throw new IllegalArgumentException("model == null");
56: if (id == null)
57: throw new IllegalArgumentException("id == null");
58:
59: String sortString = model.getSortString();
60:
61: // @author: fdietz
62: // This is a workaround. Generally, the contact dialog editor
63: // should ensure that all necessary fields are available
64: //
65:
66: // fall-back to formatted name
67: if (sortString == null || sortString.length() == 0)
68: sortString = model.getFormattedName();
69:
70: // fall-back to email address
71: if (sortString == null || sortString.length() == 0)
72: sortString = model.getPreferredEmail();
73:
74: IContactModelPartial item = new ContactModelPartial(id,
75: sortString, model.getGivenName(),
76: model.getFamilyName(), model.getPreferredEmail(), model
77: .getHomePage());
78:
79: return item;
80: }
81: }
|