Ignore:
Timestamp:
2010-10-02T22:11:29+13:00 (14 years ago)
Author:
ak19
Message:

Again for ticket 152 (moveable collectdir). If the default GS collectdir is the one active in GLI (but all collections are closed) when exiting GLI, this default GS collectdir is not stored in config.xml (in the User Data location). Instead of the last opened collection or last open collectdir, an empty value is written out in the case of the default GS collectdir. This will allow other GS installations to open in their own collectdir. The benefits do not extend to if a collection in another GS' default collectdir was left open. In that case, the collection path is written out to the config.xml file, and the collectdir that a different GLI loads will be the old GLI's collect dir.

File:
1 edited

Legend:

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

    r22911 r23015  
    316316        popupFedoraInfo();
    317317        }
     318       
     319        open_collection_file_path = open_collection;
     320        if (open_collection_file_path == null) {
     321            open_collection_file_path = Configuration.getString(
     322                "general.open_collection"+Configuration.gliPropertyNameSuffix(), true);
     323        }
     324        if (no_load) {
     325        open_collection_file_path = null;
     326        //      collectDirectoryHasChanged(); // make sure gsdlsite.cfg's collecthome defaults to GS' collect
     327        }
     328       
     329        // If opening a collection outside the standard GS collect folder, need
     330        // to open the non-standard collect folder that the collection resides in
     331        if (open_collection_file_path != null &&
     332        !open_collection_file_path.startsWith(getDefaultGSCollectDirectoryPath(true))) {
     333            File collectFolder = null;
     334           
     335            if(!open_collection_file_path.equals("")) {
     336           
     337                if(!open_collection_file_path.endsWith("gli.col")) { // then it's a collect folder
     338                    collectFolder = new File(open_collection_file_path);
     339                } else {
     340                    // the filepath is a gli.col file. To get the collect folder: the 1st level
     341                    // up is collection folder, 2 two levels up is the containing collect folder
     342                    collectFolder = new File(open_collection_file_path).getParentFile().getParentFile();
     343                }   
     344           
     345                // Need to deal with colgroups as well: while there's an etc/collect.cfg in the current
     346                // collectFolder, move one level up
     347                String cfg_file = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
     348                if(new File(collectFolder.getAbsolutePath()+File.separator+cfg_file).exists()) { // colgroup
     349                    collectFolder = collectFolder.getParentFile();         
     350                }
     351            }       
     352           
     353            if(!isGsdlRemote && (collectFolder == null || !collectFolder.exists())) {
     354                // if GLI config file specified no collectDir  (open_collection_file_path is "")
     355                // OR if dealing with a local server but the collectdir no longer exists,
     356                // use the default greenstone collect directory, and write that to affected files
     357               
     358                String defaultColDir = getDefaultGSCollectDirectoryPath(false); // no file separator at end
     359                open_collection_file_path = defaultColDir;
     360               
     361                setCollectDirectoryPath(defaultColDir); // will ensure the required file separator at end
     362               
     363                Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
     364                        true, "");
     365               
     366                if(Gatherer.GS3) {  // GS2's gsdlsite.cfg was taken care of when LocalLibraryServer was started up
     367                                    // (LocalLibraryServer would also already have set glisite.cfg to the correct collecthome)
     368                    String gsdlsitecfg = Configuration.gsdl3_path + File.separator
     369                        + "WEB-INF" + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
     370                    Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", defaultColDir); // no file separator
     371                            // if gsdlsite.cfg does not exist (if using server.exe for instance), the above method will just return
     372                }
     373            } else { // remote GS, or collect dir exists (all config files will already be set since last GLI session)
     374                if(collectFolder == null) {
     375                    setCollectDirectoryPath(getDefaultGSCollectDirectoryPath(false)); // no file separator at end
     376                } else {
     377                    setCollectDirectoryPath(collectFolder.getAbsolutePath()); // now set this as the current collect folder
     378                }
     379                   
     380            }
     381        }
    318382
    319383        // Finally, we're ready to find out the version of the remote Greenstone server
     
    353417        }
    354418        else { // local greenstone: Start up the local library server, if that's what we want
    355         if (!GS3) {
     419        if (!GS3) {     
    356420            isLocalLibrary = LocalLibraryServer.start(gsdl_path, local_library_path);
    357421        }
     
    492556        }
    493557        }
    494 
    495         open_collection_file_path = open_collection;
    496         if (open_collection_file_path == null) {
    497         open_collection_file_path = Configuration.getString(
    498             "general.open_collection"+Configuration.gliPropertyNameSuffix(), true);
    499         }
    500         if (no_load || open_collection_file_path.equals("")) {
    501         open_collection_file_path = null;
    502         //      collectDirectoryHasChanged(); // make sure gsdlsite.cfg's collecthome defaults to GS' collect
    503         }
    504 
    505         // If opening a collection outside the standard GS collect folder, need
    506         // to open the non-standard collect folder that the collection resides in
    507         if (open_collection_file_path != null &&
    508         !open_collection_file_path.startsWith(getDefaultGSCollectDirectoryPath(true))) {
    509         File collectFolder = null;
    510         if(!open_collection_file_path.endsWith("gli.col")) { // then it's a collect folder
    511             collectFolder = new File(open_collection_file_path);
    512         } else {
    513             // the filepath is a gli.col file. To get the collect folder: the 1st level
    514             // up is collection folder, 2 two levels up is the containing collect folder
    515             collectFolder = new File(open_collection_file_path).getParentFile().getParentFile();
    516         }
    517 
    518         // Need to deal with colgroups as well: while there's an etc/collect.cfg in the current
    519         // collectFolder, move one level up
    520         String cfg_file = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
    521         if(new File(collectFolder.getAbsolutePath()+File.separator+cfg_file).exists()) { // colgroup
    522             collectFolder = collectFolder.getParentFile();         
    523         }
    524        
    525         if(!isGsdlRemote && !collectFolder.exists()) {
    526             // if dealing with a local server but the collectdir no longer exists,
    527             // use the default greenstone collect directory, and write that to affected files
    528             open_collection_file_path = null; // no longer have an open collection from last time if coldir doesn't exist
    529            
    530             String defaultColDir = getDefaultGSCollectDirectoryPath(false); // no file separator at end         
    531            
    532             setCollectDirectoryPath(defaultColDir); // will ensure the required file separator at end
    533            
    534             Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
    535                     true, defaultColDir + File.separator);
    536            
    537             if(Gatherer.GS3) {  // GS2's gsdlsite.cfg was taken care of when LocalLibraryServer was started up
    538                                 // (LocalLibraryServer would also already have set glisite.cfg to the correct collecthome)
    539                 String gsdlsitecfg = Configuration.gsdl3_path + File.separator
    540                     + "WEB-INF" + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
    541                 Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", defaultColDir); // no file separator               
    542             }
    543         } else { // remote GS or collect dir exists
    544             setCollectDirectoryPath(collectFolder.getAbsolutePath()); // now set this as the current collect folder         
    545         }
    546     }
     558       
    547559    } catch (Exception exception) {
    548560        DebugStream.printStackTrace(exception);
     
    646658    }*/
    647659
    648     // If there was a collection left open last time, reopen it
    649      if (open_collection_file_path == null) {
     660    // If there was a collection left open last time, reopen it 
     661     if (open_collection_file_path == null || new File(Gatherer.open_collection_file_path).isDirectory()) {
    650662     
    651663      //the menu bar items, file and edit, are disabled from the moment of their creation. if there is no left-over collection from the last session, enable them; otherwise it is untill the collection finishes loading, will they be enabled in collectionManager.java
     
    823835    public static void collectDirectoryHasChanged(
    824836        String oldCollectPath, String newCollectPath, final Component container)
    825     {
     837    {   
     838        if(oldCollectPath.equals(newCollectPath)) {
     839            return; // nothing to be done
     840        }
     841   
    826842        // Will use a busy cursor if the process of changing the collect directory takes more
    827843        // than half a second/500ms. See http://www.catalysoft.com/articles/busyCursor.html
     
    838854            timer.schedule(timerTask, 500);
    839855       
    840             if(oldCollectPath.equals(newCollectPath)) {
    841                 return; // nothing to be done
    842             }
    843 
    844856            // first save any open collection in the old location, then close it
    845857            if(Gatherer.c_man.getCollection() != null) {
     
    848860           
    849861            // change to new collect path
    850             Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
     862            if(newCollectPath.equals(getDefaultGSCollectDirectoryPath(true))) {
     863                Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
     864                        true, "");
     865            } else {
     866                Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
    851867                        true, newCollectPath);
     868            }
    852869            Gatherer.setCollectDirectoryPath(newCollectPath);
    853870           
Note: See TracChangeset for help on using the changeset viewer.