Changeset 18673

Show
Ignore:
Timestamp:
13.03.2009 13:27:00 (10 years ago)
Author:
ak19
Message:

Some minor changes: 1. More abstract and overloadable methods; 2. Removed dependency on GS3-specific GlobalProperties?.java; 3. reloadBuildProperties() now loads from the already stored build_properties_file.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/server/BaseServer.java

    r18558 r18673  
    44import java.awt.Dimension; 
    55import java.awt.Toolkit; 
     6import java.io.BufferedReader; 
    67import java.io.File; 
    7 import java.io.InputStream; 
     8import java.io.FileInputStream; 
     9import java.io.InputStreamReader; 
    810import java.util.Properties; 
    9 import java.io.BufferedReader; 
    10 import java.io.InputStream; 
    11 import java.io.InputStreamReader; 
    1211 
    1312import org.apache.log4j.*; 
    1413 
    1514import org.greenstone.gsdl3.util.Dictionary; 
    16 import org.greenstone.gsdl3.util.GlobalProperties; 
    1715 
    1816public abstract class BaseServer  
     
    2321    static protected String STOP_CMD; 
    2422 
    25     protected static final int SERVER_STARTED = 0; 
    26     protected static final int SERVER_START_FAILED = 1; 
    27     protected static final int BROWSER_LAUNCHED = 2; 
    28     protected static final int BROWSER_LAUNCH_FAILED = 3;  
    29      
     23    static protected final int SERVER_STARTED = 0; 
     24    static protected final int SERVER_START_FAILED = 1; 
     25    static protected final int BROWSER_LAUNCHED = 2; 
     26    static protected final int BROWSER_LAUNCH_FAILED = 3;  
     27  
     28    static protected Properties build_properties; 
     29    static protected Logger logger_; 
     30 
     31    static public File build_properties_file; 
     32    static public Dictionary dictionary; 
     33    static public BaseProperty Property; 
     34 
    3035    protected int server_state_ = -1;     
    31  
    3236    protected boolean configure_required_ = true; 
    33  
    34     public static File build_properties_file; 
    35     protected static Properties build_properties; 
    36     public static Dictionary dictionary; 
    37       
    38     public static BaseProperty Property; 
    39  
     37    protected String gsdl_home; 
    4038    protected BaseServerControl server_control_;     
    41  
    42     static protected Logger logger_; 
    43      
    44     public BaseServer(String gsdl_home, String lang) 
    45     { 
     39     
     40    protected BaseServer(String gsdl_home, String lang, String build_properties_path) 
     41    { 
     42    this.gsdl_home = gsdl_home; 
     43 
     44    // make sure we write to the correct logs 
     45    initLogger(); 
    4646    logger_ = Logger.getLogger(BaseServer.class.getName()); 
    4747 
    48     String build_properties_path=gsdl_home+File.separatorChar+"build.properties"; 
    4948    build_properties_file = new File(build_properties_path); 
    5049 
     
    6059 
    6160    } 
     61 
     62    // override to write to the correct logs 
     63    protected void initLogger() {} 
    6264 
    6365    public void autoStart() 
     
    103105           recordError(CONFIGURE_CMD); 
    104106       } 
    105        GlobalProperties.reload(); // properties file may have changed, so reload it 
     107       reload(); 
    106108       configure_required_ = false; 
    107109    } 
     
    126128     
    127129    protected void recordError(String message){ 
    128         message = dictionary.get("ServerControl.Error",new String[]{message,GlobalProperties.getGSDL3Home()}); 
     130        message = dictionary.get("ServerControl.Error",new String[]{message,gsdl_home}); 
    129131    server_control_.displayMessage(message); 
    130132    logger_.error(dictionary.get("ServerControl.Failed",new String[]{message})); 
     
    133135 
    134136    protected void recordError(String message, Exception e){ 
    135         message = dictionary.get("ServerControl.Error",new String[]{message,GlobalProperties.getGSDL3Home()}); 
     137        message = dictionary.get("ServerControl.Error",new String[]{message,gsdl_home}); 
    136138    server_control_.displayMessage(message); 
    137139    logger_.error(dictionary.get("ServerControl.Failed",new String[]{message}),e); 
     
    145147 
    146148    
     149    public abstract String getBrowserURL(); 
     150    public abstract void reload(); // reload properties, since they may have changed 
     151 
    147152    public void launchBrowser() { 
    148153        server_state_ = -1; 
     
    150155        String message = dictionary.get("ServerControl.LaunchingBrowser"); 
    151156        server_control_.displayMessage(message);  
    152     String url = GlobalProperties.getGSDL3WebAddress()+ build_properties.getProperty(BaseServer.Property.DEFAULT_SERVLET); 
     157    String url = getBrowserURL(); 
     158    //recordError("**** browserURL: " + url); 
    153159    BrowserLauncher launcher = new BrowserLauncher(build_properties.getProperty(BaseServer.Property.BROWSER_PATH),url); 
    154160        logger_.info(message); 
     
    208214    public  void reloadBuildProperties() { 
    209215    try { 
    210         InputStream in = this.getClass().getClassLoader().getResourceAsStream("build.properties"); 
    211          
     216        //InputStream in = this.getClass().getClassLoader().getResourceAsStream("build.properties"); 
     217        FileInputStream in = new FileInputStream(build_properties_file); 
     218 
    212219        if (in != null) { 
    213220        logger_.info("loading build properties");