Changeset 12646


Ignore:
Timestamp:
2006-09-01T13:51:34+12:00 (18 years ago)
Author:
mdewsnip
Message:

Support for collection-specific plugins and classifiers with the new code.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
4 edited

Legend:

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

    r12644 r12646  
    436436
    437437    // Get a list of the core Greenstone classifiers and plugins
    438     Classifiers.loadClassifiersList();
    439     Plugins.loadPluginsList();
     438    Classifiers.loadClassifiersList(null);
     439    Plugins.loadPluginsList(null);
    440440    }
    441441
  • trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java

    r12645 r12646  
    5454import org.greenstone.gatherer.cdm.CollectionMetaManager;
    5555import org.greenstone.gatherer.cdm.CommandTokenizer;
     56import org.greenstone.gatherer.greenstone.Classifiers;
     57import org.greenstone.gatherer.greenstone.Plugins;
    5658import org.greenstone.gatherer.gui.LockFileDialog;
    5759import org.greenstone.gatherer.gui.ModalProgressPopup;
     
    953955        DocXMLFileManager.clearDocXMLFiles();
    954956        DocXMLFileManager.loadDocXMLFiles(collection_archives_directory);
     957
     958        // Get a list of the collection specific classifiers and plugins
     959        Classifiers.loadClassifiersList(collection_name);
     960        Plugins.loadPluginsList(collection_name);
    955961
    956962        collection.cdm = new CollectionDesignManager(collection_config_file);
  • trunk/gli/src/org/greenstone/gatherer/greenstone/Classifiers.java

    r12644 r12646  
    4949    // A list of all the classifiers in the core Greenstone "perllib/classify" folder (arguments may not be loaded)
    5050    static private ArrayList core_greenstone_classifiers_list = null;
     51    // The name of the loaded collection
     52    static private String collection_name = null;
     53    // A list of all the classifiers in the loaded collection's "perllib/classify" folder (arguments may not be loaded)
     54    static private ArrayList collection_specific_classifiers_list = null;
    5155
    5256
    5357    static public Classifier getClassifier(String classifier_name, boolean arguments_required)
    5458    {
     59    Classifier classifier = null;
     60    boolean collection_specific = false;
     61
     62    // Check the collection-specific classifiers first
     63    for (int i = 0; i < collection_specific_classifiers_list.size(); i++) {
     64        Classifier collection_specific_classifier = (Classifier) collection_specific_classifiers_list.get(i);
     65        if (collection_specific_classifier.getName().equals(classifier_name)) {
     66        classifier = collection_specific_classifier;
     67        collection_specific = true;
     68        break;
     69        }
     70    }
     71
     72    // Try the core Greenstone classifiers if necessary
     73    if (classifier == null) {
     74        for (int i = 0; i < core_greenstone_classifiers_list.size(); i++) {
     75        Classifier core_greenstone_classifier = (Classifier) core_greenstone_classifiers_list.get(i);
     76        if (core_greenstone_classifier.getName().equals(classifier_name)) {
     77            classifier = core_greenstone_classifier;
     78            break;
     79        }
     80        }
     81    }
     82
     83    // If we've found the classifier, load its arguments now, if required
     84    if (classifier != null && arguments_required) {
     85        if (classifier.getArguments().size() == 0) {
     86        loadClassifierInfo(classifier, collection_specific);
     87        }
     88        else {
     89        DebugStream.println("Already loaded arguments for " + classifier_name + "!");
     90        }
     91    }
     92
     93    return classifier;
     94    }
     95
     96
     97    /** Returns a new list from merging the collection-specific and the core Greenstone classifiers. */
     98    static public ArrayList getClassifiersList()
     99    {
     100    ArrayList classifiers_list = new ArrayList();
     101    classifiers_list.addAll(collection_specific_classifiers_list);
     102
     103    // Add in the core Greenstone classifiers, taking care not to overwrite any collection-specific ones
    55104    for (int i = 0; i < core_greenstone_classifiers_list.size(); i++) {
    56         Classifier classifier = (Classifier) core_greenstone_classifiers_list.get(i);
    57         if (classifier.getName().equals(classifier_name)) {
    58         if (arguments_required) {
    59             if (classifier.getArguments().size() == 0) {
    60             loadClassifierInfo(classifier);
    61             }
    62             else {
    63             DebugStream.println("Already loaded arguments for " + classifier_name + "!");
    64             }
    65         }
    66         return classifier;
    67         }
    68     }
    69 
    70     return null;
    71     }
    72 
    73 
    74     static public ArrayList getClassifiersList()
    75     {
    76     return core_greenstone_classifiers_list;
    77     }
    78 
    79 
    80     static private void loadClassifierInfo(Classifier classifier)
     105        Classifier core_greenstone_classifier = (Classifier) core_greenstone_classifiers_list.get(i);
     106
     107        boolean found = false;
     108        for (int j = 0; j < collection_specific_classifiers_list.size(); j++) {
     109        Classifier collection_specific_classifier = (Classifier) collection_specific_classifiers_list.get(j);
     110        if (core_greenstone_classifier.getName().equals(collection_specific_classifier.getName())) {
     111            found = true;
     112            break;
     113        }
     114        }
     115
     116        if (!found) {
     117        classifiers_list.add(core_greenstone_classifier);
     118        }
     119    }
     120
     121    return classifiers_list;
     122    }
     123
     124
     125    static private void loadClassifierInfo(Classifier classifier, boolean collection_specific)
    81126    {
    82127    DebugStream.println("Loading arguments for " + classifier.getName() + "...");
     
    96141        }
    97142        args.add(LocalGreenstone.getBinScriptDirectoryPath() + "classinfo.pl");
     143        if (collection_specific) {
     144            args.add("-collection");
     145            args.add(collection_name);
     146        }
    98147        args.add("-xml");
    99148        args.add("-language");
     
    108157        }
    109158
    110         if (xml.length() > 0) {
    111         parseClassifierInfoXML(classifier, xml.toString());
    112         }
    113         else {
     159        // Check the XML output was obtained successfully
     160        if (xml == null || xml.length() == 0) {
    114161        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.ClassifierManager.Classifier_XML_Parse_Failed", classifier.getName()), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    115         }
     162        return;
     163        }
     164
     165        parseClassifierInfoXML(classifier, xml.toString());
    116166    }
    117167    catch (Exception exception) {
     
    121171
    122172
    123     static public void loadClassifiersList()
     173    static public void loadClassifiersList(String collection_name_arg)
    124174    {
    125175    DebugStream.println("In loadClassifiersList()...");
     176
     177    // If we're getting the collection-specific classifiers, clear the old list no matter what
     178    if (collection_name_arg != null) {
     179        collection_name = collection_name_arg;
     180        collection_specific_classifiers_list = new ArrayList();
     181    }
    126182
    127183    // Run classifierfo.pl to get the list of classifiers
     
    139195        }
    140196        args.add(LocalGreenstone.getBinScriptDirectoryPath() + "classinfo.pl");
     197        if (collection_name != null) {
     198            args.add("-collection");
     199            args.add(collection_name);
     200        }
    141201        args.add("-listall");
    142202        args.add("-xml");
     
    149209        }
    150210
    151         if (xml.length() > 0) {
     211        // Check the XML output was obtained successfully
     212        if (xml == null || xml.length() == 0) {
     213        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.ClassifierManager.Classifier_List_XML_Parse_Failed"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     214        return;
     215        }
     216
     217        if (collection_name != null) {
     218        collection_specific_classifiers_list = parseClassifiersListXML(xml.toString());
     219        }
     220        else {
    152221        core_greenstone_classifiers_list = parseClassifiersListXML(xml.toString());
    153         }
    154         else {
    155         JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.ClassifierManager.Classifier_List_XML_Parse_Failed"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    156222        }
    157223    }
  • trunk/gli/src/org/greenstone/gatherer/greenstone/Plugins.java

    r12642 r12646  
    5050    // A list of all the plugins in the core Greenstone "perllib/plugins" folder (arguments may not be loaded)
    5151    static private ArrayList core_greenstone_plugins_list = null;
     52    // The name of the loaded collection
     53    static private String collection_name = null;
     54    // A list of all the plugins in the loaded collection's "perllib/plugins" folder (arguments may not be loaded)
     55    static private ArrayList collection_specific_plugins_list = null;
    5256
    5357
    5458    static public Plugin getPlugin(String plugin_name, boolean arguments_required)
    5559    {
     60    Plugin plugin = null;
     61    boolean collection_specific = false;
     62
     63    // Check the collection-specific plugins first
     64    for (int i = 0; i < collection_specific_plugins_list.size(); i++) {
     65        Plugin collection_specific_plugin = (Plugin) collection_specific_plugins_list.get(i);
     66        if (collection_specific_plugin.getName().equals(plugin_name)) {
     67        plugin = collection_specific_plugin;
     68        collection_specific = true;
     69        break;
     70        }
     71    }
     72
     73    // Try the core Greenstone plugins if necessary
     74    if (plugin == null) {
     75        for (int i = 0; i < core_greenstone_plugins_list.size(); i++) {
     76        Plugin core_greenstone_plugin = (Plugin) core_greenstone_plugins_list.get(i);
     77        if (core_greenstone_plugin.getName().equals(plugin_name)) {
     78            plugin = core_greenstone_plugin;
     79            break;
     80        }
     81        }
     82    }
     83
     84    // If we've found the plugin, load its arguments now, if required
     85    if (plugin != null && arguments_required) {
     86        if (plugin.getArguments().size() == 0) {
     87        loadPluginInfo(plugin, collection_specific);
     88        }
     89        else {
     90        DebugStream.println("Already loaded arguments for " + plugin_name + "!");
     91        }
     92    }
     93
     94    return plugin;
     95    }
     96
     97
     98    /** Returns a new list from merging the collection-specific and the core Greenstone plugins. */
     99    static public ArrayList getPluginsList()
     100    {
     101    ArrayList plugins_list = new ArrayList();
     102    plugins_list.addAll(collection_specific_plugins_list);
     103
     104    // Add in the core Greenstone plugins, taking care not to overwrite any collection-specific ones
    56105    for (int i = 0; i < core_greenstone_plugins_list.size(); i++) {
    57         Plugin plugin = (Plugin) core_greenstone_plugins_list.get(i);
    58         if (plugin.getName().equals(plugin_name)) {
    59         if (arguments_required) {
    60             if (plugin.getArguments().size() == 0) {
    61             loadPluginInfo(plugin);
    62             }
    63             else {
    64             DebugStream.println("Already loaded arguments for " + plugin_name + "!");
    65             }
    66         }
    67         return plugin;
    68         }
    69     }
    70 
    71     return null;
    72     }
    73 
    74 
    75     static public ArrayList getPluginsList()
    76     {
    77     return core_greenstone_plugins_list;
    78     }
    79 
    80 
    81     static private void loadPluginInfo(Plugin plugin)
     106        Plugin core_greenstone_plugin = (Plugin) core_greenstone_plugins_list.get(i);
     107
     108        boolean found = false;
     109        for (int j = 0; j < collection_specific_plugins_list.size(); j++) {
     110        Plugin collection_specific_plugin = (Plugin) collection_specific_plugins_list.get(j);
     111        if (core_greenstone_plugin.getName().equals(collection_specific_plugin.getName())) {
     112            found = true;
     113            break;
     114        }
     115        }
     116
     117        if (!found) {
     118        plugins_list.add(core_greenstone_plugin);
     119        }
     120    }
     121
     122    return plugins_list;
     123    }
     124
     125
     126    static private void loadPluginInfo(Plugin plugin, boolean collection_specific)
    82127    {
    83128    DebugStream.println("Loading arguments for " + plugin.getName() + "...");
     
    97142        }
    98143        args.add(LocalGreenstone.getBinScriptDirectoryPath() + "pluginfo.pl");
     144        if (collection_specific) {
     145            args.add("-collection");
     146            args.add(collection_name);
     147        }
    99148        args.add("-xml");
    100149        args.add("-language");
     
    109158        }
    110159
    111         if (xml.length() > 0) {
    112         parsePluginInfoXML(plugin, xml.toString());
    113         }
    114         else {
     160        // Check the XML output was obtained successfully
     161        if (xml == null || xml.length() == 0) {
    115162        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.PlugInManager.PlugIn_XML_Parse_Failed", plugin.getName()), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    116         }
     163        return;
     164        }
     165
     166        parsePluginInfoXML(plugin, xml.toString());
    117167    }
    118168    catch (Exception exception) {
     
    122172
    123173
    124     static public void loadPluginsList()
     174    static public void loadPluginsList(String collection_name_arg)
    125175    {
    126176    DebugStream.println("In loadPluginsList()...");
     177
     178    // If we're getting the collection-specific plugins, clear the old list no matter what
     179    if (collection_name_arg != null) {
     180        collection_name = collection_name_arg;
     181        collection_specific_plugins_list = new ArrayList();
     182    }
    127183
    128184    // Run pluginfo.pl to get the list of plugins
     
    140196        }
    141197        args.add(LocalGreenstone.getBinScriptDirectoryPath() + "pluginfo.pl");
     198        if (collection_name != null) {
     199            args.add("-collection");
     200            args.add(collection_name);
     201        }
    142202        args.add("-listall");
    143203        args.add("-xml");
     
    150210        }
    151211
    152         if (xml.length() > 0) {
     212        // Check the XML output was obtained successfully
     213        if (xml == null || xml.length() == 0) {
     214        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.PluginManager.Plugin_List_XML_Parse_Failed"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
     215        return;
     216        }
     217
     218        if (collection_name != null) {
     219        collection_specific_plugins_list = parsePluginsListXML(xml.toString());
     220        }
     221        else {
    153222        core_greenstone_plugins_list = parsePluginsListXML(xml.toString());
    154223        }
    155         else {
    156         JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.PluginManager.Plugin_List_XML_Parse_Failed"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    157         }
    158224    }
    159225    catch (Exception exception) {
    160         DebugStream.println("Failed when trying to list plugins.");
    161226        DebugStream.printStackTrace(exception);
    162227    }
Note: See TracChangeset for help on using the changeset viewer.