GPL license added
[jalview.git] / src / jalview / bin / Cache.java
1 /*\r
2 * Jalview - A Sequence Alignment Editor and Viewer\r
3 * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4 *\r
5 * This program is free software; you can redistribute it and/or\r
6 * modify it under the terms of the GNU General Public License\r
7 * as published by the Free Software Foundation; either version 2\r
8 * of the License, or (at your option) any later version.\r
9 *\r
10 * This program is distributed in the hope that it will be useful,\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 * GNU General Public License for more details.\r
14 *\r
15 * You should have received a copy of the GNU General Public License\r
16 * along with this program; if not, write to the Free Software\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
18 */\r
19 \r
20 package jalview.bin;\r
21 import java.util.*;\r
22 import java.io.*;\r
23 \r
24 import java.util.jar.*;\r
25 public class Cache\r
26 {\r
27   public static String  VERSION = "Release 2.0";\r
28   public static String  BUILD_DATE = "";\r
29 \r
30   public static Properties applicationProperties;\r
31   // Current properties include:\r
32   //\r
33   // LAST_DIRECTORY   , use this to cache record of where the user looked to find a file\r
34   // UNIPROT_CACHE\r
35   // USER_DEFINED_COLOUR - file describing last user set colours\r
36   // FONT_NAME\r
37   // FONT_STYLE\r
38   // FONT_SIZE\r
39   // logs.Axis.Level - one of the stringified Levels for log4j controlling the logging level for axis (used for web services)\r
40   // jalview.browser - used in the jalview.utils.browserLauncher class if it doesn't know what else to do.\r
41   public static void loadProperties()\r
42   {\r
43     // get last build time.\r
44     long date = 0;\r
45     try{\r
46           String localFile = Cache.class.getProtectionDomain().getCodeSource().getLocation().toString();\r
47           localFile = localFile.concat("!/");\r
48           String tmpString = "jar:";\r
49           String localJarFileString = tmpString.concat(localFile);\r
50           java.net.URL localJarFileURL = new java.net.URL(localJarFileString);\r
51           java.net.JarURLConnection localJarFile = (java.net.JarURLConnection)localJarFileURL.openConnection();\r
52           date = localJarFile.getLastModified();\r
53     }catch(Exception ex){ex.printStackTrace();}\r
54     if(date==0)\r
55     {\r
56       // this is called for unpackaged class files, ie not in a Jar file\r
57       // InstallAnywhere version will find build date this way\r
58       // not entirely accurate as it only tells you when Cache.class was last compiled\r
59 \r
60 \r
61      java.io.File f = new java.io.File(System.getProperty("user.dir") + "/jalview/bin/Cache.class" );\r
62      date = f.lastModified();\r
63     }\r
64 \r
65     if(date!=0)\r
66       BUILD_DATE = new Date( date ).toString();\r
67 \r
68     applicationProperties = new Properties();\r
69 \r
70     try\r
71     {\r
72       FileInputStream in = new FileInputStream(System.getProperty("user.home") +\r
73                                                "/.jalview_properties");\r
74       applicationProperties = new Properties();\r
75       applicationProperties.load(in);\r
76       in.close();\r
77     }\r
78     catch (Exception ex)\r
79     { }\r
80   }\r
81 \r
82   public static String getProperty(String key)\r
83   {\r
84     return  applicationProperties.getProperty(key);\r
85   }\r
86 \r
87   public static String setProperty(String key, String obj)\r
88   {\r
89     try\r
90     {\r
91       FileOutputStream out = new FileOutputStream(System.getProperty(\r
92           "user.home") + "/.jalview_properties");\r
93 \r
94       applicationProperties.setProperty(key, obj);\r
95 \r
96       applicationProperties.store(out, "---JalviewX Properties File---");\r
97       out.close();\r
98     }\r
99     catch (Exception ex)\r
100     {}\r
101 \r
102     return obj;\r
103 \r
104   }\r
105 \r
106 \r
107 \r
108 \r
109 \r
110 }\r