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 * Lists and fields within list entries are separated by '|' symbols unless otherwise stated
29 * (|) clauses are alternative values for a tag.
30 * <br><br>Current properties include:
32 * <br>logs.Axis.Level - one of the stringified Levels for log4j controlling the logging level for axis (used for web services)
34 * </li><li>logs.Castor.Level - one of the stringified Levels for log4j controlling the logging level for castor (used for serialization)
36 * </li><li>logs.Jalview.Level - Cache.log stringified level.
38 * </li><li>DISCOVERY_START - Boolean - controls if discovery services are queried on startup
39 * </li><li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
40 * </li><li>SCREEN_WIDTH
41 * </li><li>SCREEN_HEIGHT
42 * </li><li>SCREEN_Y=285
43 * </li><li>SCREEN_X=371
44 * </li><li>SHOW_FULLSCREEN boolean
45 * </li><li>FONT_NAME java font name for alignment text display
46 * </li><li>FONT_SIZE size of displayed alignment text
47 * </li><li>FONT_STYLE style of font displayed (sequence labels are always italic)
48 * </li><li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')
49 * </li><li>LAST_DIRECTORY last directory for browsing alignment
50 * </li><li>USER_DEFINED_COLOURS list of user defined colour scheme files
51 * </li><li>SHOW_FULL_ID show id with '/start-end' numbers appended
52 * </li><li>SHOW_IDENTITY show percentage identity annotation
53 * </li><li>SHOW_QUALITY show alignment quality annotation
54 * </li><li>SHOW_ANNOTATIONS show alignment annotation rows
55 * </li><li>SHOW_CONSERVATION show alignment conservation annotation
56 * </li><li>DEFAULT_COLOUR default colour scheme to apply for a new alignment
57 * </li><li>DEFAULT_FILE_FORMAT file format used to save
58 * </li><li>STARTUP_FILE file loaded on startup (may be a fully qualified url)
59 * </li><li>SHOW_STARTUP_FILE flag to control loading of startup file
60 * </li><li>VERSION the version of the jalview build
61 * </li><li>BUILD_DATE date of this build
62 * </li><li>LATEST_VERSION the latest jalview version advertised on the www.jalview.org
63 * </li><li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER descriptions
64 * </li><li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv suffix to file
65 * </li><li>RECENT_URL list of recently retrieved URLs
66 * </li><li>RECENT_FILE list of recently opened files
67 * </li><li>USE_PROXY flag for whether a http proxy is to be used
68 * </li><li>PROXY_SERVER the proxy
70 * </li><li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire service
71 * </li><li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire service
72 * </li><li>DAS_LOCAL_SOURCE list of local das sources
73 * </li><li>SHOW_OVERVIEW boolean for overview window display
74 * </li><li>ANTI_ALIAS boolean for smooth fonts
75 * </li><li>RIGHT_ALIGN_IDS boolean
76 * </li><li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus
77 * </li><li>PAD_GAPS boolean
78 * </li><li>ID_ITALICS boolean
79 * </li><li>SHOW_JV_SUFFIX
80 * </li><li>WRAP_ALIGNMENT
81 * </li><li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering style check
82 * </li><li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)
83 * </li><li>SEQUENCE_LINKS list of name|URL pairs for opening a url with $SEQUENCE_ID$
84 * </li><li>DAS_REGISTRY_URL the registry to query
85 * </li><li>DEFAULT_BROWSER for unix
86 * </li><li>DAS_ACTIVE_SOURCE list of active sources
98 * property giving log4j level for CASTOR loggers
100 public static final String CASTORLOGLEVEL = "logs.Castor.level";
102 * property giving log4j level for AXIS loggers
104 public static final String AXISLOGLEVEL = "logs.Castor.level";
106 * property giving log4j level for Jalview Log
108 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
109 public static final String DAS_LOCAL_SOURCE = "DAS_LOCAL_SOURCE";
112 * Initialises the Jalview Application Log
114 public static Logger log;
116 /** Jalview Properties */
117 public static Properties applicationProperties = new Properties();
119 /** Default file is ~/.jalview_properties */
120 static String propertiesFile;
122 public static void initLogger()
126 ConsoleAppender ap = new ConsoleAppender(new SimpleLayout(),
128 ap.setName("JalviewLogger");
129 org.apache.log4j.Logger.getRootLogger().addAppender(ap); // catch all for log output
130 Logger laxis = Logger.getLogger("org.apache.axis");
131 Logger lcastor = Logger.getLogger("org.exolab.castor");
132 jalview.bin.Cache.log = Logger.getLogger("jalview.bin.Jalview");
134 laxis.setLevel(Level.toLevel(Cache.getDefault("logs.Axis.Level",
135 Level.INFO.toString())));
136 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
137 Level.INFO.toString())));
138 lcastor = Logger.getLogger("org.exolab.castor.xml");
139 lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
140 Level.INFO.toString())));
141 jalview.bin.Cache.log.setLevel(Level.toLevel(Cache.getDefault(
142 "logs.Jalview.level",
143 Level.INFO.toString())));
144 //laxis.addAppender(ap);
145 //lcastor.addAppender(ap);
146 //jalview.bin.Cache.log.addAppender(ap);
147 // Tell the user that debug is enabled
148 jalview.bin.Cache.log.debug("Jalview Debugging Output Follows.");
152 System.err.println("Problems initializing the log4j system\n");
153 ex.printStackTrace(System.err);
157 /** Called when Jalview is started */
158 public static void loadProperties(String propsFile)
160 propertiesFile = propsFile;
161 if (propsFile == null)
163 propertiesFile = System.getProperty("user.home") + File.separatorChar +
164 ".jalview_properties";
169 FileInputStream fis = new FileInputStream(propertiesFile);
170 applicationProperties.load(fis);
171 applicationProperties.remove("LATEST_VERSION");
172 applicationProperties.remove("VERSION");
177 System.out.println("Error reading properties file: " + ex);
180 if (getDefault("USE_PROXY", false))
182 System.out.println("Using proxyServer: " + getDefault("PROXY_SERVER", null) +
183 " proxyPort: " + getDefault("PROXY_PORT", null));
184 System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null));
185 System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
188 // FIND THE VERSION NUMBER AND BUILD DATE FROM jalview.jar
189 // MUST FOLLOW READING OF LOCAL PROPERTIES FILE AS THE
190 // VERSION MAY HAVE CHANGED SINCE LAST USING JALVIEW
193 String buildDetails = "jar:"
195 Cache.class.getProtectionDomain().getCodeSource().getLocation().
197 .concat("!/.build_properties")
200 java.net.URL localJarFileURL = new java.net.URL(buildDetails);
202 InputStream in = localJarFileURL.openStream();
203 applicationProperties.load(in);
208 System.out.println("Error reading build details: " + ex);
209 applicationProperties.remove("VERSION");
212 String jnlpVersion = System.getProperty("jalview.version");
213 String codeVersion = getProperty("VERSION");
215 if (codeVersion == null)
217 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
218 codeVersion = "Test";
219 jnlpVersion = "Test";
222 System.out.println("Jalview Version: " + codeVersion);
224 // jnlpVersion will be null if we're using InstallAnywhere
225 // Dont do this check if running in headless mode
226 if (jnlpVersion == null && (
227 System.getProperty("java.awt.headless") == null
228 || System.getProperty("java.awt.headless").equals("false")))
236 String jnlpVersion = null;
239 java.net.URL url = new java.net.URL(
240 "http://www.jalview.org/webstart/jalview.jnlp");
241 BufferedReader in = new BufferedReader(new InputStreamReader(url.
244 while ( (line = in.readLine()) != null)
246 if (line.indexOf("jalview.version") == -1)
251 line = line.substring(line.indexOf("value=") + 7);
252 line = line.substring(0, line.lastIndexOf("\""));
259 System.out.println(ex);
260 jnlpVersion = getProperty("VERSION");
263 setProperty("LATEST_VERSION", jnlpVersion);
267 VersionChecker vc = new VersionChecker();
272 if (jnlpVersion != null)
274 setProperty("LATEST_VERSION", jnlpVersion);
278 applicationProperties.remove("LATEST_VERSION");
282 setProperty("VERSION", codeVersion);
284 //LOAD USERDEFINED COLOURS
285 jalview.gui.UserDefinedColours.initUserColourSchemes(getProperty(
286 "USER_DEFINED_COLOURS"));
287 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER", false);
291 * Gets Jalview application property of given key. Returns null
294 * @param key Name of property
296 * @return Property value
298 public static String getProperty(String key)
300 return applicationProperties.getProperty(key);
303 /** These methods are used when checking if the saved preference
304 * is different to the default setting
307 public static boolean getDefault(String property, boolean def)
309 String string = getProperty(property);
312 def = Boolean.valueOf(string).booleanValue();
318 /** These methods are used when checking if the saved preference
319 * is different to the default setting
321 public static String getDefault(String property, String def)
323 String string = getProperty(property);
333 * Stores property in the file "HOME_DIR/.jalview_properties"
335 * @param key Name of object
336 * @param obj String value of property
338 * @return String value of property
340 public static String setProperty(String key, String obj)
344 FileOutputStream out = new FileOutputStream(propertiesFile);
345 applicationProperties.setProperty(key, obj);
346 applicationProperties.store(out, "---JalviewX Properties File---");
351 System.out.println("Error setting property: " + key + " " + obj + "\n" +
357 public static void saveProperties()
361 FileOutputStream out = new FileOutputStream(propertiesFile);
362 applicationProperties.store(out, "---JalviewX Properties File---");
367 System.out.println("Error saving properties: " + ex);
372 * internal vamsas class discovery state
374 private static int vamsasJarsArePresent = -1;
376 * Searches for vamsas client classes on class path.
377 * @return true if vamsas client is present on classpath
379 public static boolean vamsasJarsPresent()
381 if (vamsasJarsArePresent == -1)
385 if (jalview.jbgui.GDesktop.class.getClassLoader().loadClass(
386 "uk.ac.vamsas.client.VorbaId") != null)
388 jalview.bin.Cache.log.debug(
389 "Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
390 vamsasJarsArePresent = 1;
391 Logger lvclient = Logger.getLogger("uk.ac.vamsas");
392 lvclient.setLevel(Level.toLevel(Cache.getDefault("logs.Vamsas.Level",
393 Level.INFO.toString())));
395 lvclient.addAppender(log.getAppender("JalviewLogger"));
396 // Tell the user that debug is enabled
397 lvclient.debug("Jalview Vamsas Client Debugging Output Follows.");
402 vamsasJarsArePresent = 0;
403 jalview.bin.Cache.log.debug("Vamsas Classes are not present");
406 return (vamsasJarsArePresent > 0);
409 * internal vamsas class discovery state
411 private static int groovyJarsArePresent = -1;
413 * Searches for vamsas client classes on class path.
414 * @return true if vamsas client is present on classpath
416 public static boolean groovyJarsPresent()
418 if (groovyJarsArePresent == -1)
422 if (Cache.class.getClassLoader().loadClass(
423 "groovy.lang.GroovyObject") != null)
425 jalview.bin.Cache.log.debug(
426 "Found Groovy (groovy.lang.GroovyObject can be loaded)");
427 groovyJarsArePresent = 1;
428 Logger lgclient = Logger.getLogger("groovy");
429 lgclient.setLevel(Level.toLevel(Cache.getDefault("logs.Groovy.Level",
430 Level.INFO.toString())));
432 lgclient.addAppender(log.getAppender("JalviewLogger"));
433 // Tell the user that debug is enabled
434 lgclient.debug("Jalview Groovy Client Debugging Output Follows.");
439 groovyJarsArePresent = 0;
440 jalview.bin.Cache.log.debug("Groovy Classes are not present");
443 return (groovyJarsArePresent > 0);