package org.greenstone.gsdl3.action; import org.greenstone.gsdl3.core.ModuleInterface; import org.greenstone.gsdl3.util.*; // XML classes import org.w3c.dom.Node; import org.w3c.dom.Element; import org.w3c.dom.Document; // other java stuff import java.io.File; /** base class for Actions */ abstract public class Action { /** the interface setup variables */ protected ConfigVars config_=null; /** container Document to create XML Nodes */ protected Document doc_=null; /** a converter class to parse XML and create Docs */ protected XMLConverter converter_=null; /** cgi args converter */ protected GSCGI cgi_ = null; /** a transformer class to transform xml using xslt */ protected XMLTransformer transformer_=null; /** a reference to the message router that it must talk to to * get info. it may be a communicator acting as a proxy, but it doesn't care about that */ protected ModuleInterface mr_=null; public Action() { converter_ = new XMLConverter(); transformer_ = new XMLTransformer(); doc_ = converter_.newDOM(); } /** gsdl_home_ must be set before configure called */ public void setConfigVars(ConfigVars config) { config_ = config; } /** sets the message router */ public void setMessageRouter(ModuleInterface m) { mr_ = m; } /** sets the GSCGI object - used to convert between short and long names * of params */ public void setCGI(GSCGI cgi) { cgi_ = cgi; // add in any action specific params addCGIParams(); } public void configure() { // does nothing yet } /** any action specific cgi params should be added to the GSCGI object- * overwrite this if a new action has its own params * using cgi_.addStaticParam(param-name) */ protected void addCGIParams() { } /** process takes an xml representation of cgi args * and returns the page of results - may be in html/xml/other * depending on the output att of the request */ public String process(String xml_in) { Element message = converter_.getDOM(xml_in).getDocumentElement(); Element result = process(message); return converter_.getString(result); } /** the main process method - must be implemented in subclass */ abstract public Element process(Element xml_in); protected Element getAndTransformFormat(Element format_response) { Element format_elem = (Element)GSXML.getChildByTagName(format_response, GSXML.FORMAT_ELEM); if (format_elem == null) { return null; } System.out.println("old format="+converter_.getString(format_elem)); // transform it to proper xsl String stylesheet_file = GSFile.stylesheetFile(config_, "config_format.xsl"); Document stylesheet = converter_.getDOM(new File(stylesheet_file)); Element new_format = (Element)transformer_.transform(stylesheet, format_elem); System.out.println("new format="+converter_.getString(new_format)); return new_format; } }