Changeset 12642


Ignore:
Timestamp:
2006-09-01T11:55:59+12:00 (18 years ago)
Author:
mdewsnip
Message:

Moved the new plugins stuff out into a new static class (greenstone.Plugins) in preparation for extending it to do collection-specific plugins.

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
2 added
3 edited

Legend:

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

    r12636 r12642  
    3939import org.greenstone.gatherer.GAuthenticator;
    4040import org.greenstone.gatherer.cdm.ClassifierManager;
    41 import org.greenstone.gatherer.cdm.PluginManager;
    4241import org.greenstone.gatherer.collection.CollectionManager;
    4342import org.greenstone.gatherer.feedback.ActionRecorderDialog;
     
    4544import org.greenstone.gatherer.file.FileAssociationManager;
    4645import org.greenstone.gatherer.file.RecycleBin;
     46import org.greenstone.gatherer.greenstone.Plugins;
    4747import org.greenstone.gatherer.gui.GUIManager;
    4848import org.greenstone.gatherer.gui.URLField;
     
    437437    // Get a list of the core Greenstone classifiers and plugins
    438438    ClassifierManager.loadClassifiersList();
    439     PluginManager.loadPluginsList();
     439    Plugins.loadPluginsList();
    440440    }
    441441
  • trunk/gli/src/org/greenstone/gatherer/cdm/Plugin.java

    r12637 r12642  
    3030import java.util.*;
    3131import org.greenstone.gatherer.DebugStream;
     32import org.greenstone.gatherer.greenstone.Plugins;
    3233import org.greenstone.gatherer.util.StaticStrings;
    3334import org.w3c.dom.*;
     
    7172    String plugin_name = element.getAttribute(StaticStrings.TYPE_ATTRIBUTE);
    7273    // Determine the base plugin from the plugin name
    73     Plugin base_plugin = PluginManager.getPlugin(plugin_name, true);
     74    Plugin base_plugin = Plugins.getPlugin(plugin_name, true);
    7475    Plugin plugin = new Plugin(element, base_plugin);
    7576    if (base_plugin == null) {
     
    8586    public boolean doesExplodeMetadataDatabases()
    8687    {
    87     Plugin base_plugin = PluginManager.getPlugin(getName(), false);
     88    Plugin base_plugin = Plugins.getPlugin(getName(), false);
    8889    if (base_plugin == null) {
    8990        return false;
  • trunk/gli/src/org/greenstone/gatherer/cdm/PluginManager.java

    r12641 r12642  
    4343import org.greenstone.gatherer.LocalGreenstone;
    4444import org.greenstone.gatherer.collection.CollectionContentsChangedListener;
     45import org.greenstone.gatherer.greenstone.Plugins;
    4546import org.greenstone.gatherer.gui.DesignPaneHeader;
    4647import org.greenstone.gatherer.gui.GComboBox;
     
    6263    implements CollectionContentsChangedListener
    6364{
    64     // A list of all the plugins in the core Greenstone "perllib/plugins" folder (arguments may not be loaded)
    65     static private ArrayList core_greenstone_plugins_list = null;
    66 
    6765    /** When asking how many rows are in the model, and if this variables value is true, then this modifier alters the number returned. This funtionality is used to hide the last three rows of the list in low detail modes. */
    6866    private boolean modify_row_count = false;
     
    9290
    9391
    94     // --------------------------------------------------------------------------------------------------------
    95 
    96 
    9792    /** Retrieve a list of the plugins that are available to be added to the collection. */
    9893    private Object[] getAvailablePlugins()
     
    10196
    10297    // Add all the non-abstract core Greenstone plugins, except for ArcPlug and RecPlug
    103     for (int i = 0; i < core_greenstone_plugins_list.size(); i++) {
    104         Plugin plugin = (Plugin) core_greenstone_plugins_list.get(i);
     98    ArrayList plugins_list = Plugins.getPluginsList();
     99    for (int i = 0; i < plugins_list.size(); i++) {
     100        Plugin plugin = (Plugin) plugins_list.get(i);
    105101        if (!plugin.isAbstract()) {
    106102        String plugin_name = plugin.getName();
     
    126122    {
    127123    ArrayList exploder_plugins = new ArrayList();
    128     for (int i = 0; i < core_greenstone_plugins_list.size(); i++) {
    129         Plugin plugin = (Plugin) core_greenstone_plugins_list.get(i);
     124    ArrayList plugins_list = Plugins.getPluginsList();
     125    for (int i = 0; i < plugins_list.size(); i++) {
     126        Plugin plugin = (Plugin) plugins_list.get(i);
    130127        if (plugin.doesExplodeMetadataDatabases() == true && plugin.doesProcessFile(file)) {
    131128        exploder_plugins.add(plugin);
     
    134131
    135132    return exploder_plugins;   
    136     }
    137 
    138 
    139     static public Plugin getPlugin(String plugin_name, boolean arguments_required)
    140     {
    141     for (int i = 0; i < core_greenstone_plugins_list.size(); i++) {
    142         Plugin plugin = (Plugin) core_greenstone_plugins_list.get(i);
    143         if (plugin.getName().equals(plugin_name)) {
    144         if (arguments_required) {
    145             if (plugin.getArguments().size() == 0) {
    146             loadPluginInfo(plugin);
    147             }
    148             else {
    149             DebugStream.println("Already loaded arguments for " + plugin_name + "!");
    150             }
    151         }
    152         return plugin;
    153         }
    154     }
    155 
    156     return null;
    157133    }
    158134
     
    160136    public boolean isFileExplodable(File file)
    161137    {
    162     for (int i = 0; i < core_greenstone_plugins_list.size(); i++) {
    163         Plugin plugin = (Plugin) core_greenstone_plugins_list.get(i);
     138    ArrayList plugins_list = Plugins.getPluginsList();
     139    for (int i = 0; i < plugins_list.size(); i++) {
     140        Plugin plugin = (Plugin) plugins_list.get(i);
    164141        if (plugin.doesExplodeMetadataDatabases() == true && plugin.doesProcessFile(file) == true) {
    165142        return true;
     
    169146    return false;
    170147    }
    171 
    172 
    173     static private void loadPluginInfo(Plugin plugin)
    174     {
    175     DebugStream.println("Loading arguments for " + plugin.getName() + "...");
    176 
    177     // Run pluginfo.pl to get the list of plugins
    178     try {
    179         StringBuffer xml = null;
    180         if (Gatherer.isGsdlRemote) {
    181         String pluginfo_output = RemoteGreenstoneServer.getScriptOptions("pluginfo.pl", "&plugin=" + plugin);
    182         xml = new StringBuffer(pluginfo_output);
    183         }
    184         else {
    185         ArrayList args = new ArrayList();
    186         if (Utility.isWindows()) {
    187             args.add(Configuration.perl_path);
    188             args.add("-S");
    189         }
    190         args.add(LocalGreenstone.getBinScriptDirectoryPath() + "pluginfo.pl");
    191         args.add("-xml");
    192         args.add("-language");
    193         args.add(Configuration.getLanguage());
    194         args.add(plugin.getName());
    195 
    196         // Run the pluginfo.pl process
    197         Runtime runtime = Runtime.getRuntime();
    198         Process process = runtime.exec((String[]) args.toArray(new String[] { }));
    199         InputStream input_stream = process.getErrorStream();
    200         xml = XMLTools.readXMLStream(input_stream);
    201         }
    202 
    203         if (xml.length() > 0) {
    204         parsePluginInfoXML(plugin, xml.toString());
    205         }
    206         else {
    207         JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.PlugInManager.PlugIn_XML_Parse_Failed", plugin.getName()), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    208         }
    209     }
    210     catch (Exception exception) {
    211         DebugStream.printStackTrace(exception);
    212     }
    213     }
    214 
    215 
    216     static public void loadPluginsList()
    217     {
    218     DebugStream.println("In loadPluginsList()...");
    219 
    220     // Run pluginfo.pl to get the list of plugins
    221     try {
    222         StringBuffer xml = null;
    223         if (Gatherer.isGsdlRemote) {
    224         String pluginfo_output = RemoteGreenstoneServer.getScriptOptions("pluginfo.pl", "&listall");
    225         xml = new StringBuffer(pluginfo_output);
    226         }
    227         else {
    228         ArrayList args = new ArrayList();
    229         if (Utility.isWindows()) {
    230             args.add(Configuration.perl_path);
    231             args.add("-S");
    232         }
    233         args.add(LocalGreenstone.getBinScriptDirectoryPath() + "pluginfo.pl");
    234         args.add("-listall");
    235         args.add("-xml");
    236 
    237         // Run the pluginfo.pl process
    238         Runtime runtime = Runtime.getRuntime();
    239         Process process = runtime.exec((String[]) args.toArray(new String[] { }));
    240         InputStream input_stream = process.getErrorStream();
    241         xml = XMLTools.readXMLStream(input_stream);
    242         }
    243 
    244         if (xml.length() > 0) {
    245         core_greenstone_plugins_list = parsePluginsListXML(xml.toString());
    246         }
    247         else {
    248         JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CDM.PluginManager.Plugin_List_XML_Parse_Failed"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
    249         }
    250     }
    251     catch (Exception exception) {
    252         DebugStream.println("Failed when trying to list plugins.");
    253         DebugStream.printStackTrace(exception);
    254     }
    255     }
    256 
    257 
    258     static private void parsePluginInfoXML(Plugin plugin, String xml)
    259     {
    260     Document document = XMLTools.parseXML(new StringReader(xml));
    261     parsePluginInfoXMLNode(plugin, document.getDocumentElement());
    262     }
    263 
    264 
    265     static private void parsePluginInfoXMLNode(Plugin plugin, Node root_node)
    266     {
    267     for (Node node = root_node.getFirstChild(); node != null; node = node.getNextSibling()) {
    268         String node_name = node.getNodeName();
    269 
    270         if (node_name.equalsIgnoreCase("Name")) {
    271         plugin.setName(XMLTools.getValue(node));
    272         }
    273         else if (node_name.equals("Desc")) {
    274         plugin.setDescription(XMLTools.getValue(node));
    275         }
    276         else if (node_name.equals("Abstract")) {
    277         plugin.setIsAbstract(XMLTools.getValue(node).equalsIgnoreCase(StaticStrings.YES_STR));
    278         }
    279         else if (node_name.equalsIgnoreCase("Explodes")) {
    280         plugin.setDoesExplodeMetadataDatabases(XMLTools.getValue(node).equalsIgnoreCase(StaticStrings.YES_STR));
    281         }
    282         else if (node_name.equalsIgnoreCase("Processes")) {
    283         plugin.setDefaultProcessExpression(XMLTools.getValue(node));
    284         }
    285         else if (node_name.equalsIgnoreCase("Blocks")) {
    286         plugin.setDefaultBlockExpression(XMLTools.getValue(node));
    287         }
    288         // Parse the plugin arguments
    289         else if (node_name.equalsIgnoreCase("Arguments")) {
    290         for (Node argument_node = node.getFirstChild(); argument_node != null; argument_node = argument_node.getNextSibling()) {
    291             // An option
    292             if (argument_node.getNodeName().equalsIgnoreCase("Option")) {
    293             Argument argument = new Argument();
    294             argument.parseXML((Element) argument_node);
    295             plugin.addArgument(argument);
    296             }
    297         }
    298         }
    299         // A super plugin class
    300         else if (node_name.equalsIgnoreCase("PlugInfo")) {
    301         Plugin super_plugin = new Plugin();
    302         parsePluginInfoXMLNode(super_plugin, node);
    303         plugin.setSuper(super_plugin);
    304         }
    305     }
    306     }
    307 
    308 
    309     static private ArrayList parsePluginsListXML(String xml)
    310     {
    311     ArrayList plugins_list = new ArrayList();
    312 
    313     Document document = XMLTools.parseXML(new StringReader(xml));
    314     Node root = document.getDocumentElement();
    315     for (Node node = root.getFirstChild(); node != null; node = node.getNextSibling()) {
    316         String node_name = node.getNodeName();
    317 
    318         if (node_name.equals("PlugInfo")) {
    319         Plugin plugin = new Plugin();
    320         parsePluginInfoXMLNode(plugin, node);
    321         plugins_list.add(plugin);
    322         }
    323     }
    324 
    325     return plugins_list;
    326     }
    327 
    328 
    329     // --------------------------------------------------------------------------------------------------------
    330148
    331149
     
    763581        {
    764582        // Retrieve the plugin
    765         Plugin plugin = getPlugin(plugin_name, true);
     583        Plugin plugin = Plugins.getPlugin(plugin_name, true);
    766584        if (plugin == null) {
    767585            System.err.println("Error: getPlugin() returned null.");
     
    1130948    {
    1131949        // Retrieve the plugin
    1132         Plugin plugin = getPlugin(plugin_name, true);
     950        Plugin plugin = Plugins.getPlugin(plugin_name, true);
    1133951        if (plugin == null) {
    1134952        System.err.println("Error: getPlugin() returned null.");
Note: See TracChangeset for help on using the changeset viewer.