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 * property giving log4j level for CASTOR loggers
47 public static final String CASTORLOGLEVEL = "logs.Castor.level";
49 * property giving log4j level for AXIS loggers
51 public static final String AXISLOGLEVEL = "logs.Castor.level";
53 * property giving log4j level for Jalview Log
55 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
58 * Initialises the Jalview Application Log
60 public static Logger log;
62 /** Jalview Properties */
63 public static Properties applicationProperties = new Properties();
65 /** Default file is ~/.jalview_properties */
66 static String propertiesFile;
68 public static void initLogger()
72 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
74 ap.setName("JalviewLogger");
75 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for log output
76 Logger laxis = Logger.getLogger("org.apache.axis");
77 Logger lcastor = Logger.getLogger("org.exolab.castor");
78 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
80 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
81 Level.INFO.toString())));
82 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
83 Level.INFO.toString())));
84 lcastor = Logger.getLogger("org.exolab.castor.xml");
85 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
86 Level.INFO.toString())));
87 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
89 Level.INFO.toString())));
90 //laxis.addAppender(ap);
91 //lcastor.addAppender(ap);
92 //jalview.bin.Cache.log.addAppender(ap);
93 // Tell the user that debug is enabled
94 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
98 System.err.println("Problems initializing the log4j system\n");
99 ex.printStackTrace(System.err);
103 /** Called when Jalview is started */
104 public static void loadProperties(String propsFile)
106 propertiesFile = propsFile;
107 if (propsFile == null)
109 propertiesFile = System.getProperty("user.home") + File.separatorChar +
110 ".jalview_properties";
115 FileInputStream fis = new FileInputStream(propertiesFile);
116 applicationProperties.load(fis);
117 applicationProperties.remove("LATEST_VERSION");
118 applicationProperties.remove("VERSION");
123 System.out.println("Error reading properties file: " + ex);
126 if (getDefault("USE_PROXY", false))
128 System.out.println("Using proxyServer: " + getDefault("PROXY_SERVER", null) +
129 " proxyPort: " + getDefault("PROXY_PORT", null));
130 System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null));
131 System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
134 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
135 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
136 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
139 String buildDetails = "jar:"
141 Cache.class.getProtectionDomain().getCodeSource().getLocation().
143 .concat("!/.build_properties")
146 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
148 InputStream in = localJarFileURL.openStream();
149 applicationProperties.load(in);
154 System.out.println("Error reading build details: " + ex);
155 applicationProperties.remove("VERSION");
158 String jnlpVersion = System.getProperty("jalview.version");
159 String codeVersion = getProperty("VERSION");
161 if (codeVersion == null)
163 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
164 codeVersion = "Test";
165 jnlpVersion = "Test";
168 System.out.println("Jalview Version: " + codeVersion);
170 // jnlpVersion will be null if we're using InstallAnywhere
171 // Dont do this check if running in headless mode
172 if (jnlpVersion == null && (
173 System.getProperty("java.awt.headless") == null
174 || System.getProperty("java.awt.headless").equals("false")))
182 String jnlpVersion = null;
185 java.net.URL url = new java.net.URL(
186 "http://www.jalview.org/webstart/jalview.jnlp");
187 BufferedReader in = new BufferedReader(new InputStreamReader(url.
190 while ( (line = in.readLine()) != null)
192 if (line.indexOf("jalview.version") == -1)
197 line = line.substring(line.indexOf("value=") + 7);
198 line = line.substring(0, line.lastIndexOf("\""));
205 System.out.println(ex);
206 jnlpVersion = getProperty("VERSION");
209 setProperty("LATEST_VERSION", jnlpVersion);
213 VersionChecker vc = new VersionChecker();
218 if (jnlpVersion != null)
220 setProperty("LATEST_VERSION", jnlpVersion);
224 applicationProperties.remove("LATEST_VERSION");
228 setProperty("VERSION", codeVersion);
230 //LOAD USERDEFINED COLOURS
231 jalview.gui.UserDefinedColours.initUserColourSchemes(getProperty(
232 "USER_DEFINED_COLOURS"));
233 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER", false);
237 * Gets Jalview application property of given key. Returns null
240 * @param key Name of property
242 * @return Property value
244 public static String getProperty(String key)
246 return applicationProperties.getProperty(key);
249 /** These methods are used when checking if the saved preference
250 * is different to the default setting
253 public static boolean getDefault(String property, boolean def)
255 String string = getProperty(property);
258 def = Boolean.valueOf(string).booleanValue();
264 /** These methods are used when checking if the saved preference
265 * is different to the default setting
267 public static String getDefault(String property, String def)
269 String string = getProperty(property);
279 * Stores property in the file "HOME_DIR/.jalview_properties"
281 * @param key Name of object
282 * @param obj String value of property
284 * @return String value of property
286 public static String setProperty(String key, String obj)
290 FileOutputStream out = new FileOutputStream(propertiesFile);
291 applicationProperties.setProperty(key, obj);
292 applicationProperties.store(out, "---JalviewX Properties File---");
297 System.out.println("Error setting property: " + key + " " + obj + "\n" +
303 public static void saveProperties()
307 FileOutputStream out = new FileOutputStream(propertiesFile);
308 applicationProperties.store(out, "---JalviewX Properties File---");
313 System.out.println("Error saving properties: " + ex);
318 * internal vamsas class discovery state
320 private static int vamsasJarsArePresent = -1;
322 * Searches for vamsas client classes on class path.
323 * @return true if vamsas client is present on classpath
325 public static boolean vamsasJarsPresent()
327 if (vamsasJarsArePresent == -1)
331 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
332 "uk.ac.vamsas.client.VorbaId") != null)
334 jalview.bin.Cache.log.debug(
335 "Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
336 vamsasJarsArePresent = 1;
337 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
338 lvclient.setLevel(Level.toLevel(Cache.getDefault("logs.Vamsas.Level",
339 Level.INFO.toString())));
341 lvclient.addAppender(log.getAppender("JalviewLogger"));
342 // Tell the user that debug is enabled
343 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
348 vamsasJarsArePresent = 0;
349 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
352 return (vamsasJarsArePresent > 0);
355 * internal vamsas class discovery state
357 private static int groovyJarsArePresent = -1;
359 * Searches for vamsas client classes on class path.
360 * @return true if vamsas client is present on classpath
362 public static boolean groovyJarsPresent()
364 if (groovyJarsArePresent == -1)
368 if (Cache.class.getClassLoader().loadClass(
369 "groovy.lang.GroovyObject") != null)
371 jalview.bin.Cache.log.debug(
372 "Found Groovy (groovy.lang.GroovyObject can be loaded)");
373 groovyJarsArePresent = 1;
374 Logger lgclient = Logger.getLogger("groovy");
375 lgclient.setLevel(Level.toLevel(Cache.getDefault("logs.Groovy.Level",
376 Level.INFO.toString())));
378 lgclient.addAppender(log.getAppender("JalviewLogger"));
379 // Tell the user that debug is enabled
380 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
385 groovyJarsArePresent = 0;
386 jalview.bin.Cache.log.debug("Groovy Classes are not present");
389 return (groovyJarsArePresent > 0);