2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 import org.apache.log4j.Logger;
26 import org.apache.log4j.SimpleLayout;
27 import org.apache.log4j.Level;
28 import org.apache.log4j.ConsoleAppender;
32 * Stores and retrieves Jalview Application Properties
33 * <br><br>Current properties include:
34 * <br>logs.Axis.Level - one of the stringified Levels for log4j controlling the logging level for axis (used for web services)
35 * <br>logs.Castor.Level - one of the stringified Levels for log4j controlling the logging level for castor (used for serialization)
36 * <br>logs.Jalview.Level - Cache.log stringified level.
37 * <br>DISCOVERY_START - Boolean - controls if discovery services are queried on startup
38 * <br>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
39 * <br>SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_Y=285,SCREEN_X=371,SHOW_FULLSCREEN
40 * FONT_NAME,FONT_SIZE,FONT_STYLE,GAP_SYMBOL,LAST_DIRECTORY,USER_DEFINED_COLOUR
41 * SHOW_FULL_ID,SHOW_IDENTITY,SHOW_QUALITY,SHOW_ANNOTATIONS,SHOW_CONSERVATION,
42 * DEFAULT_COLOUR,DEFAULT_FILE_FORMAT,STARTUP_FILE,SHOW_STARTUP_FILE
50 * Initialises the Apache Axis logger
52 public static Logger log;
54 /** Jalview Properties */
55 public static Properties applicationProperties = new Properties();
57 /** Default file is ~/.jalview_properties */
58 static String propertiesFile;
60 public static void initLogger()
64 Logger laxis = Logger.getLogger("org.apache.axis");
65 Logger lcastor = Logger.getLogger("org.exolab.castor");
66 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
68 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
69 Level.INFO.toString())));
70 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
71 Level.INFO.toString())));
72 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
74 Level.INFO.toString())));
75 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
77 ap.setName("JalviewLogger");
79 laxis.addAppender(ap);
80 lcastor.addAppender(ap);
81 jalview.bin.Cache.log.addAppender(ap);
82 // Tell the user that debug is enabled
83 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
87 System.err.println("Problems initializing the log4j system\n");
92 /** Called when Jalview is started */
93 public static void loadProperties(String propsFile)
95 propertiesFile = propsFile;
96 if (propsFile == null)
98 propertiesFile = System.getProperty("user.home") +File.separatorChar+".jalview_properties";
103 FileInputStream fis = new FileInputStream(propertiesFile);
104 applicationProperties.load(fis);
105 applicationProperties.remove("LATEST_VERSION");
106 applicationProperties.remove("VERSION");
111 System.out.println("Error reading properties file: "+ex);
114 if(getDefault("USE_PROXY", false))
116 System.out.println("Using proxyServer: "+getDefault("PROXY_SERVER", null)+
117 " proxyPort: "+getDefault("PROXY_PORT", null));
118 System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null));
119 System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
122 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
123 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
124 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
127 String buildDetails = "jar:"
129 Cache.class.getProtectionDomain().getCodeSource().getLocation().toString()
130 .concat("!/.build_properties")
133 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
135 InputStream in = localJarFileURL.openStream();
136 applicationProperties.load(in);
141 System.out.println("Error reading build details: "+ex);
142 applicationProperties.remove("VERSION");
145 String jnlpVersion = System.getProperty("jalview.version");
146 String codeVersion = getProperty("VERSION");
149 if(codeVersion==null)
151 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
152 codeVersion = "Test";
153 jnlpVersion = "Test";
157 System.out.println("Jalview Version: "+codeVersion);
160 // jnlpVersion will be null if we're using InstallAnywhere
161 // Dont do this check if running in headless mode
162 if(jnlpVersion==null && (
163 System.getProperty("java.awt.headless")==null
164 || System.getProperty("java.awt.headless").equals("false")))
172 String jnlpVersion = null;
175 java.net.URL url = new java.net.URL(
176 "http://www.jalview.org/webstart/jalview.jnlp");
177 BufferedReader in = new BufferedReader(new InputStreamReader(url.
180 while ( (line = in.readLine()) != null)
182 if (line.indexOf("jalview.version") == -1)
185 line = line.substring(line.indexOf("value=") + 7);
186 line = line.substring(0, line.lastIndexOf("\""));
193 System.out.println(ex);
194 jnlpVersion = getProperty("VERSION");
197 setProperty("LATEST_VERSION", jnlpVersion);
201 VersionChecker vc = new VersionChecker();
206 if(jnlpVersion!=null)
207 setProperty("LATEST_VERSION", jnlpVersion);
209 applicationProperties.remove("LATEST_VERSION");
212 setProperty("VERSION", codeVersion);
214 //LOAD USERDEFINED COLOURS
215 jalview.gui.UserDefinedColours.initUserColourSchemes( getProperty("USER_DEFINED_COLOURS"));
216 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER", false);
222 * Gets Jalview application property of given key. Returns null
225 * @param key Name of property
227 * @return Property value
229 public static String getProperty(String key)
231 return applicationProperties.getProperty(key);
235 /** These methods are used when checking if the saved preference
236 * is different to the default setting
239 public static boolean getDefault(String property, boolean def)
241 String string = getProperty(property);
244 def = Boolean.valueOf(string).booleanValue();
250 /** These methods are used when checking if the saved preference
251 * is different to the default setting
253 public static String getDefault(String property, String def)
255 String string = getProperty(property);
266 * Stores property in the file "HOME_DIR/.jalview_properties"
268 * @param key Name of object
269 * @param obj String value of property
271 * @return String value of property
273 public static String setProperty(String key, String obj)
277 FileOutputStream out = new FileOutputStream(propertiesFile);
278 applicationProperties.setProperty(key, obj);
279 applicationProperties.store(out, "---JalviewX Properties File---");
283 { System.out.println("Error setting property: "+key+" "+obj+"\n"+ex); }
287 public static void saveProperties()
291 FileOutputStream out = new FileOutputStream(propertiesFile);
292 applicationProperties.store(out, "---JalviewX Properties File---");
296 { System.out.println("Error saving properties: "+ex); }
299 * internal vamsas class discovery state
301 private static int vamsasJarsArePresent=-1;
303 * Searches for vamsas client classes on class path.
304 * @return true if vamsas client is present on classpath
306 public static boolean vamsasJarsPresent() {
307 if (vamsasJarsArePresent==-1) {
309 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass("org.vamsas.client.VorbaId")!=null) {
310 jalview.bin.Cache.log.debug("Found Vamsas Classes (org.vamsas.client.VorbaId can be loaded)");
311 vamsasJarsArePresent=1;
312 Logger lvclient = Logger.getLogger("org.vamsas");
313 lvclient.setLevel(Level.toLevel(Cache.getDefault("logs.Vamsas.Level",
314 Level.INFO.toString())));
316 lvclient.addAppender(log.getAppender("JalviewLogger"));
317 // Tell the user that debug is enabled
318 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
320 } catch (Exception e) {
321 vamsasJarsArePresent=0;
322 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
325 return (vamsasJarsArePresent>0);