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

Last change on this file since 5407 was 5407, checked in by kjdon, 21 years ago

modifed extractMetadataNames so it can find all the different ones, not just parent and ancestor

  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 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 String name = ((Element)nodes.item(i)).getAttribute("name");
74 String select = ((Element)nodes.item(i)).getAttribute("select");
75 if (select.equals("")) {
76 meta_names.add(name);
77 } else if (select.equals("ancestors")) {
78 String separator = ((Element)nodes.item(i)).getAttribute("separator");
79 meta_names.add("ancestors'"+separator+"'_"+name);
80 } else {
81 meta_names.add(select+"_"+name);
82 }
83
84 }
85 }
86
87 protected Element createMetadataParamList(HashSet metadata_names) {
88 Element param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
89
90 Element param = null;
91 Iterator i = metadata_names.iterator();
92 while (i.hasNext()) {
93 String name = (String)i.next();
94 param = this.doc.createElement(GSXML.PARAM_ELEM);
95 param_list.appendChild(param);
96 param.setAttribute(GSXML.NAME_ATT, "metadata");
97 param.setAttribute(GSXML.VALUE_ATT, name);
98
99 }
100 return param_list;
101 }
102
103}
104
105
106
107
Note: See TracBrowser for help on using the repository browser.