Changeset 24465

Show
Ignore:
Timestamp:
24.08.2011 16:52:43 (8 years ago)
Author:
ak19
Message:

Server2 now takes an additional parameter -mode, which can be 'gli' and represents the property prefix to use when looking for autoenter and start_browser properties in the config file. The way the arguments to Server2 are processed has also been changed, so that it is no longer dependent on order.

Location:
main/trunk/greenstone3/src/java/org/greenstone/server
Files:
2 modified

Legend:

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

    r24455 r24465  
    3131{ 
    3232    private static final int WAITING_TIME = 10; // time to wait and check for whether the server is running 
    33     private static final String URL_PENDING="URL_pending"; 
    34  
     33    private static final String URL_PENDING="URL_pending";   
     34     
    3535    protected String libraryURL; 
    36  
     36     
    3737    private class QuitListener extends Thread  
    3838    { 
     
    103103 
    104104 
    105     public Server2(String gsdl2_home, String lang, String configfile, int quitPort) 
     105    public Server2(String gsdl2_home, String lang, String configfile, int quitPort, String property_prefix) 
    106106    { 
    107107    super(gsdl2_home, lang, configfile, "etc"+File.separator+"logs-gsi");    
    108                    // configfile can be either glisite.cfg or llssite.cfg 
    109  
    110     Property = new Server2Property(); 
     108                   // configfile can be either glisite.cfg or llssite.cfg    
     109 
     110    //logger_.error("gsdlhome: " + gsdl2_home + " | lang: " + lang + " | configfile: "  
     111        //+ configfile + " | mode: " + property_prefix + " | quitport: " + quitPort); 
     112     
     113    // property_prefix is the mode we're running in (gli or empty) and contains the prefix 
     114    // string to look for in config file for auto_enter and start_browser properties     
     115    if(!property_prefix.equals("") && !property_prefix.endsWith(".")) { // ensure a '.' is suffixed if non-empty 
     116        property_prefix += "."; 
     117    } 
     118    Property = new Server2Property(property_prefix); 
     119     
    111120     
    112121    String frame_title = dictionary.get("ServerControl.Frame_Title"); 
     
    422431    public static void main (String[] args) 
    423432    { 
    424         if ((args.length < 1) || (args.length > 4)) { 
     433        if ((args.length < 1) || (args.length > 5)) { 
    425434        System.err.println( 
    426            "Usage: java org.greenstone.server.Server2 <gsdl2-home-dir> [lang] [--config=configfile] [--quitport=portNum]"); 
     435           "Usage: java org.greenstone.server.Server2 <gsdl2-home-dir> [lang] [--mode=\"gli\"] [--config=configfile] [--quitport=portNum]"); 
    427436        System.exit(1); 
    428     } 
     437        } 
    429438     
    430439    String gsdl2_home = args[0]; 
     
    435444    } 
    436445     
    437     String lang = (args.length>=2) ? args[1] : "en"; 
    438      
     446    int index = 1; // move onto any subsequent arguments 
     447     
     448    // defaults for optional arguments 
    439449    // if no config file is given, then it defaults to llssite.cfg (embedded in quotes to preserve spaces in the filepath) 
    440     File defaultConfigFile = new File(gsdl2_dir, "llssite.cfg"); 
    441     String configfile = (args.length>=3 && args[2].startsWith("--config=")) ? args[2] : defaultConfigFile.getAbsolutePath(); 
    442     gsdl2_dir = null; 
    443     defaultConfigFile = null; 
    444  
    445     int equalSign = configfile.indexOf('='); 
    446     if(equalSign != -1) { 
    447         configfile = configfile.substring(equalSign+1); 
    448     } 
    449  
    450     String quitport = (args.length == 4 && args[3].startsWith("--quitport=")) ? args[3] : ""; 
    451     equalSign = quitport.indexOf('='); 
     450    File defaultConfigFile = new File(gsdl2_dir, "llssite.cfg");     
     451    String configfile = defaultConfigFile.getAbsolutePath(); 
    452452    int port = -1; 
    453     if(equalSign != -1) { 
    454         try { 
    455         quitport = quitport.substring(equalSign+1); 
    456         port = Integer.parseInt(quitport); 
    457         } catch(Exception e) { // parse fails 
    458         System.err.println("Port must be numeric. Continuing without it."); 
    459         } 
    460     } 
    461  
    462     //System.err.println("Running server with config file: " + configfile); 
    463      
    464     new Server2(gsdl2_home, lang, configfile, port); 
     453    String mode = ""; 
     454    String lang = "en";  
     455     
     456    // cycle through arguments, parsing and storing them 
     457    while(args.length > index) { 
     458             
     459        if(args[index].startsWith("--config=")) { 
     460            configfile = args[index].substring(args[index].indexOf('=')+1); // get value after '=' sign          
     461            gsdl2_dir = null; 
     462            defaultConfigFile = null; 
     463        } 
     464         
     465        else if(args[index].startsWith("--quitport=")) { 
     466            String quitport = args[index].substring(args[index].indexOf('=')+1);             
     467            try {                
     468                port = Integer.parseInt(quitport); 
     469            } catch(Exception e) { // parse fails 
     470                System.err.println("Port must be numeric. Continuing without it."); 
     471            }        
     472        } 
     473         
     474        // mode can be: "gli" if launched by GLI or unspecified. If unspecified, then  
     475        // the gs2-server was launched independently. 
     476        else if(args[index].startsWith("--mode=")) { 
     477            mode = args[index].substring(args[index].indexOf('=')+1); 
     478        } 
     479         
     480        else if(args[index].length() == 2) {  
     481            // there is an optional argument, but without a --FLAGNAME= prefix, so it's a language code          
     482            lang = args[index]; 
     483        } 
     484         
     485        index++; 
     486    } 
     487     
     488    new Server2(gsdl2_home, lang, configfile, port, mode); 
    465489    } 
    466490} 
  • main/trunk/greenstone3/src/java/org/greenstone/server/Server2Property.java

    r24207 r24465  
    55public class Server2Property extends BaseProperty  
    66{ 
    7     Server2Property() 
     7    Server2Property(String property_prefix) 
    88    { 
    99    // Initialising customised final variables  
    1010    // Version number, WEB_PORT 
    11     super("2", "portnumber", "autoenter", "start_browser", "keepport"); 
     11    super("2", "portnumber", property_prefix+"autoenter", property_prefix+"start_browser", "keepport"); 
    1212    } 
    1313