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

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

added method to find a format element in hte format response, transform it and pass it back

  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 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.Element;
8import org.w3c.dom.Document;
9
10// other java stuff
11import java.io.File;
12
13/** base class for Actions */
14abstract 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 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);
85
86 System.out.println("new format="+converter_.getString(new_format));
87 return new_format;
88
89 }
90
91}
92
93
94
95
Note: See TracBrowser for help on using the repository browser.