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