import java.util.*; import java.text.*; import java.io.*; /** * Reads info about environment variables from the .properties file * * @author aleman-meza, boanerges */ public class Environment { private static final String PROPERTIES_FILE = "dev_environment.properties"; private static final String PREFIX = "directory."; public static String HTML_DIRECTORY; public static String GNUPLOT; public static String PBM2GIF; public static String BASEURL; public static String SERVLET_UPLOAD; public static String SERVLET_GNUPLOT; public static String COLUMNS_DATA; public static String INDEX_HTML; private static String propertiesFileLocation; static { try { // read a system property of interest. it is set when this is ran like: // java -Dproperties.dir=/somedirectory/ Environment propertiesFileLocation = System.getProperty( "properties.dir", "" ); if( propertiesFileLocation != null && propertiesFileLocation != "" && ! propertiesFileLocation.endsWith( File.separator ) ) { propertiesFileLocation = propertiesFileLocation + File.separator; } Properties prop = new Properties(); prop.load( new FileInputStream( new File( propertiesFileLocation + PROPERTIES_FILE ) ) ); HTML_DIRECTORY = prop.getProperty( "html.directory", "/home/aleman/public_html/" ); if( ! HTML_DIRECTORY.endsWith( File.separator ) ) { HTML_DIRECTORY = HTML_DIRECTORY + File.separator; } GNUPLOT = prop.getProperty( "gnuplot", "/home/aleman/gnuplot" ); PBM2GIF = prop.getProperty( "pbm2gif", "/home/aleman/pbm2gif" ); BASEURL = prop.getProperty( "baseurl", "http://gene.genetics.uga.edu/~aleman/" ); if( ! BASEURL.endsWith( File.separator ) ) { BASEURL = BASEURL + File.separator; } SERVLET_UPLOAD = prop.getProperty( "servlet.upload", "http://gene.genetics.uga.edu:8080/servlet/FileUploadServlet" ); SERVLET_GNUPLOT = prop.getProperty( "servlet.gnuplot", "http://gene.genetics.uga.edu:8080/servlet/GnuplotServlet" ); COLUMNS_DATA = prop.getProperty( "columns_data.file", "columns.data" ); INDEX_HTML = prop.getProperty( "index_html.file", "index.html" ); // rewrite the properties file to set the default values when // the propertiesFileLocation has some path on it. (this class // was ran with something like -Dproperties.dir=/web/ab/ ) if( propertiesFileLocation != null & propertiesFileLocation != "" ) { prop.setProperty( "html.directory", HTML_DIRECTORY ); prop.setProperty( "gnuplot", GNUPLOT); prop.setProperty( "pbm2gif", PBM2GIF ); prop.setProperty( "baseurl", BASEURL ); prop.setProperty( "servlet.upload", SERVLET_UPLOAD ); prop.setProperty( "servlet.gnuplot", SERVLET_GNUPLOT ); prop.setProperty( "columns_data.file", COLUMNS_DATA ); prop.setProperty( "index_html.file", INDEX_HTML ); prop.store( new FileOutputStream( new File( propertiesFileLocation + PROPERTIES_FILE ) ), null ); } } catch( IOException ioe ) { String errmsg = "Environment: Error loading system properties"; System.err.println( errmsg ); errorReport( errmsg ); ioe.printStackTrace(); System.exit( -1 ); } } private Environment() { } /** * Creates/Updates the 'home' html file * uses the info from the .properties file to create a link * per directory number */ public static void createHtml() { try { Properties prop = new Properties(); prop.load( new FileInputStream( new File( propertiesFileLocation + PROPERTIES_FILE ) ) ); PrintStream htmlFile = new PrintStream( new FileOutputStream( new File( HTML_DIRECTORY + INDEX_HTML ) ) ); htmlFile.println(); htmlFile.println( "" ); htmlFile.println( "
" ); htmlFile.println( "