Revision 5518
Added by ben leinfelder about 14 years ago
lib/metacat.properties.metadata.xml | ||
---|---|---|
21 | 21 |
<name>Data Manager Configuration</name> |
22 | 22 |
<description>Data Manager Configuration Values.</description> |
23 | 23 |
</group> |
24 |
<group> |
|
25 |
<index>5</index> |
|
26 |
<name>Handler Plugin Configuration</name> |
|
27 |
<description>Register Handler Plugin extensions</description> |
|
28 |
</group> |
|
24 | 29 |
|
25 | 30 |
<config> |
26 | 31 |
<key>application.default-style</key> |
... | ... | |
328 | 333 |
</config> |
329 | 334 |
<!-- END Data Manager configuration --> |
330 | 335 |
|
336 |
<!-- handler plugin --> |
|
337 |
<config> |
|
338 |
<key>plugin.handlers</key> |
|
339 |
<label>Plugin class name[s]</label> |
|
340 |
<group>5</group> |
|
341 |
<index>1</index> |
|
342 |
<description>Comma-separated list of fully-qualified class names that implement MetacatHandlerPlugin interface</description> |
|
343 |
<helpFile>properties.html#plugin.handlers</helpFile> |
|
344 |
</config> |
|
345 |
|
|
346 |
|
|
347 |
|
|
331 | 348 |
</metadataConfig> |
lib/metacat.properties | ||
---|---|---|
137 | 137 |
#datamanager.srb.endpoint= |
138 | 138 |
#datamanager.srb.machinename= |
139 | 139 |
|
140 |
######## Plugin section ####################################### |
|
141 |
plugin.handlers= |
|
142 |
|
|
140 | 143 |
######## Authentication and LDAP ############################################## |
141 | 144 |
|
142 | 145 |
auth.class=edu.ucsb.nceas.metacat.AuthLdap |
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
51 | 51 |
import edu.ucsb.nceas.metacat.database.DBConnection; |
52 | 52 |
import edu.ucsb.nceas.metacat.database.DBConnectionPool; |
53 | 53 |
import edu.ucsb.nceas.metacat.database.DatabaseService; |
54 |
import edu.ucsb.nceas.metacat.plugin.MetacatHandlerPlugin; |
|
55 |
import edu.ucsb.nceas.metacat.plugin.MetacatHandlerPluginManager; |
|
54 | 56 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
55 | 57 |
import edu.ucsb.nceas.metacat.properties.SkinPropertyService; |
56 | 58 |
import edu.ucsb.nceas.metacat.replication.ReplicationService; |
... | ... | |
1059 | 1061 |
} |
1060 | 1062 |
|
1061 | 1063 |
} else { |
1062 |
PrintWriter out = response.getWriter(); |
|
1063 |
out.println("<?xml version=\"1.0\"?>"); |
|
1064 |
out.println("<error>"); |
|
1065 |
out.println("Error: action: " + action + " not registered. Please report this error."); |
|
1066 |
out.println("</error>"); |
|
1067 |
out.close(); |
|
1064 |
//try the plugin handler if it has an entry for handling this action |
|
1065 |
MetacatHandlerPlugin handlerPlugin = MetacatHandlerPluginManager.getInstance().getHandler(action); |
|
1066 |
if (handlerPlugin != null) { |
|
1067 |
handlerPlugin.handleAction(action, params, request, response, userName, groupNames, sessionId); |
|
1068 |
} |
|
1069 |
else { |
|
1070 |
PrintWriter out = response.getWriter(); |
|
1071 |
out.println("<?xml version=\"1.0\"?>"); |
|
1072 |
out.println("<error>"); |
|
1073 |
out.println("Error: action: " + action + " not registered. Please report this error."); |
|
1074 |
out.println("</error>"); |
|
1075 |
out.close(); |
|
1076 |
} |
|
1068 | 1077 |
} |
1069 | 1078 |
|
1070 | 1079 |
// Schedule the sitemap generator to run periodically |
src/edu/ucsb/nceas/metacat/plugin/MetacatHandlerPluginManager.java | ||
---|---|---|
1 |
package edu.ucsb.nceas.metacat.plugin; |
|
2 |
|
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
import java.util.Map; |
|
6 |
import java.util.Map.Entry; |
|
7 |
|
|
8 |
import org.apache.commons.logging.Log; |
|
9 |
import org.apache.commons.logging.LogFactory; |
|
10 |
|
|
11 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
|
12 |
import edu.ucsb.nceas.metacat.shared.ServiceException; |
|
13 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
|
14 |
|
|
15 |
public class MetacatHandlerPluginManager { |
|
16 |
|
|
17 |
private static MetacatHandlerPluginManager instance = null; |
|
18 |
|
|
19 |
private static Log log = LogFactory.getLog(MetacatHandlerPluginManager.class); |
|
20 |
|
|
21 |
private List<MetacatHandlerPlugin> handlers= new ArrayList<MetacatHandlerPlugin>(); |
|
22 |
|
|
23 |
private MetacatHandlerPluginManager() { |
|
24 |
|
|
25 |
String[] configuredHandlers = null; |
|
26 |
try { |
|
27 |
String handlersString = PropertyService.getProperty("plugin.handlers"); |
|
28 |
if (handlersString != null && handlersString.length() > 0) { |
|
29 |
configuredHandlers = handlersString.split(","); |
|
30 |
for (String className: configuredHandlers) { |
|
31 |
MetacatHandlerPlugin handlerInstance = null; |
|
32 |
try { |
|
33 |
Class<?> handlerClass = Class.forName(className); |
|
34 |
handlerInstance = (MetacatHandlerPlugin) handlerClass.newInstance(); |
|
35 |
} catch (Exception e) { |
|
36 |
log.error("Problem initializing MetacatHandlerPlugin: " + className, e); |
|
37 |
continue; |
|
38 |
} |
|
39 |
handlers.add(handlerInstance); |
|
40 |
} |
|
41 |
} |
|
42 |
} catch (PropertyNotFoundException e) { |
|
43 |
log.warn("Could not find any MetacatPluginHandlers", e); |
|
44 |
return; |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
public static MetacatHandlerPluginManager getInstance() throws ServiceException { |
|
49 |
if (instance == null) { |
|
50 |
try { |
|
51 |
instance = new MetacatHandlerPluginManager(); |
|
52 |
} catch (Exception e) { |
|
53 |
throw new ServiceException(e.getMessage()); |
|
54 |
} |
|
55 |
} |
|
56 |
return instance; |
|
57 |
} |
|
58 |
|
|
59 |
public void addHandler(MetacatHandlerPlugin plugin) { |
|
60 |
|
|
61 |
} |
|
62 |
|
|
63 |
public MetacatHandlerPlugin getHandler(String action) { |
|
64 |
for (MetacatHandlerPlugin plugin: handlers) { |
|
65 |
if (plugin.handlesAction(action)) { |
|
66 |
return plugin; |
|
67 |
} |
|
68 |
} |
|
69 |
return null; |
|
70 |
} |
|
71 |
} |
|
0 | 72 |
src/edu/ucsb/nceas/metacat/plugin/MetacatHandlerPlugin.java | ||
---|---|---|
1 |
package edu.ucsb.nceas.metacat.plugin; |
|
2 |
|
|
3 |
import java.util.Hashtable; |
|
4 |
|
|
5 |
import javax.servlet.http.HttpServletRequest; |
|
6 |
import javax.servlet.http.HttpServletResponse; |
|
7 |
|
|
8 |
import edu.ucsb.nceas.metacat.shared.HandlerException; |
|
9 |
|
|
10 |
public interface MetacatHandlerPlugin { |
|
11 |
|
|
12 |
public boolean handlesAction(String action); |
|
13 |
|
|
14 |
public boolean handleAction( |
|
15 |
String action, |
|
16 |
Hashtable<String, String[]> params, |
|
17 |
HttpServletRequest request, |
|
18 |
HttpServletResponse response, |
|
19 |
String username, |
|
20 |
String[] groups, |
|
21 |
String sessionId) throws HandlerException; |
|
22 |
|
|
23 |
} |
|
0 | 24 |
Also available in: Unified diff
include MetacatHandlerPlugin interface so that other projects [semtools] can extend the actions handled by Metcat without editing the codebase directly. The SemtoolsPlugin is the prototype for this and can be registered using the Metacat admin interface. Note that the plugin implementation class and supporting jars must be included in the webapp in order for the request to be handled correctly (the semtools build is injecting these as part of it's build process).