- Timestamp:
- 2006-09-01T13:51:34+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/greenstone/Plugins.java
r12642 r12646 50 50 // A list of all the plugins in the core Greenstone "perllib/plugins" folder (arguments may not be loaded) 51 51 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; 52 56 53 57 54 58 static public Plugin getPlugin(String plugin_name, boolean arguments_required) 55 59 { 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 56 105 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) 82 127 { 83 128 DebugStream.println("Loading arguments for " + plugin.getName() + "..."); … … 97 142 } 98 143 args.add(LocalGreenstone.getBinScriptDirectoryPath() + "pluginfo.pl"); 144 if (collection_specific) { 145 args.add("-collection"); 146 args.add(collection_name); 147 } 99 148 args.add("-xml"); 100 149 args.add("-language"); … … 109 158 } 110 159 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) { 115 162 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()); 117 167 } 118 168 catch (Exception exception) { … … 122 172 123 173 124 static public void loadPluginsList( )174 static public void loadPluginsList(String collection_name_arg) 125 175 { 126 176 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 } 127 183 128 184 // Run pluginfo.pl to get the list of plugins … … 140 196 } 141 197 args.add(LocalGreenstone.getBinScriptDirectoryPath() + "pluginfo.pl"); 198 if (collection_name != null) { 199 args.add("-collection"); 200 args.add(collection_name); 201 } 142 202 args.add("-listall"); 143 203 args.add("-xml"); … … 150 210 } 151 211 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 { 153 222 core_greenstone_plugins_list = parsePluginsListXML(xml.toString()); 154 223 } 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 }158 224 } 159 225 catch (Exception exception) { 160 DebugStream.println("Failed when trying to list plugins.");161 226 DebugStream.printStackTrace(exception); 162 227 }
Note:
See TracChangeset
for help on using the changeset viewer.