Changeset 18358
- Timestamp:
- 2009-01-12T11:18:22+13:00 (15 years ago)
- Location:
- gli/branches/rtl-gli/src/org/greenstone/gatherer/collection
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
gli/branches/rtl-gli/src/org/greenstone/gatherer/collection/BasicCollectionConfiguration.java
r14049 r18358 56 56 private String name = ""; 57 57 private String is_public = ""; 58 private String collectgroup = "false"; 58 59 59 60 private String site = null; // used for gs3 colls … … 95 96 else if(command_type_str.equals(StaticStrings.COLLECTIONMETADATA_MAINTAINER_STR)) { 96 97 maintainer = tokenizer.nextToken(); 98 } 99 else if(command_type_str.equals(StaticStrings.COLLECTIONMETADATA_COLLECTGROUP_STR)) { 100 collectgroup = tokenizer.nextToken(); 97 101 } 98 102 else if(command_type_str.equalsIgnoreCase(StaticStrings.COLLECTIONMETADATA_STR)) { … … 228 232 return is_public; 229 233 } 234 235 public String getCollectGroup() { 236 return collectgroup; 237 } 230 238 231 239 /** 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 62 62 /** A reference to the import ScriptOptions. */ 63 63 public ScriptOptions import_options; 64 /** A reference to the schedule ScriptOptions */ 65 public ScriptOptions schedule_options; 64 66 /** true if an error has occurred during construction */ 65 67 public boolean error = false; … … 86 88 /** The name of the import element. */ 87 89 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"; 88 94 /** The name of the imported attribute. */ 89 95 static final private String IMPORTED = "imported"; … … 111 117 } 112 118 // 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 } 115 129 } 116 130 … … 334 348 335 349 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 336 366 337 367 /** Method to retrieve the current build options associated with this Collection. */ … … 349 379 } 350 380 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; 351 396 } 352 397 -
gli/branches/rtl-gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r14358 r18358 76 76 import org.w3c.dom.*; 77 77 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 respo sible 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. 79 79 * @author John Thompson 80 80 * @version 2.3 … … 87 87 /** Are we currently in the process of importing? */ 88 88 static private boolean importing = false; 89 /** Are we currently in the process of scheduling? */ 90 static private boolean scheduling = false; 89 91 /** The objects listening for CollectionContentsChanged events. */ 90 92 static private ArrayList collection_contents_changed_listeners = new ArrayList(); … … 97 99 /** An inner class listener responsible for noting tree changes and resetting saved when they occur. */ 98 100 static private FMTreeModelListener fm_tree_model_listener = null; 99 /** The monitor respo sible for parsing the build process. */101 /** The monitor responsible for parsing the build process. */ 100 102 static private GShellProgressMonitor build_monitor = null; 101 /** The monitor respo sible for parsing the import process. */103 /** The monitor responsible for parsing the import process. */ 102 104 static private GShellProgressMonitor import_monitor = null; 105 /** The monitor responsible for parsing the scheduler process. */ 106 static private GShellProgressMonitor schedule_monitor = null; 103 107 104 108 /** The name of the standard lock file. */ … … 109 113 /** Used to indicate the source of the message is the building methods. */ 110 114 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; 111 117 112 118 … … 116 122 this.building = false; 117 123 this.importing = false; 124 this.scheduling = false; 118 125 this.collection = null; 119 126 … … 159 166 command_parts_list.add("-S"); 160 167 } 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 } 162 191 command_parts_list.add("-gli"); 163 192 command_parts_list.add("-language"); … … 187 216 } 188 217 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 } 189 318 190 319 /** Used to determine whether the currently active collection has been built. … … 193 322 public boolean built() { 194 323 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(); 199 343 } 200 344 return false; … … 235 379 // Remove the lock file on the server 236 380 if (Gatherer.isGsdlRemote) { 237 RemoteGreenstoneServer.deleteCollectionFile(collection.getName(), lock_file);381 Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection.getName(), lock_file); 238 382 } 239 383 … … 380 524 if (!new File(collection_directory_path).exists()) { 381 525 // If there is no collection directory then the creation was unsuccessful, or cancelled 382 526 383 527 return; 384 528 } … … 403 547 collection_import_directory.mkdirs(); 404 548 if (Gatherer.isGsdlRemote) { 405 RemoteGreenstoneServer.newCollectionDirectory(name, collection_import_directory);549 Gatherer.remoteGreenstoneServer.newCollectionDirectory(name, collection_import_directory); 406 550 } 407 551 } … … 413 557 collection.import_options.setValue("removeold", true, null); 414 558 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 415 565 MetadataSetManager.clearMetadataSets(); 416 566 MetadataXMLFileManager.clearMetadataXMLFiles(); … … 431 581 if (Gatherer.isGsdlRemote) { 432 582 String base_collection_name = base_collection_directory.getName(); 433 RemoteGreenstoneServer.downloadCollection(base_collection_name);583 Gatherer.remoteGreenstoneServer.downloadCollection(base_collection_name); 434 584 } 435 585 … … 513 663 DebugStream.printStackTrace(error); 514 664 } 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 515 728 } 516 729 … … 552 765 // Delete the collection on the server if we're using a remote Greenstone 553 766 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 557 775 // Now delete the collection directory 558 776 return Utility.delete(new File(getCollectionDirectoryPath(collection_name))); … … 591 809 return getLoadedCollectionDirectoryPath() + "archives" + File.separator; 592 810 } 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 593 819 594 820 … … 764 990 command_parts_list.add("-S"); 765 991 } 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 767 1015 command_parts_list.add("-gli"); 768 1016 command_parts_list.add("-language"); … … 808 1056 // If we're using a remote Greenstone server, upload the metadata file 809 1057 if (Gatherer.isGsdlRemote) { 810 RemoteGreenstoneServer.uploadCollectionFile(collection.getName(), metadata_set_file);1058 Gatherer.remoteGreenstoneServer.uploadCollectionFile(collection.getName(), metadata_set_file); 811 1059 } 812 1060 } … … 874 1122 if (Gatherer.isGsdlRemote) { 875 1123 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("")) { 877 1125 return; 878 1126 } … … 959 1207 System.err.println("Cannot write lock file!"); 960 1208 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 } 963 1216 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Cannot_Open_With_Reason", args), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 964 1217 args = null; 965 1218 return; 966 1219 } 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 968 1281 // Open the collection file 969 1282 this.collection = new Collection(collection_file); … … 976 1289 throw(new Exception(Dictionary.get("CollectionManager.Missing_Config"))); // this error message does not agree with the error 977 1290 } 978 1291 1292 if (canDoScheduling()) { 1293 scheduling(); 1294 } 1295 979 1296 MetadataSetManager.clearMetadataSets(); 980 1297 MetadataSetManager.loadMetadataSets(collection_metadata_directory); … … 997 1314 MetadataXMLFileManager.loadMetadataXMLFiles(collection_import_directory,collection.toSkimFile()); 998 1315 999 // Read through the doc.xml files in the archives directory1000 File collection_archives_directory = new File(getLoadedCollectionArchivesDirectoryPath());1316 1317 // get rid of the previous scan through docxml files 1001 1318 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 1003 1331 1004 1332 // Get a list of the collection specific classifiers and plugins … … 1019 1347 // There is obviously no existing collection present. 1020 1348 DebugStream.printStackTrace(error); 1349 error.printStackTrace(); 1021 1350 if(error.getMessage() != null) { 1022 1351 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."; 1025 1355 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Cannot_Open_With_Reason", args), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 1026 1356 } … … 1035 1365 } 1036 1366 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 } 1037 1393 1038 1394 private void makeCollection(String name, String email) … … 1045 1401 } 1046 1402 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 } 1048 1406 1049 1407 command_parts_list.add("-collectdir"); … … 1062 1420 // Run the mkcol.pl command 1063 1421 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 //} 1064 1425 1065 1426 GShell process = new GShell(command_parts, GShell.NEW, COLLECT, this, null, GShell.GSHELL_NEW); … … 1072 1433 */ 1073 1434 public synchronized void message(GShellEvent event) { 1435 1074 1436 } 1075 1437 … … 1123 1485 buildCollection(false); 1124 1486 } 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 } 1125 1495 // If we were running a build, now is when we move files across. 1126 1496 else if(event.getType() == GShell.BUILD && event.getStatus() == GShell.OK) { … … 1159 1529 Gatherer.g_man.repaint(); 1160 1530 } 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 { 1166 1553 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Preview_Ready_Failed"), Dictionary.get("CollectionManager.Preview_Ready_Title"), JOptionPane.ERROR_MESSAGE); 1167 1554 Gatherer.refresh(Gatherer.COLLECTION_REBUILT); … … 1199 1586 } 1200 1587 1588 public void registerScheduleMonitor(GShellProgressMonitor monitor) { 1589 schedule_monitor = monitor; 1590 } 1591 1201 1592 1202 1593 static public void removeCollectionContentsChangedListener(CollectionContentsChangedListener listener) … … 1227 1618 // If we're using a remote Greenstone server, delete the metadata file on the server 1228 1619 if (Gatherer.isGsdlRemote) { 1229 RemoteGreenstoneServer.deleteCollectionFile(collection.getName(), metadata_set_file);1620 Gatherer.remoteGreenstoneServer.deleteCollectionFile(collection.getName(), metadata_set_file); 1230 1621 } 1231 1622 } … … 1317 1708 private boolean installCollection() 1318 1709 { 1710 if (Configuration.fedora_info.isActive()) { 1711 DebugStream.println("Fedora build complete. No need to move files."); 1712 return true; 1713 } 1714 1715 1319 1716 DebugStream.println("Build complete. Moving files."); 1320 1717 … … 1353 1750 1354 1751 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())); 1357 1756 } 1358 1757 -
gli/branches/rtl-gli/src/org/greenstone/gatherer/collection/CollectionTree.java
r13604 r18358 99 99 JLabel tree_cell = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); 100 100 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 106 108 return tree_cell; 107 109 } … … 125 127 private JMenuItem expand_folder = null; 126 128 private JMenuItem explode_metadata_database = null; 129 private JMenuItem replace_srcdoc_with_html = null; 127 130 private JMenuItem delete = null; 128 131 private JMenuItem metaaudit = null; 129 132 private JMenuItem new_folder = null; 130 133 private JMenuItem new_dummy_doc = null; 134 private JMenuItem refresh = null; // for refreshing folder view 131 135 private JMenuItem open_externally = null; 132 136 private JMenuItem rename = null; … … 202 206 } 203 207 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 } 204 240 205 241 private void buildContextMenu(TreePath[] selection_paths) … … 215 251 add(new_dummy_doc); 216 252 253 refresh = new JMenuItem(Dictionary.get("CollectionPopupMenu.Refresh")); 254 refresh.addActionListener(this); 255 add(refresh); 256 217 257 node = (CollectionTreeNode) collection_tree.getModel().getRoot(); 218 258 return; … … 228 268 add(delete); 229 269 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... 231 285 if (selection_paths.length > 1) { 232 286 return; … … 249 303 add(explode_metadata_database); 250 304 } 251 305 252 306 // Replace file 253 307 // !! TO DO: Remote building … … 294 348 /** Called whenever one of the menu items is clicked, this method then causes the appropriate effect. */ 295 349 public void actionPerformed(ActionEvent event) 296 { 297 350 { 351 Object source = event.getSource(); 298 352 299 353 // Collapse folder … … 310 364 else if (source == explode_metadata_database) { 311 365 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 312 376 } 313 377 … … 338 402 } 339 403 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 340 409 // Open in external program 341 410 else if (source == open_externally) { -
gli/branches/rtl-gli/src/org/greenstone/gatherer/collection/CollectionTreeNode.java
r10011 r18358 33 33 import org.greenstone.gatherer.file.FileNode; 34 34 import org.greenstone.gatherer.util.JarTools; 35 import java.util.Set; 36 import java.util.Iterator; 37 import java.nio.charset.Charset; 35 38 36 39 … … 40 43 { 41 44 static final public ImageIcon GREEN_FILE_ICON = JarTools.getImage("greenfile.gif", true); 42 45 43 46 /** Is this file a metadata database that is explodable with the explode_metadata_databases.pl script? */ 44 47 private boolean is_explodable = false; 45 48 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; 46 52 47 53 public CollectionTreeNode(File file) … … 50 56 51 57 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 52 61 } 53 62 … … 66 75 return is_explodable; 67 76 } 77 78 // To work with replace_srcdoc_with_html.pl 79 public boolean isSrcReplaceable() 80 { 81 return is_srcreplaceable; 82 } 68 83 } -
gli/branches/rtl-gli/src/org/greenstone/gatherer/collection/ScriptOptions.java
r13753 r18358 225 225 226 226 if (Gatherer.isGsdlRemote) { 227 String script_output = RemoteGreenstoneServer.getScriptOptions(filename, "");227 String script_output = Gatherer.remoteGreenstoneServer.getScriptOptions(filename, ""); 228 228 document = XMLTools.parseXML(new StringReader(script_output)); 229 229 } … … 247 247 } 248 248 249 249 250 // Create the process. 250 251 Runtime runtime = Runtime.getRuntime(); 251 252 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 252 262 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 } 253 271 } 254 272
Note:
See TracChangeset
for help on using the changeset viewer.