1 | package org.greenstone.gsdl3.action;
|
---|
2 |
|
---|
3 | import org.greenstone.gsdl3.core.ModuleInterface;
|
---|
4 | import org.greenstone.gsdl3.util.*;
|
---|
5 | // XML classes
|
---|
6 | import org.w3c.dom.Node;
|
---|
7 | import org.w3c.dom.NodeList;
|
---|
8 | import org.w3c.dom.Element;
|
---|
9 | import org.w3c.dom.Document;
|
---|
10 |
|
---|
11 | // other java stuff
|
---|
12 | import java.io.File;
|
---|
13 | import java.util.Vector;
|
---|
14 | /** base class for Actions */
|
---|
15 | abstract public class Action {
|
---|
16 |
|
---|
17 | /** the interface setup variables */
|
---|
18 | protected ConfigVars config_=null;
|
---|
19 | /** container Document to create XML Nodes */
|
---|
20 | protected Document doc_=null;
|
---|
21 | /** a converter class to parse XML and create Docs */
|
---|
22 | protected XMLConverter converter_=null;
|
---|
23 | /** a reference to the message router that it must talk to to
|
---|
24 | * get info. it may be a communicator acting as a proxy, but it
|
---|
25 | doesn't care about that */
|
---|
26 | protected ModuleInterface mr_=null;
|
---|
27 |
|
---|
28 | public Action() {
|
---|
29 | converter_ = new XMLConverter();
|
---|
30 | doc_ = converter_.newDOM();
|
---|
31 | }
|
---|
32 | /** gsdl_home_ must be set before configure called */
|
---|
33 | public void setConfigVars(ConfigVars config) {
|
---|
34 | config_ = config;
|
---|
35 | }
|
---|
36 | /** sets the message router */
|
---|
37 | public void setMessageRouter(ModuleInterface m) {
|
---|
38 | mr_ = m;
|
---|
39 | }
|
---|
40 | public void configure() {
|
---|
41 | // does nothing yet
|
---|
42 | }
|
---|
43 |
|
---|
44 | /** process takes an xml representation of cgi args
|
---|
45 | * and returns the page of results - may be in html/xml/other
|
---|
46 | * depending on the output att of the request */
|
---|
47 | public String process(String xml_in) {
|
---|
48 |
|
---|
49 | Element message = converter_.getDOM(xml_in).getDocumentElement();
|
---|
50 |
|
---|
51 | Element result = process(message);
|
---|
52 | return converter_.getString(result);
|
---|
53 | }
|
---|
54 |
|
---|
55 | /** the main process method - must be implemented in subclass */
|
---|
56 | abstract public Element process(Element xml_in);
|
---|
57 |
|
---|
58 | // protected Vector getMetadata(Element format) {
|
---|
59 | // NodeList nodes = format.getElementsByTagName("gsf:metadata");
|
---|
60 | // Vector meta_names = new Vector();
|
---|
61 | // for (int i=0; i<nodes.getLength(); i++) {
|
---|
62 | // meta_names.add(((Element)nodes.item(i)).getAttribute("name"));
|
---|
63 | // }
|
---|
64 | // return meta_names;
|
---|
65 | // }
|
---|
66 | }
|
---|
67 |
|
---|
68 |
|
---|
69 |
|
---|
70 |
|
---|