Ignore:
Timestamp:
2004-01-28T14:37:50+13:00 (20 years ago)
Author:
jmt12
Message:

File associations are now stored in the user specific config. Also, to make everyones life a little easier, the config has a version number which if no match is found, causes the current config to be backed-up, and a new default config created.

File:
1 edited

Legend:

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

    r6622 r6630  
    6868    /** The name of the general Gatherer configuration file. */
    6969    static final private String CONFIG_XML = "config.xml";
     70
     71    static final private String CURRENT_CONFIGURATION_VERSION = "2.4";
    7072    /** The name of the root element of the subtree containing gatherer configuration options. This is required as the document itself may contain several other subtrees of settings (such as in the case of a '.col' file). */
    7173    static final private String GATHERER_CONFIG = "GathererConfig";
     
    189191
    190192    // Try to reload the configuration. The first place we look is the user specific location
    191     File user_config_xml = new File(Utility.getGLIUserFolder(), CONFIG_XML);       
    192     if(user_config_xml != null && user_config_xml.exists()) {
    193         general_config = Utility.parse(user_config_xml.getAbsolutePath(), false);
     193    File config_xml = new File(Utility.getGLIUserFolder(), CONFIG_XML);     
     194    if(config_xml != null && config_xml.exists()) {
     195        general_config = Utility.parse(config_xml.getAbsolutePath(), false);
    194196    }
    195197
    196198    // We then try within the gli directory itself
    197199    if(general_config == null) {
    198         File config_xml = new File(CONFIG_XML);
     200        config_xml = new File(CONFIG_XML);
    199201        if(config_xml.exists()) {
    200202        general_config = Utility.parse(CONFIG_XML, false);
    201203        }
     204    }
     205
     206    // Check the version of the config we have loaded, and if it isn't recent enough, backup the old version, and then create a new config.
     207    if(general_config != null) {
     208        Element configuration_element = general_config.getDocumentElement();
     209        String configuration_version = configuration_element.getAttribute(StaticStrings.VERSION_ATTRIBUTE);
     210        if(!configuration_version.equals(CURRENT_CONFIGURATION_VERSION)) {
     211        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Configuration.Obsolete_Config"), Dictionary.get("Configuration.Obsolete_Config_Title"), JOptionPane.ERROR_MESSAGE);
     212        general_config = null;
     213        configuration_element = null;
     214        File backup = new File(config_xml.getAbsolutePath() + ".bak");
     215        config_xml.renameTo(backup);
     216        backup = null;
     217        }
     218        else {
     219        configuration_element = null;
     220        }
     221        configuration_version = null;
    202222    }
    203223
     
    422442    String email = getString(GENERAL_EMAIL_SETTING, true);
    423443    return (email.length() > 0 ? email : null);
     444    }
     445
     446    public Element getFileAssociations() {
     447    NodeList file_association_elements = general_config.getDocumentElement().getElementsByTagName(StaticStrings.ASSOCIATIONS_ELEMENT);
     448    return (Element) file_association_elements.item(0);
    424449    }
    425450
Note: See TracChangeset for help on using the changeset viewer.