Changeset 6086


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.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
5 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. */
  • trunk/gli/src/org/greenstone/gatherer/collection/Collection.java

    r6051 r6086  
    6262 */
    6363public class Collection {
    64     /** A reference to the BuildOptions. */
    65     public BuildOptions build_options;
    66     /** A reference to the Collection Design Manager. */
    67     public CollectionDesignManager cdm;
    68     /** A reference to the Greenstone Directory Metadata Manager. */
    69     public GDMManager gdm;
    70     /** A reference to the Metadata Set Manager. */
    71     public MetadataSetManager msm;
    72     /** <i>true</i> if the currently loaded collection has been saved since the last significant change, <i>false</i> otherwise. */
    73     private boolean saved = false;
    74     /** The document around which this collection class is based. */
    75     private Document document;
    76     /** The file the collection is in (the file may not actually exist, such in the case of a legacy collection)! */
    77     private File file;
    78    /** The name of the argument element. */
    79    static final private String ARGUMENT = "Argument";
    80    static final private String BASE_COLLECTION = "base_collection";
    81     /** The name of the build element. */
    82     static final private String BUILD = "Build";
    83     /** The name of the build config element. */
    84     static final private String BUILD_CONFIG = "BuildConfig";
    85     /** The name of the collection xml template. */
    86     static final private String COLLECTION_XML_TEMPLATE = "xml/template.col";
    87     /** The name of the directory mappings element. */
    88     static final private String DIRECTORY_MAPPINGS = "DirectoryMappings";
    89     /** The name of the file attribute. */
    90     static final private String FILE = "file";
    91     /** The name of the import element. */
    92     static final private String IMPORT = "Import";
    93     /** The name of the imported attribute. */
    94     static final private String IMPORTED = "imported";
    95     /** The name of the mapping element. */
    96     static final private String MAPPING = "Mapping";
    97     /** The name of the name attribute. */
    98     static final private String NAME = "name";
    99     /** The name of the true value. */
    100     static final private String TRUE = "true";
    101     /** Constructor. */
    102     public Collection(File collection_xml) {
    103         this.file = collection_xml;
    104         // Try to load this collections details.
    105         document = Utility.parse(collection_xml, false);
    106         // If that fails load the default settings for a collection.
    107         if(document == null) {
    108             document = Utility.parse(COLLECTION_XML_TEMPLATE, true);
    109         }
    110         // Point the Configuration class at our gatherer config arguments.
    111         Gatherer.config.setCollectionConfiguration(document);
    112         // Finally create all of the child managers that are directly dependant on a collection
    113         build_options = new BuildOptions(getBuildValues(), getImportValues());
    114     }
    115 
    116     /** Add a special directory mapping. */
    117     public boolean addDirectoryMapping(String name, File file) {
    118     boolean result = false;
    119     try {
    120         Element document_element = document.getDocumentElement();
    121         Element directory_mappings_element = (Element) MSMUtils.getNodeFromNamed(document_element, DIRECTORY_MAPPINGS);
    122                 // Ensure the name isn't already in use.
    123         boolean found = false;
    124         NodeList mappings = directory_mappings_element.getElementsByTagName(MAPPING);
    125         for(int i = 0; !found && i < mappings.getLength(); i++) {
    126         Element mapping_element = (Element) mappings.item(i);
    127         if(mapping_element.getAttribute(NAME).equalsIgnoreCase(name)) {
    128             found = true;
    129         }
    130         mapping_element = null;
    131         }
    132         // Otherwise add the mapping.
    133         if(!found) {
    134         Element mapping_element = document.createElement(MAPPING);
    135         mapping_element.setAttribute(NAME, name);
    136         mapping_element.setAttribute(FILE, file.toString());
    137         directory_mappings_element.appendChild(mapping_element);
    138         result = true;
    139         mapping_element = null;
    140         }
    141         mappings = null;
    142         directory_mappings_element = null;
    143         document_element = null;
    144         saved = false;
    145     }
    146     catch (Exception error) {
    147         Gatherer.printStackTrace(error);
    148     }
    149     return result;
    150     }
    151 
    152     /** Destructor.
    153      * @see org.greenstone.gatherer.collection.CollectionModel */
    154     public void destroy() {
     64    /** A reference to the BuildOptions. */
     65    public BuildOptions build_options;
     66    /** A reference to the Collection Design Manager. */
     67    public CollectionDesignManager cdm;
     68    /** A reference to the Greenstone Directory Metadata Manager. */
     69    public GDMManager gdm;
     70    /** A reference to the Metadata Set Manager. */
     71    public MetadataSetManager msm;
     72    /** <i>true</i> if the currently loaded collection has been saved since the last significant change, <i>false</i> otherwise. */
     73    private boolean saved = false;
     74    /** The document around which this collection class is based. */
     75    private Document document;
     76    /** The file the collection is in (the file may not actually exist, such in the case of a legacy collection)! */
     77    private File file;
     78    /** The name of the argument element. */
     79    static final private String ARGUMENT = "Argument";
     80    static final private String BASE_COLLECTION = "base_collection";
     81    /** The name of the build element. */
     82    static final private String BUILD = "Build";
     83    /** The name of the build config element. */
     84    static final private String BUILD_CONFIG = "BuildConfig";
     85    /** The name of the collection xml template. */
     86    static final private String COLLECTION_XML_TEMPLATE = "xml/template.col";
     87    /** The name of the import element. */
     88    static final private String IMPORT = "Import";
     89    /** The name of the imported attribute. */
     90    static final private String IMPORTED = "imported";
     91
     92    /** Constructor. */
     93    public Collection(File collection_xml) {
     94    this.file = collection_xml;
     95    // Try to load this collections details.
     96    document = Utility.parse(collection_xml, false);
     97    // If that fails load the default settings for a collection.
     98    if(document == null) {
     99        document = Utility.parse(COLLECTION_XML_TEMPLATE, true);
     100    }
     101    // Point the Configuration class at our gatherer config arguments.
     102    Gatherer.config.setCollectionConfiguration(document);
     103    // Finally create all of the child managers that are directly dependant on a collection
     104    build_options = new BuildOptions(getBuildValues(), getImportValues());
     105    }
     106   
     107    /** Destructor.
     108     * @see org.greenstone.gatherer.collection.CollectionModel */
     109    public void destroy() {
    155110    cdm.destroy();
    156111    gdm.destroy();
     
    161116    gdm = null;
    162117    msm = null;
    163     }
    164 
    165    /** Determine the path to the base collection.
    166     * @return the path as a String
    167     */
    168    public String getBaseCollection() {
    169       return getString(BASE_COLLECTION);
    170    }
    171 
    172     /** Determine the number of documents and folders in this collection. */
    173     public int getCount() {
     118    }
     119   
     120    /** Determine the path to the base collection.
     121     * @return the path as a String
     122     */
     123    public String getBaseCollection() {
     124    return getString(BASE_COLLECTION);
     125    }
     126   
     127    /** Determine the number of documents and folders in this collection. */
     128    public int getCount() {
    174129    return getCount((TreeNode)Gatherer.c_man.getRecordSet().getRoot(), true, true);
    175     }
    176 
    177     /** Calculates the number of documents in this collection. */
    178     public int getDocumentCount() {
     130    }
     131   
     132    /** Calculates the number of documents in this collection. */
     133    public int getDocumentCount() {
    179134    return getCount((TreeNode)Gatherer.c_man.getRecordSet().getRoot(), false, true);
    180     }
    181 
    182     /** Retrieve the description of this collection.
    183      * @return a String
    184      */
    185     public String getDescription() {
    186         if(cdm == null) {
    187             return StaticStrings.EMPTY_STR;
    188         }
    189         CollectionMeta collection_extra_collectionmeta = cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR);
    190         return collection_extra_collectionmeta.getValue(CollectionMeta.TEXT);
    191     }
    192 
    193     /** Retrieve the special directory mappings associated with this collection.
    194      * @return A <strong>HashMap</strong> containing mappings from names to directories.
    195      */
    196     public HashMap getDirectoryMappings() {
    197         HashMap special_directories = new HashMap();
    198         try {
    199             Element document_element = document.getDocumentElement();
    200             Element directory_mappings_element = (Element) MSMUtils.getNodeFromNamed(document_element, DIRECTORY_MAPPINGS);
    201             // Ensure the name isn't already in use.
    202             boolean found = false;
    203             NodeList mappings = directory_mappings_element.getElementsByTagName(MAPPING);
    204             for(int i = 0; !found && i < mappings.getLength(); i++) {
    205                 Element mapping_element = (Element) mappings.item(i);
    206                 String name = mapping_element.getAttribute(NAME);
    207                 File file = new File(mapping_element.getAttribute(FILE));
    208                 special_directories.put(name, file);
    209                 file = null;
    210                 name = null;
    211                 mapping_element = null;
    212             }
    213             mappings = null;
    214             directory_mappings_element = null;
    215             document_element = null;
    216         }
    217         catch(Exception error) {
    218             Gatherer.printStackTrace(error);
    219         }
    220         return special_directories;
    221     }
    222     /** Retrieve the authors email for this collection.
    223      * @return The email as a <strong>String</strong>.
    224      */
    225     public String getEmail() {
    226         if(cdm == null) {
    227             return StaticStrings.EMPTY_STR;
    228         }
    229         CollectionMeta creator_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getCreator());
    230         return creator_collectionmeta.getValue(CollectionMeta.TEXT);
    231     }
    232 
    233     /** Retrieve the short name for this collection.
    234      * @return The name as a <strong>String</strong>.
    235      */
    236     public String getName() {
    237         return file.getParentFile().getName();
    238     }
    239 
    240     /** Determine if this collection has been saved since the last major change.
    241      * @return <i>true</i> if it has been saved recently, <i>false</i> otherwise.
    242      */
    243     public boolean getSaved() {
    244         return saved;
    245     }
    246 
    247     /** Retrieve the title of this collection.
    248      * @return The title as a <strong>String</strong>.
    249      */
    250     public String getTitle() {
    251         if(cdm == null) {
    252             return StaticStrings.EMPTY_STR;
    253         }
    254         CollectionMeta collection_name_collectionmeta = cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR);
    255         return collection_name_collectionmeta.getValue(CollectionMeta.TEXT);
    256     }
    257     /** Remove a previously defined special directory mapping.
    258      * @param name The name of the mapping to remove as a <strong>String</strong>.
    259      * @return The <strong>File</strong> of the mapping removed.
    260      */
    261     public File removeDirectoryMapping(String name) {
    262         File file = null;
    263         try {
    264             Element document_element = document.getDocumentElement();
    265             Element directory_mappings_element = (Element) MSMUtils.getNodeFromNamed(document_element, DIRECTORY_MAPPINGS);
    266             // Ensure the name isn't already in use.
    267             boolean found = false;
    268             NodeList mappings = directory_mappings_element.getElementsByTagName(MAPPING);
    269             for(int i = 0; !found && i < mappings.getLength(); i++) {
    270                 Element mapping_element = (Element) mappings.item(i);
    271                 if(mapping_element.getAttribute(NAME).equalsIgnoreCase(name)) {
    272                     file = new File(MSMUtils.getValue(mapping_element));
    273                     directory_mappings_element.removeChild(mapping_element);
    274                     found = true;
    275                 }
    276                 mapping_element = null;
    277             }
    278             mappings = null;
    279             directory_mappings_element = null;
    280             document_element = null;
    281             saved = false;
    282         }
    283         catch(Exception error) {
    284             Gatherer.printStackTrace(error);
    285         }
    286         return file;
    287     }
    288     /** Save this xml document to the given file. */
    289     public void save() {
     135    }
     136   
     137    /** Retrieve the description of this collection.
     138     * @return a String
     139     */
     140    public String getDescription() {
     141    if(cdm == null) {
     142        return StaticStrings.EMPTY_STR;
     143    }
     144    CollectionMeta collection_extra_collectionmeta = cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR);
     145    return collection_extra_collectionmeta.getValue(CollectionMeta.TEXT);
     146    }
     147   
     148    /** Retrieve the authors email for this collection.
     149     * @return The email as a <strong>String</strong>.
     150     */
     151    public String getEmail() {
     152    if(cdm == null) {
     153        return StaticStrings.EMPTY_STR;
     154    }
     155    CollectionMeta creator_collectionmeta = new CollectionMeta(CollectionDesignManager.collect_config.getCreator());
     156    return creator_collectionmeta.getValue(CollectionMeta.TEXT);
     157    }
     158   
     159    /** Retrieve the short name for this collection.
     160     * @return The name as a <strong>String</strong>.
     161     */
     162    public String getName() {
     163    return file.getParentFile().getName();
     164    }
     165   
     166    /** Determine if this collection has been saved since the last major change.
     167     * @return <i>true</i> if it has been saved recently, <i>false</i> otherwise.
     168     */
     169    public boolean getSaved() {
     170    return saved;
     171    }
     172   
     173    /** Retrieve the title of this collection.
     174     * @return The title as a <strong>String</strong>.
     175     */
     176    public String getTitle() {
     177    if(cdm == null) {
     178        return StaticStrings.EMPTY_STR;
     179    }
     180    CollectionMeta collection_name_collectionmeta = cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR);
     181    return collection_name_collectionmeta.getValue(CollectionMeta.TEXT);
     182    }
     183
     184    /** Save this xml document to the given file. */
     185    public void save() {
    290186    Utility.export(document, file);
    291     }
    292 
    293    public void setBaseCollection(String base_collection) {
    294       set(BASE_COLLECTION, base_collection);
    295    }
    296 
    297     /** Set the value of imported to the given value.
    298     * @param value The new value for imported, <i>true</i> if the collection has been imported successfully, <i>false</i> otherwise.
    299     */
    300     public void setImported(boolean value) {
     187    }
     188
     189    public void setBaseCollection(String base_collection) {
     190    set(BASE_COLLECTION, base_collection);
     191    }
     192   
     193    /** Set the value of imported to the given value.
     194    * @param value The new value for imported, <i>true</i> if the collection has been imported successfully, <i>false</i> otherwise.
     195    */
     196    public void setImported(boolean value) {
    301197    set(IMPORTED, value);
    302198    saved = false;
    303     }
    304     /** Set the value of saved to the given value.
    305      * @param value The new value for saved, <i>true</i> if the collection has been saved recently, <i>false</i> otherwise.
    306      */
    307     public void setSaved(boolean value) {
     199    }
     200
     201    /** Set the value of saved to the given value.
     202     * @param value The new value for saved, <i>true</i> if the collection has been saved recently, <i>false</i> otherwise.
     203     */
     204    public void setSaved(boolean value) {
    308205    saved = value;
    309     }
    310     /** Set the value of title to the given value.
    311      * @param title The new <strong>String</strong> title.
    312      */
    313     public void setTitle(String title) {
    314         if(cdm != null) {
    315             CollectionMeta collection_name_collectionmeta = cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR);
    316             collection_name_collectionmeta.setValue(title);
    317         }
    318     }
    319     /** Method called to return a textual representation of a class, which in this case is the collections title.
    320      * @return A <strong>String</strong> containing the collections title.
    321      */
    322     public String toString() {
    323         return getTitle();
    324     }
    325     /** Get the value of a collection argument. */
    326     private boolean get(String name) {
     206    }
     207
     208    /** Set the value of title to the given value.
     209     * @param title The new <strong>String</strong> title.
     210     */
     211    public void setTitle(String title) {
     212    if(cdm != null) {
     213        CollectionMeta collection_name_collectionmeta = cdm.collectionmeta_manager.getMetadatum(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR);
     214        collection_name_collectionmeta.setValue(title);
     215    }
     216    }
     217
     218    /** Method called to return a textual representation of a class, which in this case is the collections title.
     219     * @return A <strong>String</strong> containing the collections title.
     220     */
     221    public String toString() {
     222    return getTitle();
     223    }
     224   
     225    /** Get the value of a collection argument. */
     226    private boolean get(String name) {
    327227    boolean result = false;
    328228    try {
    329         Element document_element = document.getDocumentElement();
    330         NodeList arguments = document_element.getElementsByTagName(ARGUMENT);
    331         boolean found = false;
    332         for(int i = 0; !found && i < arguments.getLength(); i++) {
     229        Element document_element = document.getDocumentElement();
     230        NodeList arguments = document_element.getElementsByTagName(ARGUMENT);
     231        boolean found = false;
     232        for(int i = 0; !found && i < arguments.getLength(); i++) {
    333233        Element argument_element = (Element) arguments.item(i);
    334234        if(argument_element.getParentNode() == document_element) {
    335             if(argument_element.getAttribute(NAME).equalsIgnoreCase(name)) {
     235            if(argument_element.getAttribute(StaticStrings.NAME_ATTRIBUTE).equalsIgnoreCase(name)) {
    336236            String value = MSMUtils.getValue(argument_element);
    337             if(value.equalsIgnoreCase(TRUE)) {
    338                 result = true;
     237            if(value.equalsIgnoreCase(StaticStrings.TRUE_STR)) {
     238                result = true;
    339239            }
    340240            found = true;
    341241            value = null;
    342             }
     242            }
    343243        }
    344244        argument_element = null;
    345         }
    346         arguments = null;
    347         document_element = null;
    348     }
    349     catch (Exception error) {
    350         Gatherer.printStackTrace(error);
     245        }
     246        arguments = null;
     247        document_element = null;
     248    }
     249    catch (Exception error) {
     250        Gatherer.printStackTrace(error);
    351251    }
    352252    return result;
    353     }
    354 
    355     /** Get the value of a collection argument. */
    356     private String getString(String name) {
     253    }
     254   
     255    /** Get the value of a collection argument. */
     256    private String getString(String name) {
    357257    String result = "";
    358258    try {
    359         Element document_element = document.getDocumentElement();
    360         NodeList arguments = document_element.getElementsByTagName(ARGUMENT);
    361         boolean found = false;
    362         for(int i = 0; !found && i < arguments.getLength(); i++) {
     259        Element document_element = document.getDocumentElement();
     260        NodeList arguments = document_element.getElementsByTagName(ARGUMENT);
     261        boolean found = false;
     262        for(int i = 0; !found && i < arguments.getLength(); i++) {
    363263        Element argument_element = (Element) arguments.item(i);
    364264        if(argument_element.getParentNode() == document_element) {
    365             if(argument_element.getAttribute(NAME).equalsIgnoreCase(name)) {
     265            if(argument_element.getAttribute(StaticStrings.NAME_ATTRIBUTE).equalsIgnoreCase(name)) {
    366266            result = MSMUtils.getValue(argument_element);
    367267            found = true;
    368             }
     268            }
    369269        }
    370270        argument_element = null;
    371         }
    372         arguments = null;
    373         document_element = null;
    374     }
    375     catch (Exception error) {
    376         Gatherer.printStackTrace(error);
     271        }
     272        arguments = null;
     273        document_element = null;
     274    }
     275    catch (Exception error) {
     276        Gatherer.printStackTrace(error);
    377277    }
    378278    return result;
    379     }
    380 
    381     /** Method to retrieve the current build options associated with this Collection. */
    382     private Element getBuildValues() {
     279    }
     280   
     281    /** Method to retrieve the current build options associated with this Collection. */
     282    private Element getBuildValues() {
    383283    Element build_values_element = null;
    384284    try {
    385         Element document_element = document.getDocumentElement();
    386         Element build_config_element = (Element) MSMUtils.getNodeFromNamed(document_element, BUILD_CONFIG);
    387         build_values_element = (Element) MSMUtils.getNodeFromNamed(build_config_element, BUILD);
    388         build_config_element = null;
    389         document_element = null;
    390     }
    391     catch (Exception error) {
    392         Gatherer.printStackTrace(error);
     285        Element document_element = document.getDocumentElement();
     286        Element build_config_element = (Element) MSMUtils.getNodeFromNamed(document_element, BUILD_CONFIG);
     287        build_values_element = (Element) MSMUtils.getNodeFromNamed(build_config_element, BUILD);
     288        build_config_element = null;
     289        document_element = null;
     290    }
     291    catch (Exception error) {
     292        Gatherer.printStackTrace(error);
    393293    }
    394294    return build_values_element;
    395     }
    396 
    397     /** Count either documents or folders, depending on the state of the given boolean. */
    398     private int getCount(TreeNode node, boolean count_folders, boolean count_files) {
     295    }
     296   
     297    /** Count either documents or folders, depending on the state of the given boolean. */
     298    private int getCount(TreeNode node, boolean count_folders, boolean count_files) {
    399299    int count = 0;
    400300    File file = ((FileNode)node).getFile();
    401301    if(file.isFile() && count_files) {
    402         count++;
     302        count++;
    403303    }
    404304    else if(file.isDirectory() && count_folders) {
    405         count++;
     305        count++;
    406306    }
    407307    for(int i = 0; i < node.getChildCount(); i++) {
    408         count = count + getCount(node.getChildAt(i), count_folders, count_files);
     308        count = count + getCount(node.getChildAt(i), count_folders, count_files);
    409309    }
    410310    return count;
    411     }
    412 
    413     /** Method to retrieve the current import options associated with this Collection. */
    414     public Element getImportValues() {
     311    }
     312   
     313    /** Method to retrieve the current import options associated with this Collection. */
     314    public Element getImportValues() {
    415315    Element import_values_element = null;
    416316    try {
    417         Element document_element = document.getDocumentElement();
    418         Element build_config_element = (Element) MSMUtils.getNodeFromNamed(document_element, BUILD_CONFIG);
    419         import_values_element = (Element) MSMUtils.getNodeFromNamed(build_config_element, IMPORT);
    420         build_config_element = null;
    421         document_element = null;
    422     }
    423     catch (Exception error) {
    424         Gatherer.printStackTrace(error);
     317        Element document_element = document.getDocumentElement();
     318        Element build_config_element = (Element) MSMUtils.getNodeFromNamed(document_element, BUILD_CONFIG);
     319        import_values_element = (Element) MSMUtils.getNodeFromNamed(build_config_element, IMPORT);
     320        build_config_element = null;
     321        document_element = null;
     322    }
     323    catch (Exception error) {
     324        Gatherer.printStackTrace(error);
    425325    }
    426326    return import_values_element;
    427     }
    428 
    429    /** Set the value of a collection argument. */
    430    private void set(String name, boolean value) {
    431       set(name, (value ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR));
    432    }
    433 
    434    private void set(String name, String value) {
    435       try {
    436      Element document_element = document.getDocumentElement();
    437      NodeList arguments = document_element.getElementsByTagName(ARGUMENT);
    438      boolean found = false;
    439      for(int i = 0; !found && i < arguments.getLength(); i++) {
     327    }
     328   
     329    /** Set the value of a collection argument. */
     330    private void set(String name, boolean value) {
     331    set(name, (value ? StaticStrings.TRUE_STR : StaticStrings.FALSE_STR));
     332    }
     333   
     334    private void set(String name, String value) {
     335    try {
     336        Element document_element = document.getDocumentElement();
     337        NodeList arguments = document_element.getElementsByTagName(ARGUMENT);
     338        boolean found = false;
     339        for(int i = 0; !found && i < arguments.getLength(); i++) {
    440340        Element argument_element = (Element) arguments.item(i);
    441341        if(argument_element.getParentNode() == document_element) {
    442            if(argument_element.getAttribute(NAME).equalsIgnoreCase(name)) {
    443           // Strip any current value nodes.
    444           while(argument_element.hasChildNodes()) {
    445              argument_element.removeChild(argument_element.getFirstChild());
    446           }
    447           // Append new value
    448           argument_element.appendChild(document.createTextNode(value));
    449           found = true;
    450            }
     342            if(argument_element.getAttribute(StaticStrings.NAME_ATTRIBUTE).equalsIgnoreCase(name)) {
     343            // Strip any current value nodes.
     344            while(argument_element.hasChildNodes()) {
     345                argument_element.removeChild(argument_element.getFirstChild());
     346            }
     347            // Append new value
     348            argument_element.appendChild(document.createTextNode(value));
     349            found = true;
     350            }
    451351        }
    452352        argument_element = null;
    453      }
    454      // Append it
    455      if(!found) {
     353        }
     354        // Append it
     355        if(!found) {
    456356        Element argument_element = document.createElement(ARGUMENT);
    457         argument_element.setAttribute(NAME, name);
     357        argument_element.setAttribute(StaticStrings.NAME_ATTRIBUTE, name);
    458358        argument_element.appendChild(document.createTextNode(value));
    459359        document_element.appendChild(argument_element);
    460360        argument_element = null;
    461      }
    462      arguments = null;
    463      document_element = null;
    464       }
    465       catch (Exception error) {
    466      Gatherer.printStackTrace(error);
    467       }
    468    }
     361        }
     362        arguments = null;
     363        document_element = null;
     364    }
     365    catch (Exception error) {
     366        Gatherer.printStackTrace(error);
     367    }
     368    }
    469369}
  • trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r6061 r6086  
    139139     */
    140140    public void addDirectoryMapping(String name, File file) {
    141     if(ready()) {
    142         // Update the information stored in the collection
    143         collection.addDirectoryMapping(name, file);
    144         // Now update the tree
    145         Gatherer.g_man.collection_pane.refreshWorkspaceTree(WorkspaceTree.MAPPED_DIRECTORIES_CHANGED);
    146     }
     141    // Update the information stored in the Gatherer config
     142    Gatherer.config.addDirectoryMapping(name, file);
     143    // Now update the tree
     144    Gatherer.g_man.collection_pane.refreshWorkspaceTree(WorkspaceTree.MAPPED_DIRECTORIES_CHANGED);
    147145    }
    148146    /** This method calls the builcol.pl scripts via a GShell so as to not lock up the processor.
     
    667665    static public FileNode[] getCollectionSpecificMappings()
    668666    {
    669     if (!ready()) {
    670         return null;
    671     }
    672 
    673667    // Return any predefined special directories
    674     HashMap mappings = collection.getDirectoryMappings();
     668    HashMap mappings = Gatherer.config.getDirectoryMappings();
    675669    FileNode[] mapping_nodes = new FileNode[mappings.size()];
    676670    Iterator mappings_iterator = mappings.keySet().iterator();
     
    680674        mapping_nodes[i] = new FileNode(mapping_file, mapping_name);
    681675    }
    682 
    683676    return mapping_nodes;
    684677    }
     
    11361129     */
    11371130    public File removeDirectoryMapping(FileNode target) {
    1138     File file = null;
    1139     if(ready()) {
    1140         // Remove from collection, remembering file
    1141         file = collection.removeDirectoryMapping(target.toString());
    1142         // Update tree.
    1143         Gatherer.g_man.collection_pane.refreshWorkspaceTree(WorkspaceTree.MAPPED_DIRECTORIES_CHANGED);
    1144     }
     1131    // Remove from config, remembering file
     1132    File file = Gatherer.config.removeDirectoryMapping(target.toString());
     1133    // Update tree.
     1134    Gatherer.g_man.collection_pane.refreshWorkspaceTree(WorkspaceTree.MAPPED_DIRECTORIES_CHANGED);
    11451135    return file;
    11461136    }
  • trunk/gli/src/org/greenstone/gatherer/file/WorkspaceTreeModel.java

    r5898 r6086  
    6666    static private void loadCollectionSpecificMappings()
    6767    {
     68    ///ystem.err.print("Load Collection Specific Mappings... ");
    6869    // Add the current collection specific mappings
    6970    collection_specific_mappings = CollectionManager.getCollectionSpecificMappings();
     71    ///ystem.err.print("Retrieved Mappings... ");
    7072    if (collection_specific_mappings != null) {
    7173        for (int i = 0; i < collection_specific_mappings.length; i++) {
    72         SynchronizedTreeModelTools.insertNodeInto(workspace_tree_model,
    73                               workspace_tree_root,
    74                               collection_specific_mappings[i]);
     74        ///ystem.err.print("Setting " + i + " Mapping... ");
     75        SynchronizedTreeModelTools.insertNodeInto(workspace_tree_model, workspace_tree_root, collection_specific_mappings[i], false);
    7576        }
    7677    }
     78    ///ystem.err.println("Done.");
    7779    }
    7880
  • trunk/gli/src/org/greenstone/gatherer/gui/tree/WorkspaceTree.java

    r5869 r6086  
    2323
    2424    public void refresh(int refresh_reason) {
    25     System.err.print("WorkspaceTree::refresh()... ");
     25    Gatherer.println("WorkspaceTree::refresh()... ");
    2626
    2727    // The collections in the library have changed - refresh the collect directory
    2828    if (refresh_reason == DragTree.LIBRARY_CONTENTS_CHANGED) {
    29         System.err.println("Reason: library contents changed.");
     29        Gatherer.println("...Reason: library contents changed.");
    3030        String collect_directory_str = Gatherer.config.gsdl_path + Utility.COL_DIR;
    3131        refreshEveryNodeShowingFolder(collect_directory_str);
     
    3535    // A collection has been opened/closed - reload the whole shebang
    3636    if (refresh_reason == DragTree.LOADED_COLLECTION_CHANGED) {
    37         System.err.println("Reason: loaded collection changed.");
     37        Gatherer.println("...Reason: loaded collection changed.");
    3838        setModel(WorkspaceTreeModel.getWorkspaceTreeModel());
    3939    }
     
    4141    // The collection's contents have changed - refresh collection's import folder
    4242    if (refresh_reason == DragTree.COLLECTION_CONTENTS_CHANGED) {
    43         System.err.println("Reason: collection contents changed.");
     43        Gatherer.println("...Reason: collection contents changed.");
    4444        String import_directory_str = Gatherer.c_man.getCollectionImport();
    4545        refreshEveryNodeShowingFolder(import_directory_str);
     
    4848    // The method for displaying the tree has changed - redraw the tree
    4949    if (refresh_reason == DragTree.TREE_DISPLAY_CHANGED) {
    50         System.err.println("Reason: tree display changed.");
     50        Gatherer.println("...Reason: tree display changed.");
    5151        updateUI();
    5252    }
     
    5454    // The collection specific mapped directories have changed - refresh only them
    5555    if (refresh_reason == WorkspaceTree.MAPPED_DIRECTORIES_CHANGED) {
    56         System.err.println("Reason: mapped directories changed.");
     56        Gatherer.println("...Reason: mapped directories changed.");
    5757        WorkspaceTreeModel.refreshWebCacheMappings();
    5858        WorkspaceTreeModel.refreshCollectionSpecificMappings();
Note: See TracChangeset for help on using the changeset viewer.