1 package net.suberic.pooka; 2 3 import java.util.*; 4 5 import javax.mail.*; 6 import javax.mail.internet.*; 7 8 import net.suberic.util.*; 9 10 16 public class UserProfileManager implements ItemCreator, ItemListChangeListener { 17 18 private ItemManager manager; 19 private LinkedList listenerList = new LinkedList(); 20 21 private List mailPropertiesList = null; 22 23 26 public UserProfileManager(VariableBundle sourceBundle) { 27 createMailPropertiesList(sourceBundle); 28 createUserProfileList(sourceBundle); 29 } 30 31 34 38 public void itemListChanged(ItemListChangeEvent e) { 39 fireItemListChanged(e); 40 } 41 42 46 public java.util.List getUserProfileList() { 47 return manager.getItems(); 48 } 49 50 54 public void addUserProfile(String UserProfileName) { 55 manager.addItem(UserProfileName); 56 } 57 58 61 public void addUserProfile(String [] UserProfileName) { 62 manager.addItem(UserProfileName); 63 } 64 65 68 public void removeUserProfile(String UserProfileName) { 69 manager.removeItem(UserProfileName); 70 } 71 72 75 public void removeUserProfile(String [] UserProfileNames) { 76 manager.removeItem(UserProfileNames); 77 } 78 79 82 public void removeUserProfile(UserProfile UserProfile) { 83 manager.removeItem(UserProfile); 84 } 85 86 89 public void removeUserProfile(UserProfile[] UserProfiles) { 90 manager.removeItem(UserProfiles); 91 } 92 93 97 public UserProfile getUserProfile(String UserProfileID) { 98 return (UserProfile) manager.getItem(UserProfileID); 99 } 100 101 105 public UserProfile getProfile(String UserProfileID) { 106 return getUserProfile(UserProfileID); 107 } 108 109 113 public UserProfile getDefaultProfile() { 114 UserProfile defaultUser = getUserProfile(Pooka.getProperty("UserProfile.default", "")); 115 if (defaultUser == null) { 116 List profileList = manager.getItems(); 117 if (profileList != null && profileList.size() > 0) { 118 defaultUser = (UserProfile) profileList.get(0); 119 } 120 } 121 return defaultUser; 122 } 123 124 127 public void addItemListChangeListener(ItemListChangeListener ilcl) { 128 if (! listenerList.contains(ilcl)) 129 listenerList.add(ilcl); 130 } 131 132 135 public void removeItemListChangeListener(ItemListChangeListener ilcl) { 136 listenerList.remove(ilcl); 137 } 138 139 142 public void fireItemListChanged(ItemListChangeEvent e) { 143 for (int i = 0; i < listenerList.size(); i++) 144 ((ItemListChangeListener)listenerList.get(i)).itemListChanged(e); 145 } 146 147 148 151 public Item createItem(VariableBundle sourceBundle, String resourceString, String itemID) { 152 UserProfile newProfile = new UserProfile(itemID, sourceBundle); 153 newProfile.initializeFromProperties(sourceBundle, mailPropertiesList); 154 return newProfile; 155 156 } 157 158 161 165 private void createUserProfileList(VariableBundle sourceBundle) { 166 manager = new ItemManager("UserProfile", sourceBundle, this); 167 168 manager.addItemListChangeListener(this); 169 } 170 171 175 public void createMailPropertiesList(VariableBundle mainProperties) { 176 mailPropertiesList = new ArrayList(); 177 178 180 StringTokenizer tokens = new StringTokenizer(mainProperties.getProperty("UserProfile.mailHeaders.fields", "From:FromPersonal:ReplyTo:ReplyToPersonal:Organization"), ":"); 181 while (tokens.hasMoreTokens()) { 182 mailPropertiesList.add(tokens.nextToken()); 183 } 184 185 } 186 187 public List getMailPropertiesList() { 188 return mailPropertiesList; 189 } 190 191 194 public void shutdownManager() { 195 VariableBundle resources = Pooka.getResources(); 196 List profiles = getUserProfileList(); 197 for (int i = 0; i < profiles.size(); i++) { 198 UserProfile up = (UserProfile) profiles.get(i); 199 resources.removeValueChangeListener(up); 200 } 201 resources.removeValueChangeListener(manager); 202 } 203 204 } 205 | Popular Tags |