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.*;
26 import com.boxysystems.jgoogleanalytics.FocusPoint;
27 import com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker;
30 * Stores and retrieves Jalview Application Properties Lists and fields within
31 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
32 * are alternative values for a tag. <br>
34 * Current properties include:
37 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
38 * logging level for axis (used for web services) <br>
40 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
41 * the logging level for castor (used for serialization) <br>
43 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
45 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
47 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.</li>
48 * <li>SCREEN_WIDTH</li>
49 * <li>SCREEN_HEIGHT</li>
50 * <li>SCREEN_Y=285</li>
51 * <li>SCREEN_X=371</li>
52 * <li>SHOW_FULLSCREEN boolean</li>
53 * <li>FONT_NAME java font name for alignment text display</li>
54 * <li>FONT_SIZE size of displayed alignment text</li>
55 * <li>FONT_STYLE style of font displayed (sequence labels are always italic)</li>
56 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
57 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
58 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
59 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
60 * <li>SHOW_IDENTITY show percentage identity annotation</li>
61 * <li>SHOW_QUALITY show alignment quality annotation</li>
62 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
63 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
64 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
66 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
67 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
68 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
69 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
70 * <li>VERSION the version of the jalview build</li>
71 * <li>BUILD_DATE date of this build</li>
72 * <li>LATEST_VERSION the latest jalview version advertised on the
73 * www.jalview.org</li>
74 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
76 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
78 * <li>RECENT_URL list of recently retrieved URLs</li>
79 * <li>RECENT_FILE list of recently opened files</li>
80 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
81 * <li>PROXY_SERVER the proxy</li>
83 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
85 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
87 * <li>USAGESTATS (true) Enable google analytics tracker for collecting usage
89 * <li>DAS_LOCAL_SOURCE list of local das sources</li>
90 * <li>SHOW_OVERVIEW boolean for overview window display</li>
91 * <li>ANTI_ALIAS boolean for smooth fonts</li>
92 * <li>RIGHT_ALIGN_IDS boolean</li>
93 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
94 * <li>PAD_GAPS boolean</li>
95 * <li>ID_ITALICS boolean</li>
96 * <li>SHOW_JV_SUFFIX</li>
97 * <li>WRAP_ALIGNMENT</li>
98 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
100 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
101 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
103 * <li>DAS_REGISTRY_URL the registry to query</li>
104 * <li>DEFAULT_BROWSER for unix</li>
105 * <li>DAS_ACTIVE_SOURCE list of active sources</li>
106 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
113 * @version $Revision$
118 * property giving log4j level for CASTOR loggers
120 public static final String CASTORLOGLEVEL = "logs.Castor.level";
123 * property giving log4j level for AXIS loggers
125 public static final String AXISLOGLEVEL = "logs.Axis.level";
128 * property giving log4j level for Jalview Log
130 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
132 public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
135 * Initialises the Jalview Application Log
137 public static Logger log;
139 /** Jalview Properties */
140 public static Properties applicationProperties = new Properties();
142 /** Default file is ~/.jalview_properties */
143 static String propertiesFile;
145 public static void initLogger()
149 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
151 ap.setName("JalviewLogger");
152 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for
154 Logger laxis = Logger.getLogger("org.apache.axis");
155 Logger lcastor = Logger.getLogger("org.exolab.castor");
156 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
158 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
159 Level.INFO.toString())));
160 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
161 Level.INFO.toString())));
162 lcastor = Logger.getLogger("org.exolab.castor.xml");
163 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
164 Level.INFO.toString())));
165 // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
166 // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
167 // Level.INFO.toString())));
168 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
169 "logs.Jalview.level", Level.INFO.toString())));
170 // laxis.addAppender(ap);
171 // lcastor.addAppender(ap);
172 // jalview.bin.Cache.log.addAppender(ap);
173 // Tell the user that debug is enabled
174 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
175 } catch (Exception ex)
177 System.err.println("Problems initializing the log4j system\n");
178 ex.printStackTrace(System.err);
182 /** Called when Jalview is started */
183 public static void loadProperties(String propsFile)
185 propertiesFile = propsFile;
186 if (propsFile == null)
188 propertiesFile = System.getProperty("user.home") + File.separatorChar
189 + ".jalview_properties";
194 FileInputStream fis = new FileInputStream(propertiesFile);
195 applicationProperties.load(fis);
196 applicationProperties.remove("LATEST_VERSION");
197 applicationProperties.remove("VERSION");
199 } catch (Exception ex)
201 System.out.println("Error reading properties file: " + ex);
204 if (getDefault("USE_PROXY", false))
206 System.out.println("Using proxyServer: "
207 + getDefault("PROXY_SERVER", null) + " proxyPort: "
208 + getDefault("PROXY_PORT", null));
210 .setProperty("http.proxyHost", getDefault("PROXY_SERVER",
212 System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
215 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
216 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
217 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
220 String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
221 .getCodeSource().getLocation().toString().concat(
222 "!/.build_properties"));
224 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
226 InputStream in = localJarFileURL.openStream();
227 applicationProperties.load(in);
229 } catch (Exception ex)
231 System.out.println("Error reading build details: " + ex);
232 applicationProperties.remove("VERSION");
235 String jnlpVersion = System.getProperty("jalview.version");
236 String codeVersion = getProperty("VERSION");
238 if (codeVersion == null)
240 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
241 codeVersion = "Test";
242 jnlpVersion = "Test";
245 System.out.println("Jalview Version: " + codeVersion);
247 // jnlpVersion will be null if we're using InstallAnywhere
248 // Dont do this check if running in headless mode
249 if (jnlpVersion == null
250 && (System.getProperty("java.awt.headless") == null || System
251 .getProperty("java.awt.headless").equals("false")))
254 class VersionChecker extends Thread
258 String orgtimeout = System
259 .getProperty("sun.net.client.defaultConnectTimeout");
260 if (orgtimeout == null)
263 System.out.println("# INFO: Setting default net timeout to "
264 + orgtimeout + " seconds.");
266 String jnlpVersion = null;
269 System.setProperty("sun.net.client.defaultConnectTimeout",
271 java.net.URL url = new java.net.URL(
272 "http://www.jalview.org/webstart/jalview.jnlp");
273 BufferedReader in = new BufferedReader(new InputStreamReader(
276 while ((line = in.readLine()) != null)
278 if (line.indexOf("jalview.version") == -1)
283 line = line.substring(line.indexOf("value=") + 7);
284 line = line.substring(0, line.lastIndexOf("\""));
288 } catch (Exception ex)
291 .println("Non-fatal exceptions when checking version at www.jalview.org :");
292 System.out.println(ex);
293 jnlpVersion = getProperty("VERSION");
295 System.setProperty("sun.net.client.defaultConnectTimeout",
298 setProperty("LATEST_VERSION", jnlpVersion);
302 VersionChecker vc = new VersionChecker();
307 if (jnlpVersion != null)
309 setProperty("LATEST_VERSION", jnlpVersion);
313 applicationProperties.remove("LATEST_VERSION");
317 setProperty("VERSION", codeVersion);
319 // LOAD USERDEFINED COLOURS
320 jalview.gui.UserDefinedColours
321 .initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
322 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
327 * Gets Jalview application property of given key. Returns null if key not
333 * @return Property value
335 public static String getProperty(String key)
337 return applicationProperties.getProperty(key);
341 * These methods are used when checking if the saved preference is different
342 * to the default setting
345 public static boolean getDefault(String property, boolean def)
347 String string = getProperty(property);
350 def = Boolean.valueOf(string).booleanValue();
357 * These methods are used when checking if the saved preference is different
358 * to the default setting
360 public static String getDefault(String property, String def)
362 String string = getProperty(property);
372 * Stores property in the file "HOME_DIR/.jalview_properties"
377 * String value of property
379 * @return String value of property
381 public static String setProperty(String key, String obj)
385 FileOutputStream out = new FileOutputStream(propertiesFile);
386 applicationProperties.setProperty(key, obj);
387 applicationProperties.store(out, "---JalviewX Properties File---");
389 } catch (Exception ex)
391 System.out.println("Error setting property: " + key + " " + obj
397 public static void saveProperties()
401 FileOutputStream out = new FileOutputStream(propertiesFile);
402 applicationProperties.store(out, "---JalviewX Properties File---");
404 } catch (Exception ex)
406 System.out.println("Error saving properties: " + ex);
411 * internal vamsas class discovery state
413 private static int vamsasJarsArePresent = -1;
416 * Searches for vamsas client classes on class path.
418 * @return true if vamsas client is present on classpath
420 public static boolean vamsasJarsPresent()
422 if (vamsasJarsArePresent == -1)
426 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
427 "uk.ac.vamsas.client.VorbaId") != null)
429 jalview.bin.Cache.log
430 .debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
431 vamsasJarsArePresent = 1;
432 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
433 lvclient.setLevel(Level.toLevel(Cache.getDefault(
434 "logs.Vamsas.Level", Level.INFO.toString())));
436 lvclient.addAppender(log.getAppender("JalviewLogger"));
437 // Tell the user that debug is enabled
438 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
440 } catch (Exception e)
442 vamsasJarsArePresent = 0;
443 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
446 return (vamsasJarsArePresent > 0);
450 * internal vamsas class discovery state
452 private static int groovyJarsArePresent = -1;
455 * Searches for vamsas client classes on class path.
457 * @return true if vamsas client is present on classpath
459 public static boolean groovyJarsPresent()
461 if (groovyJarsArePresent == -1)
465 if (Cache.class.getClassLoader().loadClass(
466 "groovy.lang.GroovyObject") != null)
468 jalview.bin.Cache.log
469 .debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
470 groovyJarsArePresent = 1;
471 Logger lgclient = Logger.getLogger("groovy");
472 lgclient.setLevel(Level.toLevel(Cache.getDefault(
473 "logs.Groovy.Level", Level.INFO.toString())));
475 lgclient.addAppender(log.getAppender("JalviewLogger"));
476 // Tell the user that debug is enabled
477 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
479 } catch (Exception e)
481 groovyJarsArePresent = 0;
482 jalview.bin.Cache.log.debug("Groovy Classes are not present");
485 return (groovyJarsArePresent > 0);
489 * GA tracker object - null if tracking not enabled.
491 public static JGoogleAnalyticsTracker tracker = null;
494 * Initialise the google tracker if it is not done already.
496 public static void initGoogleTracker()
500 String vrs = "No Version Accessible";
503 // Google analytics tracking code for Library Finder
504 tracker = new JGoogleAnalyticsTracker("Jalview Desktop",
505 (vrs = jalview.bin.Cache.getProperty("VERSION")
507 + jalview.bin.Cache.getDefault("BUILD_DATE",
508 "unknown")), "UA-9060947-1");
509 tracker.trackAsynchronously(new FocusPoint("Application Started."));
510 } catch (RuntimeException e)
514 log.debug("Caught runtime exception in googletracker init:", e);
517 } catch (Exception e)
523 "Failed to initialise GoogleTracker for Jalview Desktop with version "
529 "Failed to initialise GoogleTracker for Jalview Desktop with version "