KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > resource > FileResourceManager


1 package net.suberic.pooka.resource;
2
3 import net.suberic.util.*;
4 import net.suberic.pooka.ssl.*;
5 import net.suberic.pooka.*;
6 import javax.activation.*;
7
8 import java.net.*;
9 import java.io.*;
10
11 /**
12  * A ResourceManager which uses files.
13  */

14 public class FileResourceManager extends ResourceManager {
15
16   /**
17    * Creates a VariableBundle to be used.
18    */

19   public VariableBundle createVariableBundle(String JavaDoc fileName, VariableBundle defaults) {
20     try {
21       java.io.File JavaDoc f = new java.io.File JavaDoc(fileName);
22       if (! f.exists())
23     f.createNewFile();
24       return new net.suberic.util.VariableBundle(f, defaults);
25     } catch (java.io.IOException JavaDoc ioe) {
26       //new net.suberic.util.VariableBundle(url.openStream(), "net.suberic.pooka.Pooka");
27
return defaults;
28     }
29     
30   }
31
32   /**
33    * Creates a MailcapCommandMap to be used.
34    */

35   public MailcapCommandMap createMailcap(String JavaDoc fileName) throws java.io.IOException JavaDoc {
36     return new FullMailcapCommandMap(fileName);
37   }
38
39   /**
40    * Creates a PookaTrustManager.
41    */

42   public PookaTrustManager createPookaTrustManager(javax.net.ssl.TrustManager[] pTrustManagers, String JavaDoc fileName) {
43     return new PookaTrustManager(pTrustManagers, fileName);
44   }
45
46   public java.io.InputStream JavaDoc getInputStream(String JavaDoc pFileName)
47     throws java.io.IOException JavaDoc {
48     try {
49       URL url = new URL(pFileName);
50       return url.openStream();
51     } catch (MalformedURLException mue) {
52       return new FileInputStream(new File(pFileName));
53     }
54   }
55   
56
57   public java.io.OutputStream JavaDoc getOutputStream(String JavaDoc pFileName)
58     throws java.io.IOException JavaDoc {
59     return new FileOutputStream(new File(pFileName));
60   }
61
62   /**
63    * Creates an appropriate FolderInfo for the given StoreInfo.
64    */

65   public FolderInfo createFolderInfo(StoreInfo pStore, String JavaDoc pName) {
66     String JavaDoc storeProperty = pStore.getStoreProperty();
67     if (pStore.isPopStore() && pName.equalsIgnoreCase("INBOX")) {
68       return new PopInboxFolderInfo(pStore, pName);
69     } else if (Pooka.getProperty(storeProperty + ".protocol", "mbox").equalsIgnoreCase("imap")) {
70       if (Pooka.getProperty(storeProperty + ".cachingEnabled", Pooka.getProperty(storeProperty + "." + pName + ".cachingEnabled", "false")).equalsIgnoreCase("true") || Pooka.getProperty(storeProperty + ".cacheHeadersOnly", Pooka.getProperty(storeProperty + "." + pName + ".cacheHeadersOnly", "false")).equalsIgnoreCase("true")) {
71         return new net.suberic.pooka.cache.CachingFolderInfo(pStore, pName);
72       } else {
73         return new UIDFolderInfo(pStore, pName);
74       }
75     } else {
76       return new FolderInfo(pStore, pName);
77     }
78   }
79
80 }
81
82
83
Popular Tags