Ignore:
Timestamp:
2010-10-15T20:33:43+13:00 (14 years ago)
Author:
ak19
Message:

More changes to making collectdir movable: 1. When not working with a remote GS or server.exe: if the collecthome set in GLI is not the same as the one in gsdlsite.cfg used by the apache web server, then a dialog pops up on exiting GLI allowing the user to set the collecthome value for both GLI (in the user's GLI config.xml) and the server (in gsdlsite.cfg). 2. Collecthome line in gsdlsite.cfg is removed if it is the default GS collect folder. (Just as a recent commit stores an empty string for the open_collection element in the GLI config.xml file if no collection is left open on exiting GLI and the collect folder is the default GS collect directory.) 3. Some bug fixes.

File:
1 edited

Legend:

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

    r23031 r23143  
    102102    static private String non_standard_collect_directory_path = null;
    103103    static public String open_collection_file_path = null;
     104    static public String gsdlsite_collecthome = "";
    104105    /** A public reference to the FileAssociationManager. */
    105106    static public FileAssociationManager assoc_man;
     
    315316        if (fedora_info.isActive()) {
    316317        popupFedoraInfo();
    317         }   
    318 
     318        }
    319319       
     320        // the no_load flag to GLI is processed at the end of handling open_collection_file_path
    320321        open_collection_file_path = open_collection;
    321322        if (open_collection_file_path == null) {
     
    323324                "general.open_collection"+Configuration.gliPropertyNameSuffix(), true);
    324325        }
     326       
     327        initCollectDirectoryPath(open_collection);
     328       
    325329        if (no_load || (isGsdlRemote && open_collection_file_path.equals(""))) {
    326330        open_collection_file_path = null;
    327         //      collectDirectoryHasChanged(); // make sure gsdlsite.cfg's collecthome defaults to GS' collect
    328         }
    329        
    330         // If opening a collection outside the standard GS collect folder, need
    331         // to open the non-standard collect folder that the collection resides in
    332         if (!isGsdlRemote
    333             && open_collection_file_path != null
    334             && !open_collection_file_path.startsWith(getDefaultGSCollectDirectoryPath(true)))
    335         {
    336             File collectFolder = null;
    337            
    338             if(!open_collection_file_path.equals("")) {
    339            
    340                 if(!open_collection_file_path.endsWith("gli.col")) { // then it's a collect folder
    341                     collectFolder = new File(open_collection_file_path);
    342                 } else {
    343                     // the filepath is a gli.col file. To get the collect folder: the 1st level
    344                     // up is collection folder, 2 two levels up is the containing collect folder
    345                     collectFolder = new File(open_collection_file_path).getParentFile().getParentFile();
    346                 }   
    347            
    348                 // Need to deal with colgroups as well: while there's an etc/collect.cfg in the current
    349                 // collectFolder, move one level up
    350                 String cfg_file = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
    351                 if(new File(collectFolder.getAbsolutePath()+File.separator+cfg_file).exists()) { // colgroup
    352                     collectFolder = collectFolder.getParentFile();         
    353                 }
    354             }
    355            
    356             if(collectFolder == null || !collectFolder.exists()) {
    357                 // if GLI config file specified no collectDir  (open_collection_file_path is "")
    358                 // OR if dealing with a local server but the collectdir no longer exists,
    359                 // use the default greenstone collect directory, and write that to affected files
    360                
    361                 String defaultColDir = getDefaultGSCollectDirectoryPath(false); // no file separator at end
    362                 open_collection_file_path = defaultColDir;
    363                
    364                 setCollectDirectoryPath(defaultColDir); // will ensure the required file separator at end
    365                
    366                 Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(),
    367                         true, "");
    368                
    369                 if(Gatherer.GS3) {  // GS2's gsdlsite.cfg was taken care of when LocalLibraryServer was started up
    370                                     // (LocalLibraryServer would also already have set glisite.cfg to the correct collecthome)
    371                     String gsdlsitecfg = Configuration.gsdl3_path + File.separator
    372                         + "WEB-INF" + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
    373                     Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", defaultColDir); // no file separator
    374                             // if gsdlsite.cfg does not exist (if using server.exe for instance), the above method will just return
    375                 }
    376             } else { // remote GS, or collect dir exists (all config files will already be set since last GLI session)
    377                 if(collectFolder == null) {
    378                     setCollectDirectoryPath(getDefaultGSCollectDirectoryPath(false)); // no file separator at end
    379                 } else {
    380                     setCollectDirectoryPath(collectFolder.getAbsolutePath()); // now set this as the current collect folder
    381                 }                   
    382             }           
    383331        }
    384332       
     
    711659    // Flush debug
    712660    DebugStream.closeDebugStream();
    713 
     661   
    714662    // If we started a server, we should try to stop it.
    715     if (LocalLibraryServer.isRunning() == true) {
     663    if (LocalLibraryServer.isRunning() == true) {       
    716664        LocalLibraryServer.stop();
    717665    }
     
    751699   
    752700    }
     701   
     702    // if we need to know whether the local server we are running is server.exe vs apache web server
     703    static public boolean isPersistentServer() {
     704        return (!isGsdlRemote && LocalLibraryServer.isPersistentServer());
     705    }
    753706
    754707    /** Returns the path of the Greenstone "collect" directory. */
     
    835788    }
    836789
     790
     791    public static void initCollectDirectoryPath(String open_collection) {       
     792        String defaultColdir = getDefaultGSCollectDirectoryPath(false); // no file separator at end
     793        String coldir = defaultColdir;
     794        // If local GS and opening a collection outside the standard GS collect folder,
     795        // need to open the non-standard collect folder that the collection resides in
     796        if (!isGsdlRemote
     797                && !open_collection_file_path.startsWith(defaultColdir))
     798        {
     799            File collectFolder = null;
     800           
     801            if(!open_collection_file_path.equals("")) {         
     802                if(!open_collection_file_path.endsWith("gli.col")) { // then it's a collect folder
     803                    collectFolder = new File(open_collection_file_path);
     804                } else {
     805                    // the filepath is a gli.col file. To get the collect folder: the 1st level up
     806                    // is the collection folder, 2 two levels up is the containing collect folder
     807                    collectFolder = new File(open_collection_file_path).getParentFile().getParentFile();
     808                }   
     809           
     810                // Need to deal with colgroups as well: while there's an etc/collect.cfg
     811                // in the current collectFolder, move one level up
     812                String cfg_file = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE;
     813                if(new File(collectFolder.getAbsolutePath()+File.separator+cfg_file).exists()) { // colgroup
     814                    collectFolder = collectFolder.getParentFile();         
     815                }
     816            }       
     817           
     818            if(collectFolder == null || !collectFolder.exists()) {
     819                // if GLI config file specified no collectDir (open_collection_file_path is "")
     820                // OR if dealing with a local server but the collectdir no longer exists,
     821                // use the default greenstone collect directory, and write that to affected files
     822               
     823                open_collection_file_path = defaultColdir;      // default GS collect dir
     824                // Configuration.setString("general.open_collection"+Configuration.gliPropertyNameSuffix(), true, "");
     825            } else { // use the coldir value specified in the flags to GLI or from the last GLI session             
     826                coldir = collectFolder.getAbsolutePath();
     827            }           
     828            // set it as the current folder
     829            setCollectDirectoryPath(coldir); // will ensure the required file separator at end
     830        }
     831       
     832        if(!isGsdlRemote) {
     833            // LocalLibraryServer would  already have set glisite.cfg to the correct collecthome for server.exe
     834            // Here we set collecthome in gsdl(3)site.cfg for the GS2 apache web server and GS3 tomcat server
     835            String gsdlsitecfg = getGsdlSiteConfigFile();           
     836            // update the gsdlsite config file and store the old value for use when we exit GLI
     837            if(coldir.equals(defaultColdir)) {             
     838                gsdlsite_collecthome = Utility.updatePropertyConfigFile(
     839                    gsdlsitecfg, "collecthome", null);                     
     840            } else {
     841                gsdlsite_collecthome = Utility.updatePropertyConfigFile(
     842                    gsdlsitecfg, "collecthome", coldir); // no file separator
     843                    // if gsdlsite.cfg does not exist (if using server.exe for instance), the above method will just return
     844            }
     845        }       
     846    }
     847   
     848    /** depending on the version of GS being run, return the path to the current GS' installation's gsdl(3)site.cfg */
     849    public static String getGsdlSiteConfigFile() {
     850        if(Gatherer.GS3) { // web/WEB-INF/cgi/gsdl3site.cfg
     851            return Configuration.gsdl3_path + File.separator + "WEB-INF"
     852                + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
     853        } else { // cgi-bin/gsdlsite.cfg
     854            return Configuration.gsdl_path + File.separator
     855                + "cgi-bin" + File.separator + "gsdlsite.cfg";
     856        }
     857    }
    837858
    838859    public static void collectDirectoryHasChanged(
     
    885906                return;
    886907            }   
    887 
    888             String gsdlsitecfg = "";
    889             if(Gatherer.GS3) { // web/WEB-INF/cgi/gsdl3site.cfg
    890                 gsdlsitecfg = Configuration.gsdl3_path + File.separator + "WEB-INF"
    891                     + File.separator + "cgi" + File.separator + "gsdl3site.cfg";
    892             } else { // cgi-bin/gsdlsite.cfg
    893                 gsdlsitecfg = Configuration.gsdl_path + File.separator
    894                     + "cgi-bin" + File.separator + "gsdlsite.cfg";
    895             }
    896 
     908           
    897909            // non-destructive update of gsdl(3)site.cfg (comments preserved)
    898910            String collectDir = Gatherer.getCollectDirectoryPath();
    899911            //collectDir = "\"" + collectDir.substring(0, collectDir.length()-1) + "\""; // remove file separator at end   
    900912            collectDir = collectDir.substring(0, collectDir.length()-1); // remove file separator at end   
    901             Utility.updatePropertyConfigFile(gsdlsitecfg, "collecthome", collectDir);
     913            Utility.updatePropertyConfigFile(getGsdlSiteConfigFile(), "collecthome", collectDir);
    902914                    // if gsdlsite.cfg does not exist (if using server.exe for instance), the above method will just return
    903915           
Note: See TracChangeset for help on using the changeset viewer.