- Timestamp:
- 2007-05-03T09:42:34+12:00 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r13820 r14050 193 193 public boolean built() { 194 194 if(collection != null) { 195 // Determine if the collection has been built by looking for the build.cfg file 196 File build_cfg_file = new File(getLoadedCollectionIndexDirectoryPath() + "build.cfg"); 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); 197 198 return build_cfg_file.exists(); 198 199 } … … 252 253 } 253 254 254 255 public void convertToGS3Collection() {256 // Generate the convert_coll_from_gs2.pl command257 ArrayList command_parts_list = new ArrayList();258 if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) {259 command_parts_list.add(Configuration.perl_path);260 command_parts_list.add("-S");261 }262 command_parts_list.add(Configuration.getGS3ScriptPath() + "convert_coll_from_gs2.pl");263 command_parts_list.add("-collectdir");264 command_parts_list.add(getCollectDirectory());265 command_parts_list.add(collection.getName());266 267 // Run the convert_coll_from_gs2.pl command268 String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);269 GShell process = new GShell(command_parts, GShell.CONVERT, COLLECT, this, null, GShell.GSHELL_CONVERT);270 process.addGShellListener(this);271 process.run(); // Don't bother threading this... yet272 273 }255 //This method is no longer used in gs3 since the modification of CollectionConfiguration.java 256 // public void convertToGS3Collection() { 257 // // Generate the convert_coll_from_gs2.pl command 258 // ArrayList command_parts_list = new ArrayList(); 259 // if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) { 260 // command_parts_list.add(Configuration.perl_path); 261 // command_parts_list.add("-S"); 262 // } 263 // command_parts_list.add(Configuration.getGS3ScriptPath() + "convert_coll_from_gs2.pl"); 264 // command_parts_list.add("-collectdir"); 265 // command_parts_list.add(getCollectDirectory()); 266 // command_parts_list.add(collection.getName()); 267 // 268 // // Run the convert_coll_from_gs2.pl command 269 // String[] command_parts = (String[]) command_parts_list.toArray(new String[0]); 270 // GShell process = new GShell(command_parts, GShell.CONVERT, COLLECT, this, null, GShell.GSHELL_CONVERT); 271 // process.addGShellListener(this); 272 // process.run(); // Don't bother threading this... yet 273 // 274 // } 274 275 275 276 /** When basing a new collection on an existing one, we need to copy … … 379 380 if (!new File(collection_directory_path).exists()) { 380 381 // If there is no collection directory then the creation was unsuccessful, or cancelled 381 System.err.println("No collection directory..."); 382 382 383 return; 383 384 } 384 385 385 // Check for the existence of the collect.cfg file 386 File collect_cfg_file = new File(collection_directory_path + "etc" + File.separator + "collect.cfg"); 386 // Check for the existence of the collection configuration file 387 String file_name = ((Gatherer.GS3 == true)? Utility.COLLECTION_CONFIG_XML : Utility.COLLECT_CFG); 388 File collect_cfg_file = new File(collection_directory_path + "etc" + File.separator + file_name); 389 387 390 if (!collect_cfg_file.exists()) { 388 System.err.println("Error: no collect.cfgfile has been created!");391 System.err.println("Error: no " + file_name + " file has been created!"); 389 392 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Cannot_Create_Collection_With_Reason", Dictionary.get("CollectionManager.No_Config_File")), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 390 393 return; … … 449 452 450 453 // Now we update our collect.cfg 451 DebugStream.println("Copy and update collect.cfg from base collection."); 452 updateCollectionCFG(new File(base_collection_directory, Utility.CONFIG_FILE), new File(collection_directory_path, Utility.CONFIG_FILE), description, email, title); 454 DebugStream.println("Copy and update " + file_name + " from base collection."); 455 456 if (Gatherer.GS3 == true) { 457 updateCollectionConfigXML(new File(base_collection_directory, Utility.CONFIG_GS3_FILE), 458 new File(collection_directory_path, Utility.CONFIG_GS3_FILE)); 459 } else { 460 updateCollectionCFG(new File(base_collection_directory, Utility.CONFIG_FILE), 461 new File(collection_directory_path, Utility.CONFIG_FILE), 462 description, email, title); 463 } 453 464 } 454 465 … … 467 478 collection_extra_collectionmeta.setValue(description); 468 479 469 // Now that we have a CDM, update several settings, such as if we created this collection by basing it on another, set it as public automatically 480 // Now that we have a CDM, update several settings, such as if we created this collection by basing it on another, set it as public automatically. This update is done to the internal xml structure which may be saved into collect.cfg or collectionConfig.xml accordingly. 470 481 if (base_collection_directory != null) { 471 482 // Update the creator and maintainer … … 594 605 static public String getLoadedCollectionCfgFilePath() 595 606 { 596 return getLoadedCollectionEtcDirectoryPath() + "collect.cfg"; 607 String path = (Gatherer.GS3 == true)? Utility.COLLECTION_CONFIG_XML : Utility.COLLECT_CFG; 608 return getLoadedCollectionEtcDirectoryPath() + path; 597 609 } 598 610 … … 878 890 // Ensure that the directory exists 879 891 File collection_directory = collection_file.getParentFile(); 892 880 893 if (collection_directory == null || !collection_directory.exists()) { 881 894 // We can't open this … … 884 897 } 885 898 886 File collection_config_file = new File(collection_directory, Utility.CONFIG_FILE); 899 String file_str = (Gatherer.GS3)? Utility.CONFIG_GS3_FILE : Utility.CONFIG_FILE; 900 File collection_config_file = new File(collection_directory, file_str); 887 901 if (!collection_config_file.exists()) { 888 902 System.err.println("CollectionManager.loadCollection: No config file."); … … 1031 1045 command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "mkcol.pl"); 1032 1046 1047 command_parts_list.add((Gatherer.GS3) ? Utility.GS3MODE_ARGUMENT : "");// add '-gs3mode' 1048 1033 1049 command_parts_list.add("-collectdir"); 1034 1050 command_parts_list.add(getCollectDirectory()); 1051 1052 1035 1053 command_parts_list.add("-win31compat"); 1036 1054 command_parts_list.add((Gatherer.isGsdlRemote) ? "false" : "true"); … … 1042 1060 1043 1061 command_parts_list.add(name); 1044 1062 1045 1063 // Run the mkcol.pl command 1046 1064 String[] command_parts = (String[]) command_parts_list.toArray(new String[0]); 1065 1047 1066 GShell process = new GShell(command_parts, GShell.NEW, COLLECT, this, null, GShell.GSHELL_NEW); 1048 1067 process.run(); // Don't bother threading this... yet … … 1114 1133 } 1115 1134 else if (Gatherer.GS3) { 1116 convertToGS3Collection();1135 //xiao comment out this: convertToGS3Collection(); 1117 1136 Gatherer.configGS3Server(Configuration.site_name, ServletConfiguration.ADD_COMMAND + collection.getName()); 1118 1137 } … … 1380 1399 } 1381 1400 1382 1401 private void updateCollectionConfigXML(File base_cfg, File new_cfg) { 1402 //In this method, the files base_cfg and new_cfg are all xml files. 1403 1404 Document base_cfg_doc = XMLTools.parseXMLFile(base_cfg); 1405 XMLTools.writeXMLFile(new_cfg, base_cfg_doc); 1406 Document new_cfg_doc = XMLTools.parseXMLFile(new_cfg); 1407 Element collection_config = new_cfg_doc.getDocumentElement(); 1408 1409 Node browseNode = XMLTools.getChildByTagNameIndexed(collection_config, StaticStrings.BROWSE_STR, 0); 1410 NodeList classifier_children = ((Element)browseNode).getElementsByTagName(StaticStrings.CLASSIFIER_STR); 1411 int num_nodes = classifier_children.getLength(); 1412 1413 if (num_nodes < 1) { 1414 return; 1415 } 1416 1417 // Read in the classifier command watching for hfile, metadata and sort arguments. 1418 String buttonname = null; 1419 String hfile = null; 1420 String metadata = null; 1421 String sort = null; 1422 1423 for (int i=0; i<num_nodes; i++) { 1424 Element classifier_element = (Element)classifier_children.item(i); 1425 NodeList option_children = classifier_element.getElementsByTagName(StaticStrings.OPTION_STR); 1426 for (int j=0; j<option_children.getLength(); j++) { 1427 Element option_element = (Element)option_children.item(j); 1428 String name_str = option_element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 1429 String value_str = option_element.getAttribute(StaticStrings.VALUE_ATTRIBUTE); 1430 1431 if (name_str == null || name_str.equals("")) { 1432 continue; 1433 } 1434 if (name_str != null && value_str == null ) { 1435 value_str = ""; 1436 } 1437 if (name_str.equals("hfile")) { 1438 hfile = value_str; 1439 } 1440 else if (name_str.equals("metadata") && value_str != null) { 1441 String replacement = ProfileXMLFileManager.getMetadataElementFor(value_str); 1442 if (replacement != null && !replacement.equals("")) { 1443 metadata = replacement; 1444 } 1445 } 1446 else if (name_str.equals("sort") && value_str != null) { 1447 String replacement = ProfileXMLFileManager.getMetadataElementFor(value_str); 1448 if (replacement != null && !replacement.equals("")) { 1449 sort = replacement; 1450 } 1451 } 1452 else if(name_str.equals("buttonname") && value_str != null) { 1453 buttonname = value_str; 1454 } 1455 } 1456 } 1457 for (int i=0; i<num_nodes; i++) { 1458 Element classifier_element = (Element)classifier_children.item(i); 1459 NodeList option_children = classifier_element.getElementsByTagName(StaticStrings.OPTION_STR); 1460 for (int j=0; j<option_children.getLength(); j++) { 1461 Element option_element = (Element)option_children.item(j); 1462 String name_str = option_element.getAttribute(StaticStrings.NAME_ATTRIBUTE); 1463 1464 if (name_str.equals("metadata") && metadata != null) { 1465 option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, metadata); 1466 } 1467 else if (name_str.equals("hfile") && hfile != null) { 1468 option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, metadata + ".txt"); 1469 } 1470 else if (name_str.equals("sort") && sort != null) { 1471 option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, sort); 1472 } 1473 else if(name_str.equals("buttonname") && buttonname == "") { 1474 option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, metadata); 1475 } 1476 else if(buttonname == null) { 1477 // No buttonname has been specified. Lets create one using the metadata as its value 1478 Element option = new_cfg_doc.createElement(StaticStrings.OPTION_STR); 1479 option.setAttribute(StaticStrings.NAME_ATTRIBUTE, "buttonname"); 1480 option_element.setAttribute(StaticStrings.VALUE_ATTRIBUTE, metadata); 1481 classifier_element.appendChild(option); 1482 } 1483 } 1484 } 1485 1486 } 1487 1383 1488 private void updateCollectionCFG(File base_cfg, File new_cfg, String description, String email, String title) 1384 1489 {
Note:
See TracChangeset
for help on using the changeset viewer.