[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;
|
---|
[3363] | 7 | import org.w3c.dom.Element;
|
---|
[3340] | 8 | import org.w3c.dom.Document;
|
---|
| 9 |
|
---|
[3935] | 10 | // other java stuff
|
---|
| 11 | import java.io.File;
|
---|
| 12 |
|
---|
[3568] | 13 | /** base class for Actions */
|
---|
[3363] | 14 | abstract public class Action {
|
---|
[3340] | 15 |
|
---|
[3568] | 16 | /** the interface setup variables */
|
---|
[3340] | 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;
|
---|
[3568] | 22 | /** cgi args converter */
|
---|
[3645] | 23 | protected GSCGI cgi_ = null;
|
---|
[3340] | 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 | }
|
---|
[3645] | 44 | /** sets the GSCGI object - used to convert between short and long names
|
---|
| 45 | * of params */
|
---|
| 46 | public void setCGI(GSCGI cgi) {
|
---|
[3363] | 47 | cgi_ = cgi;
|
---|
[3645] | 48 | // add in any action specific params
|
---|
| 49 | addCGIParams();
|
---|
[3363] | 50 | }
|
---|
[3340] | 51 | public void configure() {
|
---|
| 52 | // does nothing yet
|
---|
| 53 | }
|
---|
[3645] | 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 | }
|
---|
[3340] | 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 */
|
---|
[3363] | 63 | public String process(String xml_in) {
|
---|
| 64 |
|
---|
| 65 | Element message = converter_.getDOM(xml_in).getDocumentElement();
|
---|
[3340] | 66 |
|
---|
[3568] | 67 | Element result = process(message);
|
---|
| 68 | return converter_.getString(result);
|
---|
[3363] | 69 | }
|
---|
[3340] | 70 |
|
---|
[3645] | 71 | /** the main process method - must be implemented in subclass */
|
---|
[3568] | 72 | abstract public Element process(Element xml_in);
|
---|
[3893] | 73 |
|
---|
[3935] | 74 | protected Element getAndTransformFormat(Element format_response) {
|
---|
| 75 |
|
---|
| 76 | Element format_elem = (Element)GSXML.getChildByTagName(format_response, GSXML.FORMAT_ELEM);
|
---|
| 77 | if (format_elem == null) {
|
---|
| 78 | return null;
|
---|
| 79 | }
|
---|
| 80 | System.out.println("old format="+converter_.getString(format_elem));
|
---|
| 81 | // transform it to proper xsl
|
---|
| 82 | String stylesheet_file = GSFile.stylesheetFile(config_, "config_format.xsl");
|
---|
| 83 | Document stylesheet = converter_.getDOM(new File(stylesheet_file));
|
---|
| 84 | Element new_format = (Element)transformer_.transform(stylesheet, format_elem);
|
---|
[3911] | 85 |
|
---|
[3935] | 86 | System.out.println("new format="+converter_.getString(new_format));
|
---|
| 87 | return new_format;
|
---|
| 88 |
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[3340] | 91 | }
|
---|
| 92 |
|
---|
[3935] | 93 |
|
---|
| 94 |
|
---|
| 95 |
|
---|