Changeset 18358

Show
Ignore:
Timestamp:
12.01.2009 11:18:22 (10 years ago)
Author:
kjdon
Message:

updated the rtl-gli branch with files from trunk. Result of a merge 14807:18318

Location:
gli/branches/rtl-gli/src/org/greenstone/gatherer/collection
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • gli/branches/rtl-gli/src/org/greenstone/gatherer/collection/BasicCollectionConfiguration.java

    r14049 r18358  
    5656    private String name = ""; 
    5757    private String is_public = ""; 
     58    private String collectgroup = "false"; 
    5859     
    5960    private String site = null; // used for gs3 colls 
     
    9596            else if(command_type_str.equals(StaticStrings.COLLECTIONMETADATA_MAINTAINER_STR)) { 
    9697                maintainer = tokenizer.nextToken(); 
     98            } 
     99            else if(command_type_str.equals(StaticStrings.COLLECTIONMETADATA_COLLECTGROUP_STR)) { 
     100                collectgroup = tokenizer.nextToken(); 
    97101            } 
    98102            else if(command_type_str.equalsIgnoreCase(StaticStrings.COLLECTIONMETADATA_STR)) { 
     
    228232    return is_public; 
    229233    } 
     234 
     235    public String getCollectGroup() { 
     236    return collectgroup; 
     237    } 
    230238     
    231239    /** Retrieve the short name for this collection which, given this current file is in <col_name>/etc/collect.cfg, is the name of this file's parent file's parent. 
  • gli/branches/rtl-gli/src/org/greenstone/gatherer/collection/Collection.java

    r13819 r18358  
    6262    /** A reference to the import ScriptOptions. */ 
    6363    public ScriptOptions import_options; 
     64    /** A reference to the schedule ScriptOptions */  
     65    public ScriptOptions schedule_options;  
    6466    /** true if an error has occurred during construction */ 
    6567    public boolean error = false; 
     
    8688    /** The name of the import element. */ 
    8789    static final private String IMPORT = "Import"; 
     90    /** The name of the schedule element. */ 
     91    static final private String SCHEDULE = "Schedule";  
     92    /** The name of the export element. */ 
     93    static final private String EXPORT = "Export"; 
    8894    /** The name of the imported attribute. */ 
    8995    static final private String IMPORTED = "imported"; 
     
    111117    } 
    112118    // Finally create all of the child managers that are directly dependant on a collection 
    113     build_options = new ScriptOptions(getBuildValues(), "buildcol.pl"); 
    114     import_options = new ScriptOptions(getImportValues(), "import.pl"); 
     119 
     120    if (Configuration.fedora_info.isActive()) { 
     121        build_options = new ScriptOptions(getValues(BUILD), "g2f-buildcol.pl"); 
     122        import_options = new ScriptOptions(getValues(IMPORT), "g2f-import.pl"); 
     123    } 
     124    else { 
     125        build_options = new ScriptOptions(getBuildValues(), "buildcol.pl"); 
     126        import_options = new ScriptOptions(getImportValues(), "import.pl"); 
     127        schedule_options = new ScriptOptions(getScheduleValues(), "schedule.pl"); 
     128    } 
    115129    } 
    116130     
     
    334348     
    335349 
     350    /** Method to retrieve the current import/build/export/whatever options associated with this Collection. */ 
     351    private Element getValues(String val_type) { 
     352    Element values_element = null; 
     353    try { 
     354        Element document_element = document.getDocumentElement(); 
     355        Element config_element = (Element) XMLTools.getNodeFromNamed(document_element, BUILD_CONFIG); 
     356        values_element = (Element) XMLTools.getNodeFromNamed(config_element, val_type); 
     357        config_element = null; 
     358        document_element = null; 
     359    } 
     360    catch (Exception error) { 
     361        DebugStream.printStackTrace(error); 
     362    } 
     363    return values_element; 
     364    } 
     365 
    336366     
    337367    /** Method to retrieve the current build options associated with this Collection. */ 
     
    349379    } 
    350380    return build_values_element; 
     381    } 
     382 
     383    private Element getScheduleValues() { 
     384    Element schedule_values_element = null; 
     385    try { 
     386        Element document_element = document.getDocumentElement(); 
     387        Element build_config_element = (Element) XMLTools.getNodeFromNamed(document_element, BUILD_CONFIG); 
     388        schedule_values_element = (Element) XMLTools.getNodeFromNamed(build_config_element, SCHEDULE); 
     389        build_config_element = null; 
     390        document_element = null; 
     391    } 
     392    catch (Exception error) { 
     393        DebugStream.printStackTrace(error); 
     394    }  
     395    return schedule_values_element; 
    351396    } 
    352397     
  • gli/branches/rtl-gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r14358 r18358  
    7676import org.w3c.dom.*; 
    7777 
    78 /** This class manages many aspects of the collection, from its creation via scripts, data access via methods and its importing and building into the final collection. It is also resposible for firing appropriate event when significant changes have occured within the collection, and for creating a new metadata set manager as necessary. 
     78/** This class manages many aspects of the collection, from its creation via scripts, data access via methods and its importing and building into the final collection. It is also responsible for firing appropriate event when significant changes have occured within the collection, and for creating a new metadata set manager as necessary. 
    7979 * @author John Thompson 
    8080 * @version 2.3 
     
    8787    /** Are we currently in the process of importing? */ 
    8888    static private boolean importing = false; 
     89    /** Are we currently in the process of scheduling? */  
     90    static private boolean scheduling = false;  
    8991    /** The objects listening for CollectionContentsChanged events. */ 
    9092    static private ArrayList collection_contents_changed_listeners = new ArrayList(); 
     
    9799    /** An inner class listener responsible for noting tree changes and resetting saved when they occur. */ 
    98100    static private FMTreeModelListener fm_tree_model_listener = null; 
    99     /** The monitor resposible for parsing the build process. */ 
     101    /** The monitor responsible for parsing the build process. */ 
    100102    static private GShellProgressMonitor build_monitor = null; 
    101     /** The monitor resposible for parsing the import process. */ 
     103    /** The monitor responsible for parsing the import process. */ 
    102104    static private GShellProgressMonitor import_monitor = null; 
     105    /** The monitor responsible for parsing the scheduler process. */  
     106    static private GShellProgressMonitor schedule_monitor = null;  
    103107 
    104108    /** The name of the standard lock file. */ 
     
    109113    /** Used to indicate the source of the message is the building methods. */ 
    110114    static final public int BUILDING  = 5; 
     115    /** Used to indicate the source of the message is in the scheduling methods...?  */  
     116    static final public int SCHEDULING = 7;  
    111117 
    112118   
     
    116122    this.building = false; 
    117123    this.importing = false; 
     124    this.scheduling = false;  
    118125    this.collection = null; 
    119126 
     
    159166        command_parts_list.add("-S"); 
    160167    } 
    161     command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "buildcol.pl"); 
     168 
     169    if (Configuration.fedora_info.isActive()) { 
     170        command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "g2f-buildcol.pl"); 
     171 
     172        command_parts_list.add("-hostname"); 
     173        command_parts_list.add(Configuration.fedora_info.getHostname()); 
     174 
     175        command_parts_list.add("-port"); 
     176        command_parts_list.add(Configuration.fedora_info.getPort()); 
     177 
     178        command_parts_list.add("-username"); 
     179        command_parts_list.add(Configuration.fedora_info.getUsername()); 
     180 
     181        command_parts_list.add("-password"); 
     182        command_parts_list.add(Configuration.fedora_info.getPassword()); 
     183 
     184        command_parts_list.add("-protocol"); 
     185        command_parts_list.add(Configuration.fedora_info.getProtocol()); 
     186 
     187    } 
     188    else { 
     189        command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "buildcol.pl"); 
     190    } 
    162191    command_parts_list.add("-gli"); 
    163192    command_parts_list.add("-language"); 
     
    187216    } 
    188217 
     218    /*probably repeating alot of work, but I want to keep this separate... wendy*/ 
     219    public void scheduleBuild(boolean incremental_build) 
     220    { 
     221 
     222    DebugStream.println("In CollectionManager.scheduleBuild(), incremental_build: " + incremental_build);  
     223    DebugStream.println("Is event dispatch threa: " + SwingUtilities.isEventDispatchThread());  
     224 
     225    ArrayList sched_list = new ArrayList();  
     226    if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) { 
     227        sched_list.add(Configuration.perl_path); 
     228        sched_list.add("-S"); 
     229    } 
     230    sched_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "schedule.pl");  
     231    sched_list.add("-colname");  
     232    sched_list.add(collection.getName());  
     233    sched_list.add("-gli");  
     234 
     235    // First, generate the import.pl command, also converting to a string 
     236    // Generate the import.pl command 
     237    ArrayList import_list = new ArrayList(); 
     238    if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) { 
     239        import_list.add(Configuration.perl_path); 
     240        import_list.add("-S"); 
     241    } 
     242        import_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "import.pl"); 
     243    import_list.add("-language"); 
     244    import_list.add(Configuration.getLanguage()); 
     245    import_list.add("-collectdir"); 
     246    import_list.add(getCollectDirectory()); 
     247 
     248    String[] import_options = collection.import_options.getValues(); 
     249    int i = 0;  
     250    for (i = 0; i < import_options.length; i++) { 
     251        import_list.add(import_options[i]); 
     252    } 
     253 
     254    import_list.add(collection.getName());   
     255 
     256    String[] import_parts = (String[]) import_list.toArray(new String[0]);  
     257    String command = ""; 
     258    i = 0;  
     259    for (i = 0; i < import_parts.length-1; i++) { 
     260        command = command + import_parts[i] + " ";  
     261    }  
     262    command = command + import_parts[i];  
     263 
     264    sched_list.add("-import");  
     265    sched_list.add("\"" + command + "\"");  
     266 
     267    // Generate the buildcol.pl command, also converting to a string 
     268    ArrayList build_list = new ArrayList(); 
     269 
     270    // i'm not doing this in schedule.pl right now - should i be?  
     271    if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) { 
     272        build_list.add(Configuration.perl_path); 
     273        build_list.add("-S"); 
     274    } 
     275    build_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "buildcol.pl"); 
     276    build_list.add("-language"); 
     277    build_list.add(Configuration.getLanguage()); 
     278    build_list.add("-collectdir"); 
     279    build_list.add(getCollectDirectory()); 
     280 
     281    // If the user hasn't manually specified "-keepold" or "-removeold" then pick one based on incremental_build 
     282    if (!collection.build_options.getValueEnabled("keepold") && !collection.build_options.getValueEnabled("removeold")) { 
     283        build_list.add(incremental_build ? "-keepold" : "-removeold"); 
     284    } 
     285 
     286    String[] build_options = collection.build_options.getValues(); 
     287    for (i = 0; i < build_options.length; i++) { 
     288        build_list.add(build_options[i]); 
     289    } 
     290 
     291    build_list.add(collection.getName()); 
     292     
     293    //build actual string 
     294    String[] build_parts = (String[]) build_list.toArray(new String[0]); 
     295    String command2 = ""; 
     296        for(i = 0; i < build_parts.length-1; i++) { 
     297            command2 = command2 + build_parts[i] + " "; 
     298        } 
     299    command2 = command2 + build_parts[i];  
     300 
     301    sched_list.add("-build");  
     302    sched_list.add("\"" + command2 + "\"");  
     303     
     304    //next, the scheduling frequency goes here 
     305    String[] schedule_options = collection.schedule_options.getValues();   
     306    for(i = 0; i < schedule_options.length; i++) {  
     307        sched_list.add(schedule_options[i]);  
     308    } 
     309 
     310    //now, hope it will run. ;)  
     311    String[] sched_parts = (String[]) sched_list.toArray(new String[0]);  
     312 
     313        GShell shell = new GShell(sched_parts, GShell.SCHEDULE, SCHEDULING, this, schedule_monitor, GShell.GSHELL_SCHEDULE); 
     314    shell.addGShellListener(Gatherer.g_man.create_pane); 
     315    shell.addGShellListener(Gatherer.g_man.format_pane); 
     316    shell.start(); 
     317    } 
    189318 
    190319    /** Used to determine whether the currently active collection has been built. 
     
    193322    public boolean built() { 
    194323    if(collection != null) { 
    195         // Determine if the collection has been built by looking for the build.cfg or buildConfig.xml file 
    196         String file_name = (Gatherer.GS3)? Utility.BUILD_CONFIG_XML : Utility.BUILD_CFG; 
    197         File build_cfg_file = new File(getLoadedCollectionIndexDirectoryPath() + file_name); 
    198         return build_cfg_file.exists(); 
     324        // Determine if the collection has been built by looking for the build.cfg (gs2)  
     325        // buildConfig.xml (gs3) or export.inf (fedora) file 
     326        String file_name = ""; 
     327         
     328        if (Configuration.fedora_info.isActive()) { // FLI case 
     329        // Fedora build 
     330        //file_name = getLoadedCollectionArchivesDirectoryPath() + "import.inf"; 
     331        file_name = getLoadedCollectionExportDirectoryPath() + "export.inf"; 
     332        } else {  
     333        // GLI is running, check if it's greenstone 3 or greenstone 2 
     334        if (Gatherer.GS3) { // GS3 GLI 
     335            file_name = getLoadedCollectionIndexDirectoryPath() + Utility.BUILD_CONFIG_XML; 
     336        } 
     337        else { // greenstone 2 GLI 
     338            file_name = getLoadedCollectionIndexDirectoryPath() + Utility.BUILD_CFG;            
     339        } 
     340        } 
     341        File test_file = new File(file_name); 
     342        return test_file.exists(); 
    199343    } 
    200344    return false; 
     
    235379    // Remove the lock file on the server 
    236380    if (Gatherer.isGsdlRemote) { 
    237         RemoteGreenstoneServer.deleteCollectionFile(collection.getName(), lock_file); 
     381        Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection.getName(), lock_file); 
    238382    } 
    239383 
     
    380524        if (!new File(collection_directory_path).exists()) { 
    381525        // If there is no collection directory then the creation was unsuccessful, or cancelled 
    382  
     526           
    383527        return; 
    384528        } 
     
    403547        collection_import_directory.mkdirs(); 
    404548        if (Gatherer.isGsdlRemote) { 
    405             RemoteGreenstoneServer.newCollectionDirectory(name, collection_import_directory); 
     549            Gatherer.remoteGreenstoneServer.newCollectionDirectory(name, collection_import_directory); 
    406550        } 
    407551        } 
     
    413557        collection.import_options.setValue("removeold", true, null); 
    414558 
     559        // for remote case, scheduling causes an Exception on creating a new collection that  
     560        // can't be recovered from. For GS3, it doesn't work since it it trying to access etc/main.cfg 
     561        if (canDoScheduling()) { 
     562        scheduling(); 
     563        } 
     564                 
    415565        MetadataSetManager.clearMetadataSets(); 
    416566        MetadataXMLFileManager.clearMetadataXMLFiles(); 
     
    431581        if (Gatherer.isGsdlRemote) { 
    432582            String base_collection_name = base_collection_directory.getName(); 
    433             RemoteGreenstoneServer.downloadCollection(base_collection_name); 
     583            Gatherer.remoteGreenstoneServer.downloadCollection(base_collection_name); 
    434584        } 
    435585 
     
    513663        DebugStream.printStackTrace(error); 
    514664    } 
     665    } 
     666 
     667    private void scheduling()  
     668    throws Exception 
     669    { 
     670    //try to obtain email address of collection owner if it exists...  
     671    String stmp = Configuration.getEmail();  
     672    if(stmp != null) { 
     673        collection.schedule_options.setValue("toaddr", false, Configuration.getEmail()); 
     674    } 
     675     
     676    //The next few items deal with updating the SMTP server, and the to: and from: addresses 
     677    //from main.cfg and the collection configuration. if no changes are made, or the  
     678    //values are result to NULL, any existing values are kept.  
     679 
     680    //try to obtain email address of Greenstone installation webmaster for - used to indicate "sender".  
     681    File mcfg = new File(LocalGreenstone.getDirectoryPath() + File.separator + "etc" + File.separator + "main.cfg"); 
     682    BufferedReader maincfg = new BufferedReader(new FileReader(mcfg));       
     683        stmp = ""; 
     684        String fromaddr = "";  
     685        while((stmp = maincfg.readLine()) != null) {  
     686        if(stmp.startsWith("maintainer")) { 
     687               fromaddr = stmp.substring(10); //length of MailServer  
     688           fromaddr = fromaddr.trim();   
     689           break;  
     690        } 
     691        } 
     692        maincfg.close();  
     693        if(!fromaddr.equals("NULL") && !fromaddr.equals("null")) { 
     694        collection.schedule_options.setValue("fromaddr", false, fromaddr);       
     695        } 
     696 
     697        //try to obtain an smtp server address from main.cfg. If that fails, 
     698        //try mail.server if an email address exists. If that fails, 
     699        //maybe a message to set attribute in main.cfg?  
     700        //i'm pretty sure there exists functionality to do this, but  
     701        //i'll finish this faster if I just wrote it 
     702 
     703 
     704        maincfg = new BufferedReader(new FileReader(mcfg));        
     705        String smtptmp = "NULL"; 
     706        while((stmp = maincfg.readLine()) != null) {  
     707        if(stmp.startsWith("MailServer")) { 
     708               smtptmp = stmp.substring(10); //length of MailServer  
     709           smtptmp = smtptmp.trim();  
     710           break;  
     711        } 
     712        } 
     713            maincfg.close(); 
     714 
     715            //try if lookup fails 
     716            if(smtptmp.equals("NULL") || smtptmp.equals("null")) { 
     717        String email2=fromaddr;  
     718        if(!email2.equals("NULL") && !email2.equals("null")) { 
     719            int loc = email2.indexOf('@');  
     720            email2 = email2.substring(loc+1);  
     721            smtptmp = "mail."+email2; 
     722            } 
     723            } 
     724        if(!smtptmp.equals("NULL") && !smtptmp.equals("null")) {  
     725        collection.schedule_options.setValue("smtp", false, smtptmp); 
     726        } 
     727 
    515728    } 
    516729 
     
    552765    // Delete the collection on the server if we're using a remote Greenstone 
    553766    if (Gatherer.isGsdlRemote) { 
    554         RemoteGreenstoneServer.deleteCollection(collection_name); 
    555     } 
    556  
     767        Gatherer.remoteGreenstoneServer.deleteCollection(collection_name); 
     768    } 
     769 
     770    // if Greenstone3, need to deactivate the collection on the server 
     771    if (Gatherer.GS3) { 
     772        Gatherer.configGS3Server(Configuration.site_name, ServletConfiguration.DEACTIVATE_COMMAND + collection_name); 
     773    } 
     774     
    557775    // Now delete the collection directory 
    558776    return Utility.delete(new File(getCollectionDirectoryPath(collection_name))); 
     
    591809    return getLoadedCollectionDirectoryPath() + "archives" + File.separator; 
    592810    } 
     811 
     812    /** Returns the absolute filename of the loaded collection's export directory. 
     813     */ 
     814    static public String getLoadedCollectionExportDirectoryPath() 
     815    { 
     816    return getLoadedCollectionDirectoryPath() + "export" + File.separator; 
     817    } 
     818 
    593819 
    594820 
     
    764990        command_parts_list.add("-S"); 
    765991    } 
    766     command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "import.pl"); 
     992 
     993    if (Configuration.fedora_info.isActive()) { 
     994        command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "g2f-import.pl"); 
     995 
     996        command_parts_list.add("-hostname"); 
     997        command_parts_list.add(Configuration.fedora_info.getHostname()); 
     998 
     999        command_parts_list.add("-port"); 
     1000        command_parts_list.add(Configuration.fedora_info.getPort()); 
     1001 
     1002        command_parts_list.add("-username"); 
     1003        command_parts_list.add(Configuration.fedora_info.getUsername()); 
     1004 
     1005        command_parts_list.add("-password"); 
     1006        command_parts_list.add(Configuration.fedora_info.getPassword()); 
     1007 
     1008        command_parts_list.add("-protocol"); 
     1009        command_parts_list.add(Configuration.fedora_info.getProtocol()); 
     1010    } 
     1011    else { 
     1012        command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "import.pl"); 
     1013    } 
     1014 
    7671015    command_parts_list.add("-gli"); 
    7681016    command_parts_list.add("-language"); 
     
    8081056        // If we're using a remote Greenstone server, upload the metadata file 
    8091057        if (Gatherer.isGsdlRemote) { 
    810             RemoteGreenstoneServer.uploadCollectionFile(collection.getName(), metadata_set_file); 
     1058            Gatherer.remoteGreenstoneServer.uploadCollectionFile(collection.getName(), metadata_set_file); 
    8111059        } 
    8121060        } 
     
    8741122    if (Gatherer.isGsdlRemote) { 
    8751123        String collection_name = location.substring(location.lastIndexOf(File.separator) + 1, location.length() - ".col".length()); 
    876         if (RemoteGreenstoneServer.downloadCollection(collection_name).equals("")) { 
     1124        if (Gatherer.remoteGreenstoneServer.downloadCollection(collection_name).equals("")) { 
    8771125        return; 
    8781126        } 
     
    9591207        System.err.println("Cannot write lock file!"); 
    9601208        String args[] = new String[2]; 
    961         args[0] = location; 
    962         args[1] = Dictionary.get("FileActions.Write_Not_Permitted_Title"); 
     1209        args[0] = location;      
     1210        args[1] = Dictionary.get("FileActions.Write_Not_Permitted_Message", new String[]{lock_file.getAbsolutePath()});      
     1211        if(Gatherer.client_operating_system.toUpperCase().indexOf("WINDOWS")!=-1){         
     1212          //if(Gatherer.client_operating_system.toUpperCase().indexOf("VISTA")!=-1){             
     1213            args[1] += Dictionary.get("FileActions.File_Permission_Detail", new String[]{Configuration.gsdl_path, System.getProperty("user.name")}); 
     1214          //}  
     1215        } 
    9631216        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Cannot_Open_With_Reason", args), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 
    9641217        args = null; 
    9651218        return; 
    9661219        } 
    967  
     1220         
     1221        if (canDoScheduling()) { 
     1222        //THIS LOOKS LIKE THE BEST PLACE TO TRY AND UPDATE .col FILES FOR EXISTING COLLECTIONS...Wendy 
     1223  
     1224        //First, see if "Schedule" exists in the XMl File...  
     1225        BufferedReader bir = new BufferedReader(new FileReader(collection_file));  
     1226        boolean flag = false;  
     1227        try { 
     1228            String stmp = new String();  
     1229            
     1230            while((stmp = bir.readLine()) != null) { 
     1231            stmp = stmp.trim();   
     1232            if(stmp.equals("<Schedule>") || stmp.equals("<Schedule/>")) { 
     1233                flag = true;  
     1234                break;  
     1235            } 
     1236            } 
     1237            bir.close();  
     1238             
     1239        } catch (IOException ioe) { 
     1240            DebugStream.printStackTrace(ioe); 
     1241        } 
     1242         
     1243        //modify if old .col (i.e. no Schedule exists in XML file) 
     1244        if(!flag) { 
     1245            File new_collection_file = new File(collection_directory.getAbsolutePath() + "/tmp.col"); 
     1246             
     1247             
     1248            BufferedWriter bor = new BufferedWriter(new FileWriter(new_collection_file));  
     1249            bir = new BufferedReader(new FileReader(collection_file));  
     1250             
     1251            try {  
     1252            String stmp = new String();  
     1253            while((stmp = bir.readLine()) != null) { 
     1254                String stmp2 = stmp.trim();  
     1255                if(stmp2.startsWith("<!ELEMENT Argument")) { 
     1256                bor.write("  <!ELEMENT Schedule          (Arguments*)>\n");                 
     1257                } 
     1258                else if(stmp2.equals("</BuildConfig>")) { 
     1259                bor.write("      <Schedule/>\n");  
     1260                } 
     1261                 
     1262                bor.write(stmp + "\n");  
     1263                 
     1264            } 
     1265            bir.close();  
     1266            bor.close(); 
     1267            } catch (IOException ioe) {   
     1268            DebugStream.printStackTrace(ioe); 
     1269            }   
     1270             
     1271            //copy over tmp.col to replace  
     1272            try {  
     1273            collection_file.delete(); 
     1274            new_collection_file.renameTo(collection_file);  
     1275            } catch (Exception e) {  
     1276            DebugStream.printStackTrace(e); 
     1277            }  
     1278        } 
     1279        } 
     1280         
    9681281        // Open the collection file 
    9691282        this.collection = new Collection(collection_file); 
     
    9761289        throw(new Exception(Dictionary.get("CollectionManager.Missing_Config"))); // this error message does not agree with the error 
    9771290        } 
    978  
     1291         
     1292        if (canDoScheduling()) { 
     1293        scheduling(); 
     1294        } 
     1295       
    9791296            MetadataSetManager.clearMetadataSets(); 
    9801297        MetadataSetManager.loadMetadataSets(collection_metadata_directory); 
     
    9971314        MetadataXMLFileManager.loadMetadataXMLFiles(collection_import_directory,collection.toSkimFile()); 
    9981315 
    999         // Read through the doc.xml files in the archives directory 
    1000         File collection_archives_directory = new File(getLoadedCollectionArchivesDirectoryPath()); 
     1316         
     1317        // get rid of the previous scan through docxml files 
    10011318        DocXMLFileManager.clearDocXMLFiles(); 
    1002         DocXMLFileManager.loadDocXMLFiles(collection_archives_directory); 
     1319 
     1320        if (Configuration.fedora_info.isActive()) { // FLI case 
     1321        // Read through the docmets.xml files in the export directory 
     1322        File collection_export_directory = new File(getLoadedCollectionExportDirectoryPath()); 
     1323        DocXMLFileManager.loadDocXMLFiles(collection_export_directory,"docmets.xml"); 
     1324        } 
     1325        else { 
     1326        // Read through the doc.xml files in the archives directory 
     1327        File collection_archives_directory = new File(getLoadedCollectionArchivesDirectoryPath()); 
     1328        DocXMLFileManager.loadDocXMLFiles(collection_archives_directory,"doc.xml"); 
     1329        } 
     1330 
    10031331 
    10041332        // Get a list of the collection specific classifiers and plugins 
     
    10191347        // There is obviously no existing collection present. 
    10201348        DebugStream.printStackTrace(error); 
     1349        error.printStackTrace(); 
    10211350        if(error.getMessage() != null) { 
    10221351        String[] args = new String[2]; 
    1023         args[0] = location; 
    1024         args[1] = error.getMessage(); 
     1352        args[0] = location;      
     1353        //args[1] = error.getMessage(); 
     1354        args[1] = "The Librarian Interface does not have permission to write to... Please check file permissions."; 
    10251355        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Cannot_Open_With_Reason", args), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 
    10261356        } 
     
    10351365    } 
    10361366 
     1367    /** At present, scheduling only works for GS2, only when GS2 is local and only when GLI runs from 
     1368     * within a GS2 installation. This method can be adjusted as scheduling becomes available for more 
     1369     * more situations. */ 
     1370    public static boolean canDoScheduling() { 
     1371    // Would be nice to support more of these, rather than returning false 
     1372    if(Gatherer.isGsdlRemote) { 
     1373        return false; 
     1374    }  
     1375    if(Gatherer.GS3) { 
     1376        return false; 
     1377    } 
     1378    if (Configuration.fedora_info.isActive()) { 
     1379        return false; 
     1380    } 
     1381 
     1382    // GS2's etc/main.cfg is necessary for scheduling, but scheduling looks for it locally:  
     1383    // it assumes GLI is inside a GS2 installation 
     1384    File mcfg = new File(LocalGreenstone.getDirectoryPath() + File.separator + "etc" + File.separator + "main.cfg"); 
     1385    if(!mcfg.exists()) { 
     1386        System.out.println("Cannot do scheduling, since there is no file: " + mcfg.getAbsolutePath()  
     1387                   + ".\nScheduling presently depends on GLI running from inside a GS2."); 
     1388        return false; 
     1389    } 
     1390     
     1391    return true; 
     1392    } 
    10371393 
    10381394    private void makeCollection(String name, String email) 
     
    10451401    } 
    10461402    command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "mkcol.pl"); 
    1047     command_parts_list.add((Gatherer.GS3) ? Utility.GS3MODE_ARGUMENT : "");// add '-gs3mode'  
     1403    if(Gatherer.GS3) { 
     1404        command_parts_list.add(Utility.GS3MODE_ARGUMENT); // add '-gs3mode'  
     1405    } 
    10481406 
    10491407    command_parts_list.add("-collectdir"); 
     
    10621420    // Run the mkcol.pl command 
    10631421    String[] command_parts = (String[]) command_parts_list.toArray(new String[0]); 
     1422    //for(int i = 0; i < command_parts.length; i++) { 
     1423    ///ystem.err.println("\""+command_parts[i]+"\""); 
     1424    //} 
    10641425     
    10651426    GShell process = new GShell(command_parts, GShell.NEW, COLLECT, this, null, GShell.GSHELL_NEW); 
     
    10721433     */ 
    10731434    public synchronized void message(GShellEvent event) { 
     1435       
    10741436    } 
    10751437 
     
    11231485        buildCollection(false); 
    11241486    } 
     1487    else if(event.getType() == GShell.SCHEDULE && event.getStatus() == GShell.OK ) { 
     1488 
     1489        WarningDialog collection_built_warning_dialog = new WarningDialog("warning.ScheduleBuilt", Dictionary.get("ScheduleBuilt.Title"), Dictionary.get("ScheduleBuilt.Message"), null, false); 
     1490        collection_built_warning_dialog.setMessageOnly(true); // Not a warning 
     1491        collection_built_warning_dialog.display(); 
     1492        collection_built_warning_dialog.dispose(); 
     1493        collection_built_warning_dialog = null;    
     1494    }  
    11251495    // If we were running a build, now is when we move files across. 
    11261496    else if(event.getType() == GShell.BUILD && event.getStatus() == GShell.OK) { 
     
    11591529        Gatherer.g_man.repaint(); 
    11601530    } 
    1161     else if (event.getStatus() == GShell.ERROR) { 
    1162         DebugStream.println("There was an error in the gshell:"+ event.getMessage()); 
    1163         if (event.getType() == GShell.NEW) { 
    1164         JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Cannot_Create_Collection"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 
    1165         } else { 
     1531    else if (event.getStatus() == GShell.ERROR) {        
     1532        if (event.getType() == GShell.NEW) {      
     1533          String name = event.getMessage(); 
     1534          String collectDir = getCollectionDirectoryPath(name); 
     1535          String errMsg = ""; 
     1536          if (!new File(getCollectionDirectoryPath(name)).exists() || !new File(getCollectionDirectoryPath(name)).canWrite()) {        
     1537        String reason = Dictionary.get("FileActions.Write_Not_Permitted_Message", new String[]{collectDir}); 
     1538        errMsg = Dictionary.get("CollectionManager.Cannot_Create_Collection_With_Reason", new String[]{reason}); 
     1539        if(Gatherer.client_operating_system.toUpperCase().indexOf("WINDOWS") != -1){           
     1540          //if(Gatherer.client_operating_system.toUpperCase().indexOf("VISTA")!=-1){             
     1541            errMsg += Dictionary.get("FileActions.File_Permission_Detail", new String[]{Configuration.gsdl_path, System.getProperty("user.name")}); 
     1542          //}  
     1543        } 
     1544          } else { 
     1545        errMsg = Dictionary.get("CollectionManager.Cannot_Create_Collection"); 
     1546          } 
     1547          JOptionPane.showMessageDialog(Gatherer.g_man, errMsg, Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 
     1548        }  
     1549        else if(event.getType() == GShell.SCHEDULE) {  
     1550        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Schedule_Failed"), Dictionary.get("CollectionManager.Schedule_Ready_Title"), JOptionPane.ERROR_MESSAGE); 
     1551        } 
     1552        else { 
    11661553        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Preview_Ready_Failed"), Dictionary.get("CollectionManager.Preview_Ready_Title"), JOptionPane.ERROR_MESSAGE); 
    11671554        Gatherer.refresh(Gatherer.COLLECTION_REBUILT); 
     
    11991586    } 
    12001587 
     1588    public void registerScheduleMonitor(GShellProgressMonitor monitor) {  
     1589    schedule_monitor = monitor;  
     1590    } 
     1591 
    12011592 
    12021593    static public void removeCollectionContentsChangedListener(CollectionContentsChangedListener listener) 
     
    12271618        // If we're using a remote Greenstone server, delete the metadata file on the server 
    12281619        if (Gatherer.isGsdlRemote) { 
    1229         RemoteGreenstoneServer.deleteCollectionFile(collection.getName(), metadata_set_file); 
     1620        Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection.getName(), metadata_set_file); 
    12301621        } 
    12311622    } 
     
    13171708    private boolean installCollection() 
    13181709    { 
     1710    if (Configuration.fedora_info.isActive()) { 
     1711        DebugStream.println("Fedora build complete. No need to move files."); 
     1712        return true; 
     1713    } 
     1714 
     1715        
    13191716    DebugStream.println("Build complete. Moving files."); 
    13201717 
     
    13531750 
    13541751        if (Gatherer.isGsdlRemote) { 
    1355             RemoteGreenstoneServer.deleteCollectionFile(collection.getName(), new File(getLoadedCollectionIndexDirectoryPath())); 
    1356             RemoteGreenstoneServer.moveCollectionFile(collection.getName(), new File(getLoadedCollectionBuildingDirectoryPath()), new File(getLoadedCollectionIndexDirectoryPath())); 
     1752            Gatherer.remoteGreenstoneServer.deleteCollectionFile( 
     1753                             collection.getName(), new File(getLoadedCollectionIndexDirectoryPath())); 
     1754            Gatherer.remoteGreenstoneServer.moveCollectionFile(collection.getName(),  
     1755                    new File(getLoadedCollectionBuildingDirectoryPath()), new File(getLoadedCollectionIndexDirectoryPath())); 
    13571756        } 
    13581757 
  • gli/branches/rtl-gli/src/org/greenstone/gatherer/collection/CollectionTree.java

    r13604 r18358  
    9999        JLabel tree_cell = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 
    100100 
    101         // Mark explodable files with a different icon 
    102         if (value instanceof CollectionTreeNode && ((CollectionTreeNode) value).isExplodable()) { 
    103         tree_cell.setIcon(CollectionTreeNode.GREEN_FILE_ICON); 
    104         } 
    105  
     101        // Mark explodable files and SrcReplaceable files with a different icon (Green file icon) 
     102        if(value instanceof CollectionTreeNode) { 
     103        if(((CollectionTreeNode) value).isExplodable() || ((CollectionTreeNode) value).isSrcReplaceable()) { 
     104            tree_cell.setIcon(CollectionTreeNode.GREEN_FILE_ICON); 
     105        } 
     106        } 
     107             
    106108        return tree_cell; 
    107109    } 
     
    125127    private JMenuItem expand_folder = null; 
    126128    private JMenuItem explode_metadata_database = null; 
     129    private JMenuItem replace_srcdoc_with_html = null; 
    127130    private JMenuItem delete = null; 
    128131    private JMenuItem metaaudit = null; 
    129132    private JMenuItem new_folder = null; 
    130133    private JMenuItem new_dummy_doc = null; 
     134    private JMenuItem refresh = null; // for refreshing folder view 
    131135    private JMenuItem open_externally = null; 
    132136    private JMenuItem rename = null; 
     
    202206    } 
    203207 
     208    /** Checks whether the files selected are of the same filetype (have the same extension). 
     209     * @param selectedFilePaths - the full file paths to the treenodes selected in the  
     210     * collection fileview.  
     211     * @return true if the file extensions of all the selected files are the same. False is  
     212     * returned if the file extension of any selected file is different (this means that if  
     213     * a folder was selected, false would be returned). False is also returned if nothing was 
     214     * selected. 
     215     * For use with replace_srcdoc_with_html.pl 
     216    */ 
     217    private boolean selectedFilesOfSameType(TreePath[] selectedFilePaths) { 
     218        if(selectedFilePaths == null || selectedFilePaths.length <= 0) 
     219        return false; 
     220 
     221        boolean sameExtension = true; 
     222 
     223        // get just the filename from the path and extract its extension 
     224        String firstFile = selectedFilePaths[0].getLastPathComponent().toString(); 
     225        int period = firstFile.lastIndexOf('.'); 
     226        if(period == -1) { // someone could have selected a folder 
     227        return false; 
     228        } 
     229        String extension = firstFile.substring(period); // includes period 
     230 
     231        // compare with the other selected files' extensions: 
     232        for(int i = 1; i < selectedFilePaths.length && sameExtension; i++) { 
     233        String otherFile = selectedFilePaths[i].getLastPathComponent().toString(); 
     234        String otherFileExt = otherFile.substring(otherFile.lastIndexOf('.')); 
     235        if(!extension.equals(otherFileExt))  
     236            sameExtension = false; 
     237        } 
     238        return sameExtension; 
     239    } 
    204240 
    205241    private void buildContextMenu(TreePath[] selection_paths) 
     
    215251        add(new_dummy_doc); 
    216252 
     253        refresh = new JMenuItem(Dictionary.get("CollectionPopupMenu.Refresh")); 
     254        refresh.addActionListener(this); 
     255        add(refresh); 
     256 
    217257        node = (CollectionTreeNode) collection_tree.getModel().getRoot(); 
    218258        return; 
     
    228268        add(delete); 
    229269 
    230         // Only meta-audit and delete are available if multiple items are selected... 
     270        // The src doc replaceable (with html file) option is only available when all files selected are of the 
     271        // same type (same extension). For srcreplaceable files only. Works with replace_srcdoc_with_html.pl 
     272        CollectionTreeNode firstSelectedNode = (CollectionTreeNode)selection_paths[0].getLastPathComponent(); 
     273        if(firstSelectedNode.isSrcReplaceable()) { // test the first selected node 
     274        replace_srcdoc_with_html = new JMenuItem(Dictionary.get("Menu.Replace_SrcDoc_With_HTML"), KeyEvent.VK_H); 
     275        replace_srcdoc_with_html.addActionListener(this);        
     276        add(replace_srcdoc_with_html); 
     277         
     278        // Now the menu is there, grey it out if not all the files are of the same type 
     279        if(!selectedFilesOfSameType(selection_paths)) { 
     280            replace_srcdoc_with_html.setEnabled(false); 
     281        }  
     282        } 
     283        
     284        // Only meta-audit and delete (and possibly replace_srcdoc) are available if multiple items are selected... 
    231285        if (selection_paths.length > 1) { 
    232286        return; 
     
    249303            add(explode_metadata_database); 
    250304        } 
    251  
     305     
    252306        // Replace file 
    253307        // !! TO DO: Remote building 
     
    294348    /** Called whenever one of the menu items is clicked, this method then causes the appropriate effect. */ 
    295349    public void actionPerformed(ActionEvent event) 
    296     { 
    297         Object source = event.getSource(); 
     350    {    
     351        Object source = event.getSource(); 
    298352 
    299353        // Collapse folder 
     
    310364        else if (source == explode_metadata_database) { 
    311365        Gatherer.f_man.explodeMetadataDatabase(node.getFile()); 
     366        } 
     367         
     368        // Replace source document with generated html (works with replace_srcdoc_with_html.pl) 
     369        else if (source == replace_srcdoc_with_html) { 
     370        java.io.File[] source_files = new java.io.File[selection_paths.length]; 
     371        for (int i = 0; i < selection_paths.length; i++) { 
     372            CollectionTreeNode node = (CollectionTreeNode) selection_paths[i].getLastPathComponent();  
     373            source_files[i] = node.getFile(); 
     374        } 
     375        Gatherer.f_man.replaceSrcDocWithHtml(source_files); // passing the selected files 
    312376        } 
    313377 
     
    338402        } 
    339403 
     404        // Refresh action to reload folder view 
     405        else if (source == refresh) { // Refresh collection tree 
     406        Gatherer.g_man.refreshCollectionTree(DragTree.COLLECTION_CONTENTS_CHANGED); 
     407        } 
     408 
    340409        // Open in external program 
    341410        else if (source == open_externally) { 
  • gli/branches/rtl-gli/src/org/greenstone/gatherer/collection/CollectionTreeNode.java

    r10011 r18358  
    3333import org.greenstone.gatherer.file.FileNode; 
    3434import org.greenstone.gatherer.util.JarTools; 
     35import java.util.Set; 
     36import java.util.Iterator; 
     37import java.nio.charset.Charset; 
    3538 
    3639 
     
    4043{ 
    4144    static final public ImageIcon GREEN_FILE_ICON = JarTools.getImage("greenfile.gif", true); 
    42  
     45     
    4346    /** Is this file a metadata database that is explodable with the explode_metadata_databases.pl script? */ 
    4447    private boolean is_explodable = false; 
    4548 
     49    /** Keeps track of whether this file can be replaced with a Greenstone-generated html file. 
     50     * To work with replace_srcdoc_with_html.pl */ 
     51    private boolean is_srcreplaceable = false; 
    4652 
    4753    public CollectionTreeNode(File file) 
     
    5056 
    5157    this.is_explodable = CollectionDesignManager.plugin_manager.isFileExplodable(file); 
     58    // To work with replace_srcdoc_with_html.pl 
     59    this.is_srcreplaceable = CollectionDesignManager.plugin_manager.isFileSrcReplaceable(file); 
     60     
    5261    } 
    5362 
     
    6675    return is_explodable; 
    6776    } 
     77 
     78    // To work with replace_srcdoc_with_html.pl 
     79    public boolean isSrcReplaceable() 
     80    { 
     81    return is_srcreplaceable; 
     82    } 
    6883} 
  • gli/branches/rtl-gli/src/org/greenstone/gatherer/collection/ScriptOptions.java

    r13753 r18358  
    225225 
    226226        if (Gatherer.isGsdlRemote) { 
    227         String script_output = RemoteGreenstoneServer.getScriptOptions(filename, ""); 
     227        String script_output = Gatherer.remoteGreenstoneServer.getScriptOptions(filename, ""); 
    228228        document = XMLTools.parseXML(new StringReader(script_output)); 
    229229        } 
     
    247247        } 
    248248 
     249 
    249250        // Create the process. 
    250251        Runtime runtime = Runtime.getRuntime(); 
    251252        Process process = runtime.exec(args); 
     253 
     254         
     255        for (int i=0; i<args.length; i++) {  
     256            System.err.print(args[i] + " "); 
     257        } 
     258        System.err.println(""); 
     259         
     260 
     261 
    252262        document = XMLTools.parseXML(process.getErrorStream()); 
     263         
     264        if (document == null) { 
     265            // command has not generated XML, script has probably failed in some way 
     266            for (int i=0; i<args.length; i++) {  
     267            DebugStream.print(args[i] + " "); 
     268            } 
     269            DebugStream.println(""); 
     270        } 
    253271        } 
    254272