Build date determination
[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 = "ß test";\r
18   public static String  BUILD_DATE = "1-1-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 \r
56 \r
57     applicationProperties = new Properties();\r
58 \r
59     try\r
60     {\r
61       FileInputStream in = new FileInputStream(System.getProperty("user.home") +\r
62                                                "/.jalview_properties");\r
63       applicationProperties = new Properties();\r
64       applicationProperties.load(in);\r
65       in.close();\r
66     }\r
67     catch (Exception ex)\r
68     { }\r
69   }\r
70 \r
71   public static String getProperty(String key)\r
72   {\r
73     return  applicationProperties.getProperty(key);\r
74   }\r
75 \r
76   public static String setProperty(String key, String obj)\r
77   {\r
78     try\r
79     {\r
80       FileOutputStream out = new FileOutputStream(System.getProperty(\r
81           "user.home") + "/.jalview_properties");\r
82 \r
83       applicationProperties.setProperty(key, obj);\r
84 \r
85       applicationProperties.store(out, "---JalviewX Properties File---");\r
86       out.close();\r
87     }\r
88     catch (Exception ex)\r
89     {}\r
90 \r
91     return obj;\r
92 \r
93   }\r
94 \r
95 \r
96 \r
97 \r
98 \r
99 }\r