release version
[jalview.git] / src / jalview / bin / Cache.java
1 /********************\r
2  * 2004 Jalview Reengineered\r
3  * Barton Group\r
4  * Dundee University\r
5  *\r
6  * AM Waterhouse\r
7  *******************/\r
8 \r
9 \r
10 package jalview.bin;\r
11 import java.util.*;\r
12 import java.io.*;\r
13 \r
14 import java.util.jar.*;\r
15 public class Cache\r
16 {\r
17   public static String  VERSION = "Release 2.0";\r
18   public static String  BUILD_DATE = "01-05-2005";\r
19 \r
20   public static Properties applicationProperties;\r
21   // Current properties include:\r
22   //\r
23   // LAST_DIRECTORY   , use this to cache record of where the user looked to find a file\r
24   // UNIPROT_CACHE\r
25   // USER_DEFINED_COLOUR - file describing last user set colours\r
26   // FONT_NAME\r
27   // FONT_STYLE\r
28   // FONT_SIZE\r
29   // logs.Axis.Level - one of the stringified Levels for log4j controlling the logging level for axis (used for web services)\r
30 \r
31   public static void loadProperties()\r
32   {\r
33     // get last build time.\r
34     long date = 0;\r
35     try{\r
36           String localFile = Cache.class.getProtectionDomain().getCodeSource().getLocation().toString();\r
37           localFile = localFile.concat("!/");\r
38           String tmpString = "jar:";\r
39           String localJarFileString = tmpString.concat(localFile);\r
40           java.net.URL localJarFileURL = new java.net.URL(localJarFileString);\r
41           java.net.JarURLConnection localJarFile = (java.net.JarURLConnection)localJarFileURL.openConnection();\r
42           date = localJarFile.getLastModified();\r
43     }catch(Exception ex){ex.printStackTrace();}\r
44     if(date==0)\r
45     {\r
46       // this is called for unpackaged class files.\r
47       // not entirely accurate as it only tells you when Cache.class was last compiled\r
48       java.net.URL url = Cache.class.getResource("/jalview/bin/Cache.class");\r
49       java.io.File f = new java.io.File(url.getFile());\r
50       date = f.lastModified();\r
51     }\r
52 \r
53     BUILD_DATE = new Date( date ).toString();\r
54 \r
55     applicationProperties = new Properties();\r
56 \r
57     try\r
58     {\r
59       FileInputStream in = new FileInputStream(System.getProperty("user.home") +\r
60                                                "/.jalview_properties");\r
61       applicationProperties = new Properties();\r
62       applicationProperties.load(in);\r
63       in.close();\r
64     }\r
65     catch (Exception ex)\r
66     { }\r
67   }\r
68 \r
69   public static String getProperty(String key)\r
70   {\r
71     return  applicationProperties.getProperty(key);\r
72   }\r
73 \r
74   public static String setProperty(String key, String obj)\r
75   {\r
76     try\r
77     {\r
78       FileOutputStream out = new FileOutputStream(System.getProperty(\r
79           "user.home") + "/.jalview_properties");\r
80 \r
81       applicationProperties.setProperty(key, obj);\r
82 \r
83       applicationProperties.store(out, "---JalviewX Properties File---");\r
84       out.close();\r
85     }\r
86     catch (Exception ex)\r
87     {}\r
88 \r
89     return obj;\r
90 \r
91   }\r
92 \r
93 \r
94 \r
95 \r
96 \r
97 }\r