1 package net.suberic.pooka.resource; 2 3 import net.suberic.util.*; 4 import net.suberic.pooka.*; 5 import net.suberic.pooka.ssl.*; 6 7 import javax.activation.*; 8 import java.io.*; 9 import java.util.*; 10 import java.net.*; 11 12 15 public class DisklessResourceManager extends ResourceManager { 16 17 20 public VariableBundle createVariableBundle(String fileName, VariableBundle defaults) { 21 return defaults; 22 } 23 24 27 public MailcapCommandMap createMailcap(String fileName) { 28 return new FullMailcapCommandMap(); 29 } 30 31 34 public PookaTrustManager createPookaTrustManager(javax.net.ssl.TrustManager[] pTrustManagers, String fileName) { 35 return new PookaTrustManager(pTrustManagers, null, false); 36 } 37 38 42 public static void exportResources(File pOutputFile, boolean pIncludePasswords) throws IOException { 43 VariableBundle sourceBundle = Pooka.getResources(); 44 45 pOutputFile.createNewFile(); 46 VariableBundle newWritableProperties = new VariableBundle(pOutputFile, null); 47 48 50 List allStores = Pooka.getStoreManager().getStoreList(); 51 List toRemoveList = new ArrayList(); 52 List keepList = new ArrayList(); 53 54 Iterator iter = allStores.iterator(); 55 while (iter.hasNext()) { 56 StoreInfo current = (StoreInfo) iter.next(); 59 60 if (current.getProtocol() != null && current.getProtocol().toLowerCase().startsWith("imap")) { 61 newWritableProperties.setProperty(current.getStoreProperty() + ".cachingEnabled", "false"); 62 keepList.add(current.getStoreID()); 63 } else { 64 toRemoveList.add(current.getStoreID()); 65 } 66 } 67 68 Enumeration names = sourceBundle.getProperties().propertyNames(); 71 72 while (names.hasMoreElements()) { 73 String current = (String ) names.nextElement(); 74 75 boolean keep = true; 76 if (current.startsWith("Store")) { 77 if ((! pIncludePasswords) && current.endsWith("password")) { 78 keep = false; 79 } else if (current.endsWith("cachingEnabled")) { 80 keep = false; 81 } 82 83 for (int i = 0; keep && i < toRemoveList.size(); i++) { 84 if (current.startsWith("Store." + (String ) toRemoveList.get(i))) { 85 keep = false; 86 } 87 } 88 } 89 90 if (keep) { 91 newWritableProperties.setProperty(current, sourceBundle.getProperty(current)); 92 } 93 94 } 95 96 newWritableProperties.setProperty("Pooka.useLocalFiles", "false"); 98 99 newWritableProperties.setProperty("Store", VariableBundle.convertToString(keepList)); 101 102 104 newWritableProperties.saveProperties(); 106 107 109 110 } 111 112 116 public java.io.InputStream getInputStream(String pFileName) 117 throws java.io.IOException { 118 try { 119 URL url = new URL(pFileName); 120 return url.openStream(); 121 } catch (MalformedURLException mue) { 122 throw new IOException("Error opening URL: " + mue.getMessage()); 123 } 124 } 125 126 public java.io.OutputStream getOutputStream(String pFileName) 127 throws java.io.IOException { 128 throw new IOException("Diskless mode: no file modification available."); 130 } 131 132 135 public FolderInfo createFolderInfo(StoreInfo pStore, String pName) { 136 String storeProperty = pStore.getStoreProperty(); 137 if (pStore.isPopStore() && pName.equalsIgnoreCase("INBOX")) { 138 return new PopInboxFolderInfo(pStore, pName); 139 } else if (Pooka.getProperty(storeProperty + ".protocol", "mbox").equalsIgnoreCase("imap")) { 140 return new UIDFolderInfo(pStore, pName); 141 } else { 142 return new FolderInfo(pStore, pName); 143 } 144 } 145 146 } 147 | Popular Tags |