2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4.0.b2)
3 * Copyright (C) 2009 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 Lists and fields within
28 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
29 * are alternative values for a tag. <br>
31 * Current properties include:
34 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
35 * logging level for axis (used for web services) <br>
37 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
38 * the logging level for castor (used for serialization) <br>
40 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
42 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
44 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.</li>
45 * <li>SCREEN_WIDTH</li>
46 * <li>SCREEN_HEIGHT</li>
47 * <li>SCREEN_Y=285</li>
48 * <li>SCREEN_X=371</li>
49 * <li>SHOW_FULLSCREEN boolean</li>
50 * <li>FONT_NAME java font name for alignment text display</li>
51 * <li>FONT_SIZE size of displayed alignment text</li>
52 * <li>FONT_STYLE style of font displayed (sequence labels are always italic)</li>
53 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
54 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
55 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
56 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
57 * <li>SHOW_IDENTITY show percentage identity annotation</li>
58 * <li>SHOW_QUALITY show alignment quality annotation</li>
59 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
60 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
61 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
63 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
64 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
65 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
66 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
67 * <li>VERSION the version of the jalview build</li>
68 * <li>BUILD_DATE date of this build</li>
69 * <li>LATEST_VERSION the latest jalview version advertised on the
70 * www.jalview.org</li>
71 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
73 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
75 * <li>RECENT_URL list of recently retrieved URLs</li>
76 * <li>RECENT_FILE list of recently opened files</li>
77 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
78 * <li>PROXY_SERVER the proxy</li>
80 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
82 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
84 * <li>USAGESTATS (true) Enable google analytics tracker for collecting usage
86 * <li>DAS_LOCAL_SOURCE list of local das sources</li>
87 * <li>SHOW_OVERVIEW boolean for overview window display</li>
88 * <li>ANTI_ALIAS boolean for smooth fonts</li>
89 * <li>RIGHT_ALIGN_IDS boolean</li>
90 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
91 * <li>PAD_GAPS boolean</li>
92 * <li>ID_ITALICS boolean</li>
93 * <li>SHOW_JV_SUFFIX</li>
94 * <li>WRAP_ALIGNMENT</li>
95 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
97 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
98 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
100 * <li>DAS_REGISTRY_URL the registry to query</li>
101 * <li>DEFAULT_BROWSER for unix</li>
102 * <li>DAS_ACTIVE_SOURCE list of active sources</li>
103 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
110 * @version $Revision$
115 * property giving log4j level for CASTOR loggers
117 public static final String CASTORLOGLEVEL = "logs.Castor.level";
120 * property giving log4j level for AXIS loggers
122 public static final String AXISLOGLEVEL = "logs.Axis.level";
125 * property giving log4j level for Jalview Log
127 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
129 public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
132 * Initialises the Jalview Application Log
134 public static Logger log;
136 /** Jalview Properties */
137 public static Properties applicationProperties = new Properties();
139 /** Default file is ~/.jalview_properties */
140 static String propertiesFile;
142 public static void initLogger()
146 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
148 ap.setName("JalviewLogger");
149 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
151 Logger laxis = Logger.getLogger("org.apache.axis");
152 Logger lcastor = Logger.getLogger("org.exolab.castor");
153 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
155 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
156 Level.INFO.toString())));
157 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
158 Level.INFO.toString())));
159 lcastor = Logger.getLogger("org.exolab.castor.xml");
160 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
161 Level.INFO.toString())));
162 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
163 // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
164 // Level.INFO.toString())));
165 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
166 "logs.Jalview.level", Level.INFO.toString())));
167 // laxis.addAppender(ap);
168 // lcastor.addAppender(ap);
169 // jalview.bin.Cache.log.addAppender(ap);
170 // Tell the user that debug is enabled
171 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
172 } catch (Exception ex)
174 System.err.println("Problems initializing the log4j system\n");
175 ex.printStackTrace(System.err);
179 /** Called when Jalview is started */
180 public static void loadProperties(String propsFile)
182 propertiesFile = propsFile;
183 if (propsFile == null)
185 propertiesFile = System.getProperty("user.home") + File.separatorChar
186 + ".jalview_properties";
191 FileInputStream fis = new FileInputStream(propertiesFile);
192 applicationProperties.load(fis);
193 applicationProperties.remove("LATEST_VERSION");
194 applicationProperties.remove("VERSION");
196 } catch (Exception ex)
198 System.out.println("Error reading properties file: " + ex);
201 if (getDefault("USE_PROXY", false))
203 System.out.println("Using proxyServer: "
204 + getDefault("PROXY_SERVER", null) + " proxyPort: "
205 + getDefault("PROXY_PORT", null));
207 .setProperty("http.proxyHost", getDefault("PROXY_SERVER",
209 System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
212 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
213 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
214 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
217 String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
218 .getCodeSource().getLocation().toString().concat(
219 "!/.build_properties"));
221 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
223 InputStream in = localJarFileURL.openStream();
224 applicationProperties.load(in);
226 } catch (Exception ex)
228 System.out.println("Error reading build details: " + ex);
229 applicationProperties.remove("VERSION");
232 String jnlpVersion = System.getProperty("jalview.version");
233 String codeVersion = getProperty("VERSION");
235 if (codeVersion == null)
237 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
238 codeVersion = "Test";
239 jnlpVersion = "Test";
242 System.out.println("Jalview Version: " + codeVersion);
244 // jnlpVersion will be null if we're using InstallAnywhere
245 // Dont do this check if running in headless mode
246 if (jnlpVersion == null
247 && (System.getProperty("java.awt.headless") == null || System
248 .getProperty("java.awt.headless").equals("false")))
251 class VersionChecker extends Thread
255 String orgtimeout = System
256 .getProperty("sun.net.client.defaultConnectTimeout");
257 if (orgtimeout == null)
260 System.out.println("# INFO: Setting default net timeout to "
261 + orgtimeout + " seconds.");
263 String jnlpVersion = null;
266 System.setProperty("sun.net.client.defaultConnectTimeout",
268 java.net.URL url = new java.net.URL(
269 "http://www.jalview.org/webstart/jalview.jnlp");
270 BufferedReader in = new BufferedReader(new InputStreamReader(
273 while ((line = in.readLine()) != null)
275 if (line.indexOf("jalview.version") == -1)
280 line = line.substring(line.indexOf("value=") + 7);
281 line = line.substring(0, line.lastIndexOf("\""));
285 } catch (Exception ex)
288 .println("Non-fatal exceptions when checking version at www.jalview.org :");
289 System.out.println(ex);
290 jnlpVersion = getProperty("VERSION");
292 System.setProperty("sun.net.client.defaultConnectTimeout",
295 setProperty("LATEST_VERSION", jnlpVersion);
299 VersionChecker vc = new VersionChecker();
304 if (jnlpVersion != null)
306 setProperty("LATEST_VERSION", jnlpVersion);
310 applicationProperties.remove("LATEST_VERSION");
314 setProperty("VERSION", codeVersion);
316 // LOAD USERDEFINED COLOURS
317 jalview.gui.UserDefinedColours
318 .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
319 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
324 * Gets Jalview application property of given key. Returns null if key not
330 * @return Property value
332 public static String getProperty(String key)
334 return applicationProperties.getProperty(key);
338 * These methods are used when checking if the saved preference is different
339 * to the default setting
342 public static boolean getDefault(String property, boolean def)
344 String string = getProperty(property);
347 def = Boolean.valueOf(string).booleanValue();
354 * These methods are used when checking if the saved preference is different
355 * to the default setting
357 public static String getDefault(String property, String def)
359 String string = getProperty(property);
369 * Stores property in the file "HOME_DIR/.jalview_properties"
374 * String value of property
376 * @return String value of property
378 public static String setProperty(String key, String obj)
382 FileOutputStream out = new FileOutputStream(propertiesFile);
383 applicationProperties.setProperty(key, obj);
384 applicationProperties.store(out, "---JalviewX Properties File---");
386 } catch (Exception ex)
388 System.out.println("Error setting property: " + key + " " + obj
394 public static void saveProperties()
398 FileOutputStream out = new FileOutputStream(propertiesFile);
399 applicationProperties.store(out, "---JalviewX Properties File---");
401 } catch (Exception ex)
403 System.out.println("Error saving properties: " + ex);
408 * internal vamsas class discovery state
410 private static int vamsasJarsArePresent = -1;
413 * Searches for vamsas client classes on class path.
415 * @return true if vamsas client is present on classpath
417 public static boolean vamsasJarsPresent()
419 if (vamsasJarsArePresent == -1)
423 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
424 "uk.ac.vamsas.client.VorbaId") != null)
426 jalview.bin.Cache.log
427 .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
428 vamsasJarsArePresent = 1;
429 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
430 lvclient.setLevel(Level.toLevel(Cache.getDefault(
431 "logs.Vamsas.Level", Level.INFO.toString())));
433 lvclient.addAppender(log.getAppender("JalviewLogger"));
434 // Tell the user that debug is enabled
435 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
437 } catch (Exception e)
439 vamsasJarsArePresent = 0;
440 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
443 return (vamsasJarsArePresent > 0);
447 * internal vamsas class discovery state
449 private static int groovyJarsArePresent = -1;
452 * Searches for vamsas client classes on class path.
454 * @return true if vamsas client is present on classpath
456 public static boolean groovyJarsPresent()
458 if (groovyJarsArePresent == -1)
462 if (Cache.class.getClassLoader().loadClass(
463 "groovy.lang.GroovyObject") != null)
465 jalview.bin.Cache.log
466 .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
467 groovyJarsArePresent = 1;
468 Logger lgclient = Logger.getLogger("groovy");
469 lgclient.setLevel(Level.toLevel(Cache.getDefault(
470 "logs.Groovy.Level", Level.INFO.toString())));
472 lgclient.addAppender(log.getAppender("JalviewLogger"));
473 // Tell the user that debug is enabled
474 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
476 } catch (Exception e)
478 groovyJarsArePresent = 0;
479 jalview.bin.Cache.log.debug("Groovy Classes are not present");
482 return (groovyJarsArePresent > 0);
486 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not enabled.
488 protected static Object tracker = null;
489 protected static Class trackerfocus = null;
490 protected static Class jgoogleanalyticstracker = null;
493 * Initialise the google tracker if it is not done already.
495 public static void initGoogleTracker()
499 if (jgoogleanalyticstracker==null)
501 // try to get the tracker class
503 jgoogleanalyticstracker = Cache.class.getClassLoader().loadClass(
504 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
505 trackerfocus = Cache.class.getClassLoader().loadClass(
506 "com.boxysystems.jgoogleanalytics.FocusPoint");
507 } catch (Exception e)
509 log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
511 jgoogleanalyticstracker=null;
516 // now initialise tracker
517 Exception re = null, ex = null;
519 String vrs = "No Version Accessible";
522 // Google analytics tracking code for Library Finder
523 tracker = jgoogleanalyticstracker.getConstructor(new Class[] { String.class,String.class,String.class}).newInstance(new Object[] { "Jalview Desktop",
524 (vrs = jalview.bin.Cache.getProperty("VERSION")
526 + jalview.bin.Cache.getDefault("BUILD_DATE",
527 "unknown")), "UA-9060947-1"});
528 jgoogleanalyticstracker.getMethod("trackAsynchronously", new Class[] { trackerfocus })
529 .invoke(tracker, new Object[] { trackerfocus.getConstructor(
530 new Class[] { String.class}).newInstance(new Object[] { "Application Started." })});
531 } catch (RuntimeException e)
534 } catch (Exception e)
541 if (re != null || ex != null || err != null)
548 "Caught runtime exception in googletracker init:",
552 "Failed to initialise GoogleTracker for Jalview Desktop with version "
556 "Whilst initing GoogleTracker for Jalview Desktop version "
564 .println("Debug: Caught runtime exception in googletracker init:"
566 re.printStackTrace();
571 .println("Warning: Failed to initialise GoogleTracker for Jalview Desktop with version "
573 ex.printStackTrace();
579 .println("ERROR: Whilst initing GoogleTracker for Jalview Desktop version "
581 err.printStackTrace();
587 log.debug("Successfully initialised tracker.");