Changeset 22806 for main/trunk/gli


Ignore:
Timestamp:
2010-08-30T16:29:40+12:00 (14 years ago)
Author:
ak19
Message:

Further changes to ticket 152 (movable collectdir). Need to deal with GLI being started and reading in a non-standard collectdir from config files (stored from a previous GLI session) that now no longer exists. In this case need to revert back to the default Greenstone collectdir. Tested on Windows with the included Apache webserver and server.exe

Location:
main/trunk/gli/src/org/greenstone/gatherer
Files:
2 edited

Legend:

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

    r22771 r22806  
    505505        // If opening a collection outside the standard GS collect folder, need
    506506        // 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(getCollectDirectoryPath())) {
     507        if (open_collection_file_path != null &&
     508        !open_collection_file_path.startsWith(getDefaultGSCollectDirectoryPath(true))) {
    509509        File collectFolder = null;
    510510        if(!open_collection_file_path.endsWith("gli.col")) { // then it's a collect folder
     
    520520        String cfg_file = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
    521521        if(new File(collectFolder.getAbsolutePath()+File.separator+cfg_file).exists()) { // colgroup
    522             collectFolder = collectFolder.getParentFile();
    523            
    524         }
    525         setCollectDirectoryPath(collectFolder.getAbsolutePath()); // now set this as the current collect folder
    526         }
    527        
    528     }
    529     catch (Exception exception) {
     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    }
     547    } catch (Exception exception) {
    530548        DebugStream.printStackTrace(exception);
    531549    }
     
    715733    }
    716734   
    717     return getDefaultGSCollectDirectoryPath();
     735    return getDefaultGSCollectDirectoryPath(true); // file separator appended
    718736   
    719737    }
    720738
    721739    /** Returns the path of the Greenstone "collect" directory. */
    722     static public String getDefaultGSCollectDirectoryPath() {
    723         if (!GS3) {
    724             return Configuration.gsdl_path + "collect" + File.separator;
     740    static public String getDefaultGSCollectDirectoryPath(boolean appendSeparator) {
     741        String colDir;
     742        if (GS3) {
     743            colDir = getSitesDirectoryPath() + Configuration.site_name + File.separator + "collect";           
    725744        }
    726745        else {
    727             return getSitesDirectoryPath() + Configuration.site_name + File.separator + "collect" + File.separator;
    728         }
     746            colDir = Configuration.gsdl_path + "collect";
     747        }
     748       
     749        if(appendSeparator) {
     750            colDir += File.separator;
     751        }
     752        return colDir;
    729753    }   
    730754
     
    802826    }
    803827
    804     // first save any open collection in the *old* location
     828    // first save any open collection in the old location, then close it
    805829    if(Gatherer.c_man.getCollection() != null) {
    806         Gatherer.setCollectDirectoryPath(oldCollectPath); // go back to current collection's location
    807830        Gatherer.g_man.saveThenCloseCurrentCollection(); // close the current collection first
    808831    }
     
    830853    if(Gatherer.GS3) { // web/WEB-INF/cgi/gsdl3site.cfg
    831854        gsdlsitecfg = Configuration.gsdl3_path + File.separator + "WEB-INF"
    832         + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
     855            + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
    833856    } else { // cgi-bin/gsdlsite.cfg
    834857        gsdlsitecfg = Configuration.gsdl_path + File.separator
    835         + "cgi-bin" + File.separator + "gsdlsite.cfg";
     858            + "cgi-bin" + File.separator + "gsdlsite.cfg";
    836859    }
    837860
  • main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java

    r22771 r22806  
    694694        }
    695695       
    696         // We're in the constructor, so we'll be running the LLS the first time,  if we're
    697         // running *server.exe* and if the current collect dir at Local Lib's startup is
    698         // anything other than the default GS collect dir, then use that:
    699         if (isPersistentServer) { // server.exe, so we're dealing with a local GS2
    700             String collectDir = Configuration.getString("general.open_collection_gs2", true);
    701 
    702             // If opening a collection outside the standard GS collect folder, need
    703             // to open the non-standard collect folder that the collection resides in
    704             if (!collectDir.startsWith(Gatherer.getDefaultGSCollectDirectoryPath())) {
    705                 File collectFolder = null;
    706                 if(!collectDir.endsWith("gli.col")) { // then it's a collect folder
    707                     collectFolder = new File(collectDir);
    708                 } else {
    709                     // the filepath is a gli.col file. To get the collect folder: the 1st level
    710                     // up is collection folder, 2 two levels up is the containing collect folder
    711                     collectFolder = new File(collectDir).getParentFile().getParentFile();
     696        // GS2. We're in the constructor, so we'll be running the LLS the first time
     697        // 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
     700        // 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);
    712724                }
    713 
    714                 // Need to deal with colgroups as well: while there's an etc/collect.cfg in the current
    715                 // collectFolder, move one level up
    716                 if(new File(collectFolder.getAbsolutePath()+File.separator+Utility.CONFIG_FILE).exists()) {
    717                     collectFolder = collectFolder.getParentFile();             
    718                 }   
    719                 collectDir = collectFolder.getAbsolutePath();               
    720                
    721                 // write out the non-standard collectDir (minus file separator at end) to the lls site conf
    722                 // file being used
    723                 if(collectDir.endsWith(File.separator)) {
    724                     collectDir = collectDir.substring(0, collectDir.length());
    725                 }
     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            }
     732           
     733            // if we're running *server.exe* and if the current collect dir at Local Lib's startup
     734            // is anything other than the default GS collect dir or if we changed back to the default
     735            // collect dir because the non-standard collectDir didn't exist, then write out
     736            // the new collectDir (minus file separator at end) to the lls site conf in use
     737            if (isPersistentServer) { // server.exe, so we're dealing with a local GS2         
    726738                put(COLLECTHOME, collectDir);
    727739                save();
    728740                lastModified = configFile.lastModified();
    729741            }
     742           
    730743        } // now the correct current collect dir will get loaded when the server is started up hereafter       
    731744    }
Note: See TracChangeset for help on using the changeset viewer.