Changeset 14050


Ignore:
Timestamp:
05/03/07 09:42:34 (14 years ago)
Author:
xiao
Message:

Changes made to look for collectionConfig.xml in gs3 mode and collect.cfg in gs2 mode, rather than presumably only for the file collect.cfg; Calling convertToGS3Collection method is no longer needed; Add new implementation of method updateCollectionConfigXML when in gs3 mode to update collectionConfig.xml file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r13820 r14050  
    193193    public boolean built() {
    194194    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);
    197198        return build_cfg_file.exists();
    198199    }
     
    252253    }
    253254
    254 
    255     public void convertToGS3Collection() {
    256     // Generate the convert_coll_from_gs2.pl command
    257     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 command
    268     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... yet
    272        
    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//    }
    274275
    275276    /** When basing a new collection on an existing one, we need to copy
     
    379380        if (!new File(collection_directory_path).exists()) {
    380381        // If there is no collection directory then the creation was unsuccessful, or cancelled
    381         System.err.println("No collection directory...");
     382
    382383        return;
    383384        }
    384385
    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
    387390        if (!collect_cfg_file.exists()) {
    388         System.err.println("Error: no collect.cfg file has been created!");
     391        System.err.println("Error: no " + file_name + " file has been created!");
    389392        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);
    390393        return;
     
    449452
    450453        // 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        }
    453464        }
    454465
     
    467478        collection_extra_collectionmeta.setValue(description);
    468479
    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.
    470481        if (base_collection_directory != null) {
    471482        // Update the creator and maintainer
     
    594605    static public String getLoadedCollectionCfgFilePath()
    595606    {
    596     return getLoadedCollectionEtcDirectoryPath() + "collect.cfg";
     607    String path = (Gatherer.GS3 == true)? Utility.COLLECTION_CONFIG_XML : Utility.COLLECT_CFG;
     608    return getLoadedCollectionEtcDirectoryPath() + path;
    597609    }
    598610
     
    878890    // Ensure that the directory exists
    879891    File collection_directory = collection_file.getParentFile();
     892       
    880893    if (collection_directory == null || !collection_directory.exists()) {
    881894        // We can't open this
     
    884897    }
    885898
    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);
    887901    if (!collection_config_file.exists()) {
    888902        System.err.println("CollectionManager.loadCollection: No config file.");
     
    10311045    command_parts_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "mkcol.pl");
    10321046
     1047    command_parts_list.add((Gatherer.GS3) ? Utility.GS3MODE_ARGUMENT : "");// add '-gs3mode'
     1048
    10331049    command_parts_list.add("-collectdir");
    10341050    command_parts_list.add(getCollectDirectory());
     1051
     1052   
    10351053    command_parts_list.add("-win31compat");
    10361054    command_parts_list.add((Gatherer.isGsdlRemote) ? "false" : "true");
     
    10421060
    10431061    command_parts_list.add(name);
    1044 
     1062   
    10451063    // Run the mkcol.pl command
    10461064    String[] command_parts = (String[]) command_parts_list.toArray(new String[0]);
     1065
    10471066    GShell process = new GShell(command_parts, GShell.NEW, COLLECT, this, null, GShell.GSHELL_NEW);
    10481067    process.run(); // Don't bother threading this... yet
     
    11141133        }
    11151134        else if (Gatherer.GS3) {
    1116             convertToGS3Collection();
     1135            //xiao comment out this: convertToGS3Collection();
    11171136            Gatherer.configGS3Server(Configuration.site_name, ServletConfiguration.ADD_COMMAND + collection.getName());
    11181137        } 
     
    13801399    }
    13811400
    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   
    13831488    private void updateCollectionCFG(File base_cfg, File new_cfg, String description, String email, String title)
    13841489    {
Note: See TracChangeset for help on using the changeset viewer.