Ignore:
Timestamp:
2003-12-02T17:15:47+13:00 (20 years ago)
Author:
jmt12
Message:

Moved the special folder 'shortcuts' from collection based to shared for the installation of gli. This caused some added fun when it turned out one of the workspace tree refreshes was blocking the AWTEvent thread, despite me putting tests in place to stop that from happening. It had never reared its ugly head before, as there were never any shortcut collections being mapped when a collection had been closed, or when GLI was exiting before.

File:
1 edited

Legend:

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

    r6051 r6086  
    4545import javax.swing.plaf.*;
    4646import org.greenstone.gatherer.msm.MSMUtils;
     47import org.greenstone.gatherer.util.StaticStrings;
    4748import org.greenstone.gatherer.util.Utility;
    4849import org.w3c.dom.*;
     
    100101    /** The general configuration settings. */
    101102    private Document general_config;
     103   
     104    /** The element, from glis config file, that contains the various directory mappings. */
     105    private Element directory_mappings_element;
     106
    102107    private int cache_hit = 0;
    103108    private int cache_miss = 0;
     
    177182        Gatherer.println("Loaded current Gatherer configuration.");
    178183    }
     184
     185    // Determine the Directory Mappings element
     186    directory_mappings_element = (Element) MSMUtils.getNodeFromNamed(general_config.getDocumentElement(), StaticStrings.DIRECTORY_MAPPINGS_ELEMENT);
     187
    179188    // Re-establish the color settings.
    180189    updateUI();
     
    196205    Gatherer.println("EXEC_ADDRESS = " + exec_address);
    197206    }
     207
     208    /** Add a special directory mapping. */
     209    public boolean addDirectoryMapping(String name, File file) {
     210    boolean result = false;
     211    try {
     212        // Ensure the name isn't already in use.
     213        boolean found = false;
     214        NodeList mappings = directory_mappings_element.getElementsByTagName(StaticStrings.MAPPING_ELEMENT);
     215        for(int i = 0; !found && i < mappings.getLength(); i++) {
     216        Element mapping_element = (Element) mappings.item(i);
     217        if(mapping_element.getAttribute(StaticStrings.NAME_ATTRIBUTE).equalsIgnoreCase(name)) {
     218            found = true;
     219        }
     220        mapping_element = null;
     221        }
     222        // Otherwise add the mapping.
     223        if(!found) {
     224        Element mapping_element = general_config.createElement(StaticStrings.MAPPING_ELEMENT);
     225        mapping_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
     226        mapping_element.setAttribute(StaticStrings.FILE_ATTRIBUTE, file.toString());
     227        directory_mappings_element.appendChild(mapping_element);
     228        result = true;
     229        mapping_element = null;
     230        }
     231        mappings = null;
     232    }
     233    catch (Exception exception) {
     234        Gatherer.printStackTrace(exception);
     235    }
     236    return result;
     237    } /** addDirectoryMapping(String name, String file) **/
    198238
    199239    /** The default get action retrieves the named property from the desired configuration, and returns a true or false. */
     
    319359    } */
    320360
     361    /** Retrieve the special directory mappings associated with this collection.
     362     * @return A <strong>HashMap</strong> containing mappings from names to directories.
     363     */
     364    public HashMap getDirectoryMappings() {
     365    HashMap special_directories = new HashMap();
     366    try {
     367        // Ensure the name isn't already in use.
     368        boolean found = false;
     369        NodeList mappings = directory_mappings_element.getElementsByTagName(StaticStrings.MAPPING_ELEMENT);
     370        for(int i = 0; !found && i < mappings.getLength(); i++) {
     371        Element mapping_element = (Element) mappings.item(i);
     372        String name = mapping_element.getAttribute(StaticStrings.NAME_ATTRIBUTE);
     373        File file = new File(mapping_element.getAttribute(StaticStrings.FILE_ATTRIBUTE));
     374        special_directories.put(name, file);
     375        file = null;
     376        name = null;
     377        mapping_element = null;
     378        }
     379        mappings = null;
     380    }
     381    catch(Exception exception) {
     382        Gatherer.printStackTrace(exception);
     383    }
     384    return special_directories;
     385    } /** getDirectoryMappings() */
     386
    321387    /** Retrieve the current users email. These are always stored in the general settings.
    322388     * @return the email address, if it is set, as a String
     
    443509    return gsdl_path + "bin" + File.separator + "script" + File.separator;
    444510    }
     511
     512    /** Remove a previously defined special directory mapping.
     513     * @param name The name of the mapping to remove as a <strong>String</strong>.
     514     * @return The <strong>File</strong> of the mapping removed.
     515     */
     516    public File removeDirectoryMapping(String name) {
     517    File file = null;
     518    try {
     519        // Ensure the name isn't already in use.
     520        boolean found = false;
     521        NodeList mappings = directory_mappings_element.getElementsByTagName(StaticStrings.MAPPING_ELEMENT);
     522        for(int i = 0; !found && i < mappings.getLength(); i++) {
     523        Element mapping_element = (Element) mappings.item(i);
     524        if(mapping_element.getAttribute(StaticStrings.NAME_ATTRIBUTE).equalsIgnoreCase(name)) {
     525            file = new File(MSMUtils.getValue(mapping_element));
     526            directory_mappings_element.removeChild(mapping_element);
     527            found = true;
     528        }
     529        mapping_element = null;
     530        }
     531        mappings = null;
     532    }
     533    catch(Exception error) {
     534        Gatherer.printStackTrace(error);
     535    }
     536    return file;
     537    } /** removeDirectoryMapping(String name) */
    445538
    446539    /** Export the general configuration to file. */
Note: See TracChangeset for help on using the changeset viewer.