Changeset 23015


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.

Location:
main/trunk/gli/src/org/greenstone/gatherer
Files:
4 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           
  • main/trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r22807 r23015  
    11611161    public void loadCollection(String collection_file_path)
    11621162    {
    1163     if(new File(collection_file_path).isDirectory()) { // collect folder instead of previously-opened collection
    1164         Gatherer.setMenuBarEnabled(true);
    1165         return; // nothing else to be done, no collection to open
    1166     }
    1167 
    11681163    // Display a modal progress popup to indicate that the collection is being loaded
    11691164    ModalProgressPopup load_collection_progress_popup = new ModalProgressPopup(Dictionary.get("CollectionManager.Loading_Collection"), Dictionary.get("CollectionManager.Loading_Collection_Please_Wait"));
     
    15621557
    15631558    public void openCollectionFromLastTime() {
    1564       // If there was an open collection last session, reopen it
    1565       if (Gatherer.open_collection_file_path != null) {
    1566      // Load the collection now
    1567      loadCollection(Gatherer.open_collection_file_path);
    1568       }
    1569 
     1559      // If there was an open collection last session, reopen it.
     1560      // Skip if there was none or only a collect folder instead of any previously-opened collection     
     1561      if (Gatherer.open_collection_file_path != null
     1562            && !(new File(Gatherer.open_collection_file_path).isDirectory())) {
     1563         // Load the collection now
     1564         loadCollection(Gatherer.open_collection_file_path);
     1565      }
    15701566    }
    15711567
  • main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java

    r22911 r23015  
    696696        // GS2. We're in the constructor, so we'll be running the LLS the first time
    697697        // Set the correct collectdir (from last time) before the server is started up
    698         String collectDir = Configuration.getString("general.open_collection_gs2", true);
    699         String defaultColDir = Gatherer.getDefaultGSCollectDirectoryPath(false); // no file separator at end
     698       
     699        //String collectDir = Configuration.getString("general.open_collection_gs2", true);
     700        String orig_collection_path = Configuration.getString("general.open_collection_gs2", true);
     701        String collectDir = Gatherer.getCollectDirectoryPath();
     702        String defaultColDir = Gatherer.getDefaultGSCollectDirectoryPath(true); // with file separator at end
     703       
    700704        // If opening a collection outside the standard GS collect folder, need
    701         // to open the non-standard collect folder that the collection resides in
    702         if (!collectDir.startsWith(defaultColDir + File.separator)) {
    703             File collectFolder = null;
    704             if(!collectDir.endsWith("gli.col")) { // then it's a collect folder
    705                 collectFolder = new File(collectDir);
    706             } else {
    707                 // the filepath is a gli.col file. To get the collect folder: the 1st level
    708                 // up is collection folder, 2 two levels up is the containing collect folder
    709                 collectFolder = new File(collectDir).getParentFile().getParentFile();
    710             }
    711 
    712             // Need to deal with colgroups as well: while there's an etc/collect.cfg
    713             // in the current collectFolder, move one level up
    714             if(new File(collectFolder.getAbsolutePath()+File.separator+Utility.CONFIG_FILE).exists()) {
    715                 collectFolder = collectFolder.getParentFile();             
    716             }
    717            
    718             // if the collectdir from last time no longer exists this time,
    719             // go back to Greenstone default collect dir
    720             if(collectFolder.exists()) {
    721                 collectDir = collectFolder.getAbsolutePath();               
    722                 if(collectDir.endsWith(File.separator)) {
    723                     collectDir = collectDir.substring(0, collectDir.length()-1);
    724                 }
    725             } else {
    726                 collectDir = defaultColDir;             
    727                 // necessary for local apache web server: update gsdlsite.cfg with the reverted collectdir
    728                 String gsdlsitecfg = Configuration.gsdl_path + File.separator
    729                     + "cgi-bin" + File.separator + "gsdlsite.cfg";
    730                 Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", collectDir); // no file separator at end
    731                     // if gsdlsite.cfg does not exist (if using server.exe for instance), the above method will just return
    732             }
    733            
    734             // if we're running *server.exe* and if the current collect dir at Local Lib's startup
    735             // is anything other than the default GS collect dir or if we changed back to the default
    736             // collect dir because the non-standard collectDir didn't exist, then write out
    737             // the new collectDir (minus file separator at end) to the lls site conf in use
     705        // to open the non-standard collect folder that the collection resides in.
     706        // Also, would have been forced to change the loaded collection--and hence collectDir--
     707        // to the default coldir if orig_col_path was "" or led to a collectdir that didn't exist
     708        // (in the last case, gsdlsite.cfg already corrected in Gatherer if coldir was changed).   
     709       
     710        if(orig_collection_path.equals("")) { // default GS collect dir path
     711            return;
     712        }
     713       
     714        if (Gatherer.open_collection_file_path != null // may be null if no_load was specified on GLI startup           
     715            && (!orig_collection_path.startsWith(collectDir) // if coldir would've been changed on startup OR if coldir is non-standard collect folder
     716                || !collectDir.equals(defaultColDir)))
     717        {           
     718            // if we're running *server.exe* and if the current collect dir at Local Lib's startup is
     719            // anything other than the default GS collect dir or if we changed back to the default collect
     720            // dir because the non-standard collectDir didn't exist/wasn't specified in the GLI config
     721            // file, then write out the new collectDir (minus file separator at end) to the lls site conf in use
    738722            if (isPersistentServer) { // server.exe, so we're dealing with a local GS2         
    739723                put(COLLECTHOME, collectDir);
    740724                save();
    741725                lastModified = configFile.lastModified();
    742             }
    743            
    744         } // now the correct current collect dir will get loaded when the server is started up hereafter       
     726            }           
     727        } // now the correct current collect dir will get loaded when the server is started up hereafter
    745728    }
    746729
  • main/trunk/gli/src/org/greenstone/gatherer/gui/GUIManager.java

    r22686 r23015  
    510510    else {
    511511        // if there was no open collection, then write out the collect dir path for next time
    512         Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
    513                     true, Gatherer.getCollectDirectoryPath()); // null
     512        // IF this is not the default collect directory
     513        if(Gatherer.getCollectDirectoryPath().equals(
     514                Gatherer.getDefaultGSCollectDirectoryPath(true))) {
     515            Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
     516                    true, "");
     517        } else {
     518            Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
     519                    true, Gatherer.getCollectDirectoryPath());
     520        }
    514521    }
    515522
Note: See TracChangeset for help on using the changeset viewer.