source: trunk/gsdl3/src/java/org/greenstone/gsdl3/action/Action.java@ 8800

Last change on this file since 8800 was 8675, checked in by kjdon, 20 years ago

metadata in format statements is only in metadata elements now

  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1package org.greenstone.gsdl3.action;
2
3import org.greenstone.gsdl3.core.ModuleInterface;
4import org.greenstone.gsdl3.util.*;
5// XML classes
6import org.w3c.dom.Node;
7import org.w3c.dom.NodeList;
8import org.w3c.dom.Element;
9import org.w3c.dom.Document;
10
11// other java stuff
12import java.io.File;
13import java.util.Vector;
14import java.util.HashMap;
15import java.util.HashSet;
16import java.util.Iterator;
17
18/** base class for Actions */
19abstract 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 void configure() {
45 // does nothing yet
46 }
47
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 */
51 public String process(String xml_in) {
52
53 Element message = this.converter.getDOM(xml_in).getDocumentElement();
54
55 Element result = process(message);
56 return this.converter.getString(result);
57 }
58
59 /** the main process method - must be implemented in subclass */
60 abstract public Element process(Element xml_in);
61
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
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++) {
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")) {
80 metadata.append("all");
81 metadata.append(GSConstants.META_RELATION_SEP);
82 }
83 if (!select.equals("")) {
84 metadata.append(select);
85 metadata.append(GSConstants.META_RELATION_SEP);
86 }
87 if (!sep.equals("")) {
88 metadata.append(GSConstants.META_SEPARATOR_SEP);
89 metadata.append(sep);
90 metadata.append(GSConstants.META_SEPARATOR_SEP);
91 metadata.append(GSConstants.META_RELATION_SEP);
92 }
93
94 metadata.append(name);
95 meta_names.add(metadata.toString());
96 }
97
98 }
99
100 protected Element createMetadataParamList(HashSet metadata_names) {
101 Element param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
102
103 Element param = null;
104 Iterator i = metadata_names.iterator();
105 while (i.hasNext()) {
106 String name = (String)i.next();
107 param = this.doc.createElement(GSXML.PARAM_ELEM);
108 param_list.appendChild(param);
109 param.setAttribute(GSXML.NAME_ATT, "metadata");
110 param.setAttribute(GSXML.VALUE_ATT, name);
111
112 }
113 return param_list;
114 }
115
116}
117
118
119
120
Note: See TracBrowser for help on using the repository browser.