2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2007 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
24 import org.apache.log4j.*;
27 * Stores and retrieves Jalview Application Properties
28 * <br><br>Current properties include:
29 * <br>logs.Axis.Level - one of the stringified Levels for log4j controlling the logging level for axis (used for web services)
30 * <br>logs.Castor.Level - one of the stringified Levels for log4j controlling the logging level for castor (used for serialization)
31 * <br>logs.Jalview.Level - Cache.log stringified level.
32 * <br>DISCOVERY_START - Boolean - controls if discovery services are queried on startup
33 * <br>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
34 * <br>SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_Y=285,SCREEN_X=371,SHOW_FULLSCREEN
35 * FONT_NAME,FONT_SIZE,FONT_STYLE,GAP_SYMBOL,LAST_DIRECTORY,USER_DEFINED_COLOUR
36 * SHOW_FULL_ID,SHOW_IDENTITY,SHOW_QUALITY,SHOW_ANNOTATIONS,SHOW_CONSERVATION,
37 * DEFAULT_COLOUR,DEFAULT_FILE_FORMAT,STARTUP_FILE,SHOW_STARTUP_FILE
45 * Initialises the Apache Axis logger
47 public static Logger log;
49 /** Jalview Properties */
50 public static Properties applicationProperties = new Properties();
52 /** Default file is ~/.jalview_properties */
53 static String propertiesFile;
55 public static void initLogger()
59 Logger laxis = Logger.getLogger("org.apache.axis");
60 Logger lcastor = Logger.getLogger("org.exolab.castor");
61 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
63 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
64 Level.INFO.toString())));
65 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
66 Level.INFO.toString())));
67 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
69 Level.INFO.toString())));
70 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
72 ap.setName("JalviewLogger");
74 laxis.addAppender(ap);
75 lcastor.addAppender(ap);
76 jalview.bin.Cache.log.addAppender(ap);
77 // Tell the user that debug is enabled
78 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
82 System.err.println("Problems initializing the log4j system\n");
86 /** Called when Jalview is started */
87 public static void loadProperties(String propsFile)
89 propertiesFile = propsFile;
90 if (propsFile == null)
92 propertiesFile = System.getProperty("user.home") + File.separatorChar +
93 ".jalview_properties";
98 FileInputStream fis = new FileInputStream(propertiesFile);
99 applicationProperties.load(fis);
100 applicationProperties.remove("LATEST_VERSION");
101 applicationProperties.remove("VERSION");
106 System.out.println("Error reading properties file: " + ex);
109 if (getDefault("USE_PROXY", false))
111 System.out.println("Using proxyServer: " + getDefault("PROXY_SERVER", null) +
112 " proxyPort: " + getDefault("PROXY_PORT", null));
113 System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null));
114 System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
117 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
118 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
119 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
122 String buildDetails = "jar:"
124 Cache.class.getProtectionDomain().getCodeSource().getLocation().
126 .concat("!/.build_properties")
129 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
131 InputStream in = localJarFileURL.openStream();
132 applicationProperties.load(in);
137 System.out.println("Error reading build details: " + ex);
138 applicationProperties.remove("VERSION");
141 String jnlpVersion = System.getProperty("jalview.version");
142 String codeVersion = getProperty("VERSION");
144 if (codeVersion == null)
146 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
147 codeVersion = "Test";
148 jnlpVersion = "Test";
151 System.out.println("Jalview Version: " + codeVersion);
153 // jnlpVersion will be null if we're using InstallAnywhere
154 // Dont do this check if running in headless mode
155 if (jnlpVersion == null && (
156 System.getProperty("java.awt.headless") == null
157 || System.getProperty("java.awt.headless").equals("false")))
165 String jnlpVersion = null;
168 java.net.URL url = new java.net.URL(
169 "http://www.jalview.org/webstart/jalview.jnlp");
170 BufferedReader in = new BufferedReader(new InputStreamReader(url.
173 while ( (line = in.readLine()) != null)
175 if (line.indexOf("jalview.version") == -1)
180 line = line.substring(line.indexOf("value=") + 7);
181 line = line.substring(0, line.lastIndexOf("\""));
188 System.out.println(ex);
189 jnlpVersion = getProperty("VERSION");
192 setProperty("LATEST_VERSION", jnlpVersion);
196 VersionChecker vc = new VersionChecker();
201 if (jnlpVersion != null)
203 setProperty("LATEST_VERSION", jnlpVersion);
207 applicationProperties.remove("LATEST_VERSION");
211 setProperty("VERSION", codeVersion);
213 //LOAD USERDEFINED COLOURS
214 jalview.gui.UserDefinedColours.initUserColourSchemes(getProperty(
215 "USER_DEFINED_COLOURS"));
216 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER", false);
220 * Gets Jalview application property of given key. Returns null
223 * @param key Name of property
225 * @return Property value
227 public static String getProperty(String key)
229 return applicationProperties.getProperty(key);
232 /** These methods are used when checking if the saved preference
233 * is different to the default setting
236 public static boolean getDefault(String property, boolean def)
238 String string = getProperty(property);
241 def = Boolean.valueOf(string).booleanValue();
247 /** These methods are used when checking if the saved preference
248 * is different to the default setting
250 public static String getDefault(String property, String def)
252 String string = getProperty(property);
262 * Stores property in the file "HOME_DIR/.jalview_properties"
264 * @param key Name of object
265 * @param obj String value of property
267 * @return String value of property
269 public static String setProperty(String key, String obj)
273 FileOutputStream out = new FileOutputStream(propertiesFile);
274 applicationProperties.setProperty(key, obj);
275 applicationProperties.store(out, "---JalviewX Properties File---");
280 System.out.println("Error setting property: " + key + " " + obj + "\n" +
286 public static void saveProperties()
290 FileOutputStream out = new FileOutputStream(propertiesFile);
291 applicationProperties.store(out, "---JalviewX Properties File---");
296 System.out.println("Error saving properties: " + ex);
301 * internal vamsas class discovery state
303 private static int vamsasJarsArePresent = -1;
305 * Searches for vamsas client classes on class path.
306 * @return true if vamsas client is present on classpath
308 public static boolean vamsasJarsPresent()
310 if (vamsasJarsArePresent == -1)
314 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
315 "uk.ac.vamsas.client.VorbaId") != null)
317 jalview.bin.Cache.log.debug(
318 "Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
319 vamsasJarsArePresent = 1;
320 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
321 lvclient.setLevel(Level.toLevel(Cache.getDefault("logs.Vamsas.Level",
322 Level.INFO.toString())));
324 lvclient.addAppender(log.getAppender("JalviewLogger"));
325 // Tell the user that debug is enabled
326 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
331 vamsasJarsArePresent = 0;
332 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
335 return (vamsasJarsArePresent > 0);
338 * internal vamsas class discovery state
340 private static int groovyJarsArePresent = -1;
342 * Searches for vamsas client classes on class path.
343 * @return true if vamsas client is present on classpath
345 public static boolean groovyJarsPresent()
347 if (groovyJarsArePresent == -1)
351 if (Cache.class.getClassLoader().loadClass(
352 "groovy.lang.GroovyObject") != null)
354 jalview.bin.Cache.log.debug(
355 "Found Groovy (groovy.lang.GroovyObject can be loaded)");
356 groovyJarsArePresent = 1;
357 Logger lgclient = Logger.getLogger("groovy");
358 lgclient.setLevel(Level.toLevel(Cache.getDefault("logs.Groovy.Level",
359 Level.INFO.toString())));
361 lgclient.addAppender(log.getAppender("JalviewLogger"));
362 // Tell the user that debug is enabled
363 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
368 groovyJarsArePresent = 0;
369 jalview.bin.Cache.log.debug("Groovy Classes are not present");
372 return (groovyJarsArePresent > 0);