Changeset 8232


Ignore:
Timestamp:
2004-10-07T16:56:41+13:00 (20 years ago)
Author:
mdewsnip
Message:

Removed the "config" variable, just to prevent anyone from trying to use it. Configuration requests should go through the now-static Configuration class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r8231 r8232  
    9696    /** A public reference to the CollectionManager. */
    9797    static public CollectionManager c_man;
    98     /** A public reference to the Gatherer's configuration. */
    99     static public Configuration config;
    10098    /** a reference to the Servlet Configuration is GS3 */
    10199    static public ServletConfiguration servlet_config;
     
    213211        // now set the user specified one
    214212        if (feedback_enabled && feedback_dialog != null) {
    215         feedback_dialog.setLocale(config.getLocale("general.locale", true));
     213        feedback_dialog.setLocale(Configuration.getLocale("general.locale", true));
    216214        }
    217215       
    218216        // Read Dictionary
    219         dictionary = new Dictionary(config.getLocale("general.locale", true), config.getFont("general.font", true));
     217        dictionary = new Dictionary(Configuration.getLocale("general.locale", true), Configuration.getFont("general.font", true));
    220218
    221219
     
    225223
    226224        // If we were given a server run it if neccessary.
    227         if (!GS3 && config.exec_file != null) {
     225        if (!GS3 && Configuration.exec_file != null) {
    228226        startServerEXE();
    229227        }
    230228
    231229        // Having loaded the configuration (necessary to determine if certain warnings have been disabled) and dictionary, we now check if the necessary path variables have been provided.
    232         if (config.exec_file == null && config.exec_address == null) {
    233         if (config.exec_file == null) {
    234             Gatherer.println("config.exec_file is null");
    235         }
    236         if (config.exec_address == null) {
    237             Gatherer.println("config.exec_address is null");
    238         }
     230        if (Configuration.exec_file == null && Configuration.exec_address == null) {
     231        Gatherer.println("config.exec_file is null");
     232        Gatherer.println("config.exec_address is null");
    239233        missingEXEC();
    240234        }
     
    247241        // start the Gatherer without providing a perl path
    248242        boolean found_perl = false;
    249         if (config.perl_path != null) {
     243        if (Configuration.perl_path != null) {
    250244            // See if the file pointed to actually exists
    251             File perl_file = new File(config.perl_path);
     245            File perl_file = new File(Configuration.perl_path);
    252246            found_perl = perl_file.exists();
    253247            perl_file = null;
    254248        }
    255         if (config.perl_path == null || !found_perl) {
     249        if (Configuration.perl_path == null || !found_perl) {
    256250            // Run test to see if we can run perl as is.
    257251            PerlTest perl_test = new PerlTest();
     
    259253            // If so replace the perl path with the system
    260254            // default (or null for unix).
    261             config.perl_path = perl_test.toString();
     255            Configuration.perl_path = perl_test.toString();
    262256            found_perl = true;
    263257            }
     
    270264
    271265        // also check for wget
    272         boolean mirror_workflow = config.get(StaticStrings.WORKFLOW_MIRROR, false);
     266        boolean mirror_workflow = Configuration.get(StaticStrings.WORKFLOW_MIRROR, false);
    273267        if (mirror_workflow) {
    274268        wget_version_str = StaticStrings.NO_WGET_STR;
     
    305299       
    306300        // tell the config the new values
    307         config.setWGetPath(wget_path);
    308         config.setWGetVersion(wget_version_str);
     301        Configuration.setWGetPath(wget_path);
     302        Configuration.setWGetVersion(wget_version_str);
    309303        }
    310304
    311305        // Set default font
    312         setUIFont(config.getFont("general.font", true), config.getFont("general.tooltip_font", true));
     306        setUIFont(Configuration.getFont("general.font", true), Configuration.getFont("general.tooltip_font", true));
    313307        // Set up proxy
    314308        setProxy();
     
    324318        if (GS3) {
    325319        if (site_name==null) {
    326             site_name = config.site_name;
     320            site_name = Configuration.site_name;
    327321            servlet_path = null; // need to reset this
    328322        }
    329323        if (servlet_path == null) {
    330             servlet_path = config.getServletPath();
     324            servlet_path = Configuration.getServletPath();
    331325        }
    332326        }
     
    334328        // If there was an open collection last session, reopen it.
    335329        if (open_collection == null) {
    336         open_collection = config.getString("general.open_collection", true);
     330        open_collection = Configuration.getString("general.open_collection", true);
    337331        }
    338332        if (!no_load && open_collection.length() > 0) {
     
    356350    {
    357351    // Size and place the frame on the screen
    358     Rectangle bounds = config.getBounds("general.bounds", true);
     352    Rectangle bounds = Configuration.getBounds("general.bounds", true);
    359353    if (bounds == null) {
    360354        // Choose a sensible default value
     
    367361        size.width = 640;
    368362    }
    369     else if (size.width > config.screen_size.width) {
    370         size.width = config.screen_size.width;
     363    else if (size.width > Configuration.screen_size.width) {
     364        size.width = Configuration.screen_size.width;
    371365    }
    372366    if (size.height < 480) {
    373367        size.height = 480;
    374368    }
    375     else if (size.height > config.screen_size.height) {
    376         size.height = config.screen_size.height;
     369    else if (size.height > Configuration.screen_size.height) {
     370        size.height = Configuration.screen_size.height;
    377371    }
    378372   
     
    429423    exit = true;
    430424    // If we have an open collection make note of it.
    431     config.setString("general.open_collection", true, null);
     425    Configuration.setString("general.open_collection", true, null);
    432426    if(c_man.ready()) {
    433427        ///ystem.err.println("Collection open.");
    434428        if(c_man.saved()) {
    435429        ///ystem.err.println("Collection has been recently saved, so I'll remember it for next time.");
    436         config.setString("general.open_collection", true, c_man.getCollectionFilename());
     430        Configuration.setString("general.open_collection", true, c_man.getCollectionFilename());
    437431        }
    438432        c_man.closeCollection();
     
    445439    // Store the current position and size (if reasonable) of the Gatherer for next time
    446440    Rectangle bounds = g_man.getBounds();
    447     config.setBounds("general.bounds", true, bounds);
     441    Configuration.setBounds("general.bounds", true, bounds);
    448442
    449443    // Save configuration.
     
    493487    {
    494488    try {
    495         String raw_url = config.exec_address.toString() + command;
     489        String raw_url = Configuration.exec_address.toString() + command;
    496490        URL url = new URL(raw_url);
    497491        Gatherer.println("Action: " + raw_url);
     
    517511    try {
    518512        // need to add the servlet name to the exec address
    519         String raw_url = config.exec_address.toString() + config.getServletPath() + command;
     513        String raw_url = Configuration.exec_address.toString() + Configuration.getServletPath() + command;
    520514        URL url = new URL(raw_url);
    521515        Gatherer.println("Action: " + raw_url);
     
    723717    private void loadConfig(String gsdl_path, String gsdl3_path, String exec_path, String perl_path, boolean mirroring_enabled, String site_name) {
    724718    try {
    725         config = new Configuration(gsdl_path, gsdl3_path, exec_path, perl_path, mirroring_enabled, site_name);
     719        new Configuration(gsdl_path, gsdl3_path, exec_path, perl_path, mirroring_enabled, site_name);
    726720    }
    727721    catch (Exception error) {
     
    741735    private void saveConfig() {
    742736    try {
    743         config.save();
     737        Configuration.save();
    744738    } catch (Exception error) {
    745739        Gatherer.printStackTrace(error);
     
    748742
    749743    private void startServerEXE() {
    750     if(config.exec_file != null && config.exec_address == null && Utility.isWindows() && !GS3) {
     744    if(Configuration.exec_file != null && Configuration.exec_address == null && Utility.isWindows() && !GS3) {
    751745        // First of all we create a GSDLSiteCFG object and check if a URL is already present, in which case the server is already running.
    752         gsdlsite_cfg = new GSDLSiteConfig(config.exec_file);
     746        gsdlsite_cfg = new GSDLSiteConfig(Configuration.exec_file);
    753747        String url = gsdlsite_cfg.getURL();
    754748        // If its already running then set exec address.
    755749        if(url != null) {
    756750        try {
    757             config.exec_address = new URL(url);
     751            Configuration.exec_address = new URL(url);
    758752        }
    759753        catch(Exception error) {
     
    761755        }
    762756        // Otherwise its time to run the server in a spawned process.
    763         if(config.exec_address == null && config.exec_file.exists()) {
     757        if(Configuration.exec_address == null && Configuration.exec_file.exists()) {
    764758        // Configure for immediate entry. Note that this only works if the gsdlsite.cfg file exists.
    765759        gsdlsite_cfg.set();
    766760        // Spawn server
    767         String command = config.exec_file.getAbsolutePath() + " " + gsdlsite_cfg.getSiteConfigFilename();
     761        String command = Configuration.exec_file.getAbsolutePath() + " " + gsdlsite_cfg.getSiteConfigFilename();
    768762        server = new ExternalApplication(command);
    769763        server.start();
     
    793787            if((url = gsdlsite_cfg.getURL()) != null) {
    794788            // Ta-da. Now the url should be available.
    795             config.exec_address = new URL(url);
     789            Configuration.exec_address = new URL(url);
    796790           
    797791            // A quick test involves opening a connection to get the home page  for this collection. If this fails then we try changing the url to be localhost.
    798792            try {
    799                 Gatherer.println("Try connecting to server on config url: '" + config.exec_address + "'");
    800                 URLConnection connection = config.exec_address.openConnection();
     793                Gatherer.println("Try connecting to server on config url: '" + Configuration.exec_address + "'");
     794                URLConnection connection = Configuration.exec_address.openConnection();
    801795                connection.getContent();
    802796            }
     
    804798                try {
    805799                Gatherer.println("Try connecting to server on local host: '" + gsdlsite_cfg.getLocalHostURL() + "'");
    806                 config.exec_address = new URL(gsdlsite_cfg.getLocalHostURL  ());
    807                 URLConnection connection = config.exec_address.openConnection();
     800                Configuration.exec_address = new URL(gsdlsite_cfg.getLocalHostURL   ());
     801                URLConnection connection = Configuration.exec_address.openConnection();
    808802                connection.getContent();
    809803                }
    810804                catch(IOException worse_url_connection) {
    811805                Gatherer.println("Can't connect to server on either address.");
    812                 config.exec_address = null;
    813                 config.exec_file = null;
     806                Configuration.exec_address = null;
     807                Configuration.exec_file = null;
    814808                }
    815809            }
     
    826820        // Can't do a damb thing.
    827821    }
    828     Gatherer.println("Having started server.exe, exec_address is: " + config.exec_address);
     822    Gatherer.println("Having started server.exe, exec_address is: " + Configuration.exec_address);
    829823    }
    830824
    831825    private void stopServerEXE() {
    832     if(server != null && config.exec_address != null) {
     826    if(server != null && Configuration.exec_address != null) {
    833827        // See if its already exited for some reason.
    834828        gsdlsite_cfg.load();
Note: See TracChangeset for help on using the changeset viewer.