Changeset 7281


Ignore:
Timestamp:
2004-05-05T15:14:48+12:00 (20 years ago)
Author:
kjdon
Message:

tidied up some stuff to do with creating BasicCollectionConfigurations - now check for the existence of the config file before creation. and other bits

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
9 edited

Legend:

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

    r6879 r7281  
    7070    /** A reference to the Metadata Set Manager. */
    7171    public MetadataSetManager msm;
     72    /** true if an error has occurred during construction */
     73    public boolean error = false;
    7274    /** <i>true</i> if the currently loaded collection has been saved since the last significant change, <i>false</i> otherwise. */
    7375    private boolean saved = false;
     
    98100    if(document == null) {
    99101        document = Utility.parse(COLLECTION_XML_TEMPLATE, true);
     102    }
     103    if (document == null) {
     104        error = true;
     105        return;
    100106    }
    101107    // Point the Configuration class at our gatherer config arguments.
  • trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r7275 r7281  
    5050import org.greenstone.gatherer.cdm.CollectionMetaManager;
    5151import org.greenstone.gatherer.cdm.CommandTokenizer;
    52 import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
    5352import org.greenstone.gatherer.collection.Collection;
    5453import org.greenstone.gatherer.collection.SaveCollectionTask;
     
    769768        return false;
    770769    }
     770    File collection_config_file = new File(collection_directory, Utility.CONFIG_FILE);
     771    if (!collection_config_file.exists()) {
     772        Gatherer.println("CollectionManager.loadCollection: No config file");
     773        collection_directory = null;
     774        collection_config_file = null;
     775        return false;
     776    }
    771777
    772778    // Special case of a user trying to open an old greenstone collection.
     
    793799        lock_file = null;
    794800        collection_directory = null;
     801        collection_config_file = null;
    795802        return false;
    796803    }
     
    816823        // Open the collection file
    817824        collection = new Collection(collection_file);
    818         if(collection.getTitle().equals(StaticStrings.ERROR_STR)) {
     825        if (collection.error) {
    819826        collection = null;
    820827        // Remove lock file
     
    822829            lock_file.delete();
    823830        }
    824         throw(new Exception(Dictionary.get("CollectionManager.Missing_Config")));
     831        throw(new Exception(Dictionary.get("CollectionManager.Missing_Config"))); // this error message does not agree with the error
    825832        }
    826833
     
    840847        }
    841848
    842         collection.cdm = new CollectionDesignManager(new File(collection_file.getParent(), Utility.CONFIG_FILE));
     849        collection.cdm = new CollectionDesignManager(collection_config_file);
    843850        if (non_gatherer_collection) {
    844851        // We first recurse the Import folder tree, reading in any metadata.xml files, and then altering the non-namespaced element names to be valid GLI names
     
    884891    lock_file = null;
    885892    collection_directory = null;
     893    collection_config_file = null;
    886894
    887895    args2 = null;
  • trunk/gli/src/org/greenstone/gatherer/collection/DeleteCollectionPrompt.java

    r7224 r7281  
    225225        ArrayTools.sort(collections);
    226226        for(int i = 0; collections != null && i < collections.length; i++) {
    227         if(!collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
    228             File config_file = Utility.findConfigFile(collections[i]);
    229             if (config_file != null) {
     227        if(collections[i].isDirectory() && !collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
     228            File config_file = new File(collections[i], Utility.CONFIG_FILE);
     229            if (config_file.exists()) {
    230230            BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
    231             if(!config.getName().equals(StaticStrings.EMPTY_STR)) {
    232                 list_model.addElement(config);
    233             }   
     231            list_model.addElement(config);
     232            config = null;
    234233            }
    235234        }
  • trunk/gli/src/org/greenstone/gatherer/collection/ExportCollectionPrompt.java

    r7224 r7281  
    353353        ArrayTools.sort(collections);
    354354        for(int i = 0; collections != null && i < collections.length; i++) {
    355         if(!collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
    356             File config_file = Utility.findConfigFile(collections[i]);
    357             if (config_file != null) {
     355        if(collections[i].isDirectory() && !collections[i].getName().equals(StaticStrings.MODEL_COLLECTION_NAME)) {
     356            File config_file = new File(collections[i], Utility.CONFIG_FILE);
     357            if (config_file.exists()) {
    358358            BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
    359             if (!config.getName().equals(StaticStrings.EMPTY_STR)) {
    360                 all_collections.add(config);
    361             }   
     359            all_collections.add(config);               
    362360            config = null;
    363361            }
  • trunk/gli/src/org/greenstone/gatherer/file/FileNode.java

    r7275 r7281  
    269269    if(children == null) {
    270270        children = new ArrayList();
    271         // Super Special Case: if the name of this node is the Tree.World string, then we actually map the collections installed in greenstone. The file in this case will actually by the collect directory of greenstone.
     271        // Super Special Case: if the name of this node is the Tree.World string, then we actually map the collections installed in greenstone. The file in this case will actually be the collect directory of greenstone.
    272272        if(file == null && title.equals(Dictionary.get("Tree.World"))) {
    273273        ///atherer.println("Map the 'Greenstone Collections' node.");
     
    283283            File import_dir = new File(cols[i], StaticStrings.IMPORT_FOLDER);
    284284            if(import_dir.exists()) {
     285                // we don't care if there is no config file
    285286                BasicCollectionConfiguration collect_cfg = new BasicCollectionConfiguration(new File(cols[i], Utility.CONFIG_FILE));
    286287                FileNode collection_root = new FileNode(import_dir, collect_cfg.toString(), true);
  • trunk/gli/src/org/greenstone/gatherer/gui/SimpleOpenCollectionDialog.java

    r7275 r7281  
    214214        File collection_folder = collection_folders[i];
    215215        String collection_foldername = collection_folder.getName();
    216         if(!collection_folder.isFile() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) {
    217            BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(new File(collection_folder, Utility.CONFIG_FILE));
    218            if(!collection_configuration.getName().equals(StaticStrings.ERROR_STR)) {
    219               data.add(collection_configuration);
    220            }
     216        if(collection_folder.isDirectory() && !collection_foldername.equals(StaticStrings.MODEL_COLLECTION_NAME)) {
     217            File config_file = new File(collection_folder, Utility.CONFIG_FILE);
     218            if (config_file.exists()) {
     219            BasicCollectionConfiguration collection_configuration = new BasicCollectionConfiguration(config_file);
     220            data.add(collection_configuration);
     221            }
     222            config_file = null;
    221223        }
    222224        collection_foldername = null;
  • trunk/gli/src/org/greenstone/gatherer/mem/MEMNode.java

    r7275 r7281  
    160160            if(is_descendant) {
    161161                // Create a basic config class
    162                 BasicCollectionConfiguration config = new BasicCollectionConfiguration(new File(source_path, Utility.CONFIG_FILE));
    163                 text = config.toString();
    164                 config = null;
     162                File config_file = new File(source_path, Utility.CONFIG_FILE);
     163                if (config_file.exists()) {
     164                BasicCollectionConfiguration config = new BasicCollectionConfiguration(config_file);
     165                text = config.toString();
     166                config = null;
     167                } else {
     168                text = source_path.getAbsolutePath();
     169                }
     170                config_file = null;
    165171            }
    166172            else {
  • trunk/gli/src/org/greenstone/gatherer/util/StaticStrings.java

    r7251 r7281  
    9898    static final public String ENUM_STR                                   = "enum";
    9999    static final public String EQUALS_CHARACTER                           = "=";
    100     static final public String ERROR_STR                                  = "Error";
    101100    static final public String ESCAPE_PATTERN                             = "\\\\";
    102101    static final public String ESCAPE_STR                                 = "\\";
  • trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r7275 r7281  
    264264     * @return The collect.cfg File or null if not found.
    265265     */
    266     static final public File findConfigFile(File start) {
     266    /*    static final public File findConfigFile(File start) {
    267267    if(start == null) {
    268268        return null;
     
    280280    // Otherwise search this directories parent if its not null.
    281281    return findConfigFile(start.getParentFile());
    282     }
     282    }*/
    283283
    284284    /** Convert a long, detailing the length of a file in bytes, into a nice human readable string using b, kb, Mb and Gb. */
Note: See TracChangeset for help on using the changeset viewer.