Changeset 24491 for main/trunk


Ignore:
Timestamp:
2011-08-26T15:32:35+12:00 (13 years ago)
Author:
ak19
Message:

Now Server2's main method handles messy commandline arguments of the kind where parameters are split over multiple arguments, which can happen when gs2-webserver.bat calls Server2 now. The logic of dealing with spaces in filepath (and messy parameters) is therefore moved now from gs2-webserver.bat into Server2.java

File:
1 edited

Legend:

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

    r24479 r24491  
    1414import java.net.URL;
    1515//import java.net.URLConnection;
     16import java.util.ArrayList;
    1617import java.util.Properties;
    17 import java.util.ArrayList;
     18import java.util.StringTokenizer;
    1819
    1920import org.apache.log4j.*;
     
    449450    }
    450451   
    451     int index = 1; // move onto any subsequent arguments
    452    
    453     // defaults for optional arguments
    454     // if no config file is given, then it defaults to llssite.cfg (embedded in quotes to preserve spaces in the filepath)
     452    //for(int i = 0; i < args.length; i++) { System.err.println("Arg[" + i + "]: |" + args[i] + "|");   }
     453   
     454    // for every subsequent argument, check whether we're dealing with amalgamated
     455    // parameters in that argument. If so, split on whitespace and reconstruct arguments
     456    for(int i = 1; i < args.length; i++) {
     457   
     458        // if the *last* occurrence of a flag parameter is not at the start of
     459        // this argument then we're dealing with amalgamated parameters in this
     460        // argument. Need to split on whitespace and reconstitute the args list
     461        int lastIndex = args[i].lastIndexOf("--");
     462        if(lastIndex > 0) {
     463       
     464            StringTokenizer tokenizer = new StringTokenizer(args[i]); // splits on whitespace
     465            String[] tokens = new String[tokenizer.countTokens()+i];
     466            int j = 0;
     467            for(; j < i; j++) { // copy over previous arguments
     468                tokens[j] = args[j];
     469            }
     470           
     471            // the remainder comes from the tokens
     472            for(; tokenizer.hasMoreTokens(); j++) {
     473                tokens[j] = tokenizer.nextToken();
     474            }
     475            args = null;
     476            args = tokens;
     477        }
     478       
     479    }   
     480   
     481    // Defaults for optional arguments
     482   
     483    // if no config file is given, then it defaults to llssite.cfg
     484    // (embedded in quotes to preserve spaces in the filepath)
    455485    File defaultConfigFile = new File(gsdl2_dir, "llssite.cfg");   
    456486    String configfile = defaultConfigFile.getAbsolutePath();
    457487    int port = -1;
    458488    String mode = "";
    459     String lang = "en";
    460    
    461     // cycle through arguments, parsing and storing them
     489    String lang = "en";
     490   
     491    int index = 1; // move onto any subsequent arguments (past 1st GSDLHOME arg)
     492    if (args.length > index && !args[index].startsWith("--")) {
     493        lang = args[index]; // 2nd arg is not a flag option, so must be language
     494        index++;
     495    }   
     496   
     497    // Cycle through arguments, parsing and storing them
     498    // note that the batch file could have split arguments in the config-
     499    // filepath over several parameters. Here we join them back up again.
    462500    while(args.length > index) {
    463501           
     
    483521        }
    484522       
    485         else if(args[index].length() == 2) {
    486             // there is an optional argument, but without a --FLAGNAME= prefix, so it's a language code         
    487             lang = args[index];
     523        else if(!args[index].startsWith("--")) { // assume it's part of the config file name (that this path had spaces in it)
     524            configfile = configfile + " " + args[index]; // reinstate space in path
    488525        }
    489526       
    490527        index++;
    491528    }
    492    
     529
     530    //System.err.println("\n\n*******\n\ngsdlhome: " + gsdl2_home + " | lang: " + lang + " |configfile:"
     531    //  + configfile + "| mode: " + mode + " | quitport: " + port + "\n\n*************\n");
    493532    new Server2(gsdl2_home, lang, configfile, port, mode);
    494533    }
Note: See TracChangeset for help on using the changeset viewer.