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.Element;
|
---|
8 | import org.w3c.dom.Document;
|
---|
9 |
|
---|
10 | // other java stuff
|
---|
11 | import java.io.File;
|
---|
12 |
|
---|
13 | /** base class for Actions */
|
---|
14 | abstract public class Action {
|
---|
15 |
|
---|
16 | /** the interface setup variables */
|
---|
17 | protected ConfigVars config_=null;
|
---|
18 | /** container Document to create XML Nodes */
|
---|
19 | protected Document doc_=null;
|
---|
20 | /** a converter class to parse XML and create Docs */
|
---|
21 | protected XMLConverter converter_=null;
|
---|
22 | /** cgi args converter */
|
---|
23 | protected GSCGI cgi_ = null;
|
---|
24 | /** a transformer class to transform xml using xslt */
|
---|
25 | protected XMLTransformer transformer_=null;
|
---|
26 | /** a reference to the message router that it must talk to to
|
---|
27 | * get info. it may be a communicator acting as a proxy, but it
|
---|
28 | doesn't care about that */
|
---|
29 | protected ModuleInterface mr_=null;
|
---|
30 |
|
---|
31 | public Action() {
|
---|
32 | converter_ = new XMLConverter();
|
---|
33 | transformer_ = new XMLTransformer();
|
---|
34 | doc_ = converter_.newDOM();
|
---|
35 | }
|
---|
36 | /** gsdl_home_ must be set before configure called */
|
---|
37 | public void setConfigVars(ConfigVars config) {
|
---|
38 | config_ = config;
|
---|
39 | }
|
---|
40 | /** sets the message router */
|
---|
41 | public void setMessageRouter(ModuleInterface m) {
|
---|
42 | mr_ = m;
|
---|
43 | }
|
---|
44 | /** sets the GSCGI object - used to convert between short and long names
|
---|
45 | * of params */
|
---|
46 | public void setCGI(GSCGI cgi) {
|
---|
47 | cgi_ = cgi;
|
---|
48 | // add in any action specific params
|
---|
49 | addCGIParams();
|
---|
50 | }
|
---|
51 | public void configure() {
|
---|
52 | // does nothing yet
|
---|
53 | }
|
---|
54 | /** any action specific cgi params should be added to the GSCGI object-
|
---|
55 | * overwrite this if a new action has its own params
|
---|
56 | * using cgi_.addStaticParam(param-name) */
|
---|
57 | protected void addCGIParams() {
|
---|
58 |
|
---|
59 | }
|
---|
60 | /** process takes an xml representation of cgi args
|
---|
61 | * and returns the page of results - may be in html/xml/other
|
---|
62 | * depending on the output att of the request */
|
---|
63 | public String process(String xml_in) {
|
---|
64 |
|
---|
65 | Element message = converter_.getDOM(xml_in).getDocumentElement();
|
---|
66 |
|
---|
67 | Element result = process(message);
|
---|
68 | return converter_.getString(result);
|
---|
69 | }
|
---|
70 |
|
---|
71 | /** the main process method - must be implemented in subclass */
|
---|
72 | abstract public Element process(Element xml_in);
|
---|
73 |
|
---|
74 | /** locates the format element, transforms it with config_format.xsl, then
|
---|
75 | * returns the transformed element */
|
---|
76 | protected Element getAndTransformFormat(Element format_response) {
|
---|
77 |
|
---|
78 | Element format_elem = (Element)GSXML.getChildByTagName(format_response, GSXML.FORMAT_ELEM);
|
---|
79 | if (format_elem == null) {
|
---|
80 | return null;
|
---|
81 | }
|
---|
82 | // transform it to proper xsl
|
---|
83 | String stylesheet_file = GSFile.stylesheetFile(config_, "config_format.xsl");
|
---|
84 | Document stylesheet = converter_.getDOM(new File(stylesheet_file));
|
---|
85 | Element new_format = (Element)transformer_.transform(stylesheet, format_elem);
|
---|
86 |
|
---|
87 | return new_format;
|
---|
88 |
|
---|
89 | }
|
---|
90 |
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|