1 package net.suberic.pooka; 2 3 import javax.mail.*; 4 import java.util.*; 5 import net.suberic.util.*; 6 7 12 13 public class StoreManager implements ItemCreator, ItemListChangeListener { 14 15 private ItemManager manager; 16 private LinkedList listenerList = new LinkedList(); 17 18 public StoreManager() { 19 createStoreList(); 20 } 21 22 25 32 public void itemListChanged(ItemListChangeEvent e) { 33 fireItemListChanged(e); 34 refreshStoreInfos(e); 35 } 36 37 41 public java.util.Vector getStoreList() { 42 return manager.getItems(); 43 } 44 45 48 public void addStore(String storeName) { 49 manager.addItem(storeName); 50 } 51 52 55 public void addStore(String [] storeName) { 56 manager.addItem(storeName); 57 } 58 59 62 public void removeStore(String storeName) { 63 manager.removeItem(storeName); 64 } 65 66 69 public void removeStore(String [] storeNames) { 70 manager.removeItem(storeNames); 71 } 72 73 76 public void removeStore(StoreInfo store) { 77 manager.removeItem(store); 78 } 79 80 83 public void removeStore(StoreInfo[] stores) { 84 manager.removeItem(stores); 85 } 86 87 91 public void refreshStoreInfos(ItemListChangeEvent e) { 92 Item[] removedStores = e.getRemoved(); 93 for (int i = 0; removedStores != null && i < removedStores.length; i++) { 94 ((StoreInfo) removedStores[i]).remove(); 95 } 96 } 97 98 102 public FolderInfo getFolder(String folderName) { 103 if (folderName != null && folderName.length() >= 1) { 104 int divider = folderName.indexOf('/', 1); 105 while (divider == 0) { 106 folderName = folderName.substring(1); 107 divider = folderName.indexOf('/'); 108 } 109 110 if (divider > 0) { 111 String storeName = folderName.substring(0, divider); 112 StoreInfo store = getStoreInfo(storeName); 113 if (store != null) { 114 return store.getChild(folderName.substring(divider +1)); 115 } 116 } 117 } 118 119 return null; 120 } 121 122 126 public FolderInfo getFolderById(String folderID) { 127 129 java.util.Vector allStores = getStoreList(); 130 131 for (int i = 0; i < allStores.size(); i++) { 132 StoreInfo currentStore = (StoreInfo) allStores.elementAt(i); 133 if (folderID.startsWith(currentStore.getStoreID())) { 134 FolderInfo possibleMatch = currentStore.getFolderById(folderID); 135 if (possibleMatch != null) { 136 return possibleMatch; 137 } 138 } 139 } 140 141 return null; 142 } 143 144 147 public Vector getAllOpenFolders() { 148 Vector returnValue = new Vector(); 149 Vector currentStores = getStoreList(); 150 for (int i = 0; i < currentStores.size(); i++) { 151 returnValue.addAll(((StoreInfo) currentStores.elementAt(i)).getAllFolders()); 152 } 153 154 return returnValue; 155 } 156 157 161 public StoreInfo getStoreInfo(String storeID) { 162 return (StoreInfo) manager.getItem(storeID); 163 } 164 165 170 public void loadAllSentFolders() { 171 List profileList = Pooka.getPookaManager().getUserProfileManager().getUserProfileList(); 172 173 for (int i = 0; i < profileList.size(); i++) { 174 ((UserProfile)profileList.get(i)).loadSentFolder(); 175 } 176 } 177 178 181 public void addItemListChangeListener(ItemListChangeListener ilcl) { 182 if (! listenerList.contains(ilcl)) 183 listenerList.add(ilcl); 184 } 185 186 189 public void removeItemListChangeListener(ItemListChangeListener ilcl) { 190 listenerList.remove(ilcl); 191 } 192 193 196 public void fireItemListChanged(ItemListChangeEvent e) { 197 for (int i = 0; i < listenerList.size(); i++) 198 ((ItemListChangeListener)listenerList.get(i)).itemListChanged(e); 199 } 200 201 202 207 public Item createItem(VariableBundle sourceBundle, String resourceString, String itemID) { 208 return new StoreInfo(itemID); 209 } 210 211 214 218 private void createStoreList() { 219 manager = new ItemManager("Store", Pooka.getResources(), this); 220 manager.addItemListChangeListener(this); 221 } 222 223 226 public static void setupSSL() { 227 229 233 try { 234 Object provider = Class.forName("com.sun.net.ssl.internal.ssl.Provider").newInstance(); 235 236 java.security.Security.addProvider((java.security.Provider ) provider); 237 238 } catch (Exception e) { 240 } 244 246 } 247 248 251 public void cleanup() { 252 Pooka.getResources().removeValueChangeListener(manager); 253 } 254 } 255 256 | Popular Tags |