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 | import java.util.HashMap;
|
---|
15 | import java.util.HashSet;
|
---|
16 | import java.util.Iterator;
|
---|
17 |
|
---|
18 | /** base class for Actions */
|
---|
19 | abstract public class Action {
|
---|
20 |
|
---|
21 | /** the system set up variables */
|
---|
22 | protected HashMap config_params = null;
|
---|
23 | /** container Document to create XML Nodes */
|
---|
24 | protected Document doc=null;
|
---|
25 | /** a converter class to parse XML and create Docs */
|
---|
26 | protected XMLConverter converter=null;
|
---|
27 | /** a reference to the message router that it must talk to to
|
---|
28 | * get info. it may be a communicator acting as a proxy, but it
|
---|
29 | doesn't care about that */
|
---|
30 | protected ModuleInterface mr=null;
|
---|
31 |
|
---|
32 | public Action() {
|
---|
33 | this.converter = new XMLConverter();
|
---|
34 | this.doc = this.converter.newDOM();
|
---|
35 | }
|
---|
36 | /** the config variables must be set before configure is called */
|
---|
37 | public void setConfigParams(HashMap params) {
|
---|
38 | this.config_params = params;
|
---|
39 | }
|
---|
40 | /** sets the message router */
|
---|
41 | public void setMessageRouter(ModuleInterface m) {
|
---|
42 | this.mr = m;
|
---|
43 | }
|
---|
44 | public boolean configure() {
|
---|
45 | // does nothing yet
|
---|
46 | return true;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /** process takes an xml representation of cgi args
|
---|
50 | * and returns the page of results - may be in html/xml/other
|
---|
51 | * depending on the output att of the request */
|
---|
52 | public String process(String xml_in) {
|
---|
53 |
|
---|
54 | Element message = this.converter.getDOM(xml_in).getDocumentElement();
|
---|
55 |
|
---|
56 | Element result = process(message);
|
---|
57 | return this.converter.getString(result);
|
---|
58 | }
|
---|
59 |
|
---|
60 | /** the main process method - must be implemented in subclass */
|
---|
61 | abstract public Element process(Element xml_in);
|
---|
62 |
|
---|
63 | /** tell the param class what its arguments are
|
---|
64 | * if an action has its own arguments, this should add them to the params
|
---|
65 | * object - particularly important for args that should not be saved */
|
---|
66 | public boolean getActionParameters(GSParams params) {
|
---|
67 | return true;
|
---|
68 | }
|
---|
69 |
|
---|
70 | protected void extractMetadataNames(Element format, HashSet meta_names) {
|
---|
71 | //NodeList nodes = format.getElementsByTagNameNS("metadata", "http://www.greenstone.org/configformat");
|
---|
72 | NodeList nodes = format.getElementsByTagName("gsf:metadata");
|
---|
73 | for (int i=0; i<nodes.getLength(); i++) {
|
---|
74 | Element elem = (Element)nodes.item(i);
|
---|
75 | StringBuffer metadata = new StringBuffer();
|
---|
76 | String all = elem.getAttribute("multiple");
|
---|
77 | String name = elem.getAttribute("name");
|
---|
78 | String select = elem.getAttribute("select");
|
---|
79 | String sep = elem.getAttribute("separator");
|
---|
80 | if (all.equals("true")) {
|
---|
81 | metadata.append("all");
|
---|
82 | metadata.append(GSConstants.META_RELATION_SEP);
|
---|
83 | }
|
---|
84 | if (!select.equals("")) {
|
---|
85 | metadata.append(select);
|
---|
86 | metadata.append(GSConstants.META_RELATION_SEP);
|
---|
87 | }
|
---|
88 | if (!sep.equals("")) {
|
---|
89 | metadata.append(GSConstants.META_SEPARATOR_SEP);
|
---|
90 | metadata.append(sep);
|
---|
91 | metadata.append(GSConstants.META_SEPARATOR_SEP);
|
---|
92 | metadata.append(GSConstants.META_RELATION_SEP);
|
---|
93 | }
|
---|
94 |
|
---|
95 | metadata.append(name);
|
---|
96 | meta_names.add(metadata.toString());
|
---|
97 | }
|
---|
98 |
|
---|
99 | }
|
---|
100 |
|
---|
101 | protected Element createMetadataParamList(HashSet metadata_names) {
|
---|
102 | Element param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
|
---|
103 |
|
---|
104 | Element param = null;
|
---|
105 | Iterator i = metadata_names.iterator();
|
---|
106 | while (i.hasNext()) {
|
---|
107 | String name = (String)i.next();
|
---|
108 | param = this.doc.createElement(GSXML.PARAM_ELEM);
|
---|
109 | param_list.appendChild(param);
|
---|
110 | param.setAttribute(GSXML.NAME_ATT, "metadata");
|
---|
111 | param.setAttribute(GSXML.VALUE_ATT, name);
|
---|
112 |
|
---|
113 | }
|
---|
114 | return param_list;
|
---|
115 | }
|
---|
116 |
|
---|
117 | }
|
---|
118 |
|
---|
119 |
|
---|
120 |
|
---|
121 |
|
---|