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.NodeList; import org.w3c.dom.Element; import org.w3c.dom.Document; // other java stuff import java.io.File; import java.util.Vector; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import org.apache.log4j.*; /** base class for Actions */ abstract public class Action { /** the system set up variables */ protected HashMap config_params = null; /** container Document to create XML Nodes */ protected Document doc=null; /** a converter class to parse XML and create Docs */ protected XMLConverter converter=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; static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.Action.class.getName()); public Action() { this.converter = new XMLConverter(); this.doc = this.converter.newDOM(); } /** the config variables must be set before configure is called */ public void setConfigParams(HashMap params) { this.config_params = params; } /** sets the message router */ public void setMessageRouter(ModuleInterface m) { this.mr = m; } public boolean configure() { // does nothing yet return true; } /** 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) { Document message_doc = this.converter.getDOM(xml_in); if (message_doc == null) { logger.error("Couldn't parse request"); logger.error(xml_in); return null; } Node result = process(message_doc); return this.converter.getString(result); } /** the main process method - must be implemented in subclass */ abstract public Node process(Node xml_in); /** tell the param class what its arguments are * if an action has its own arguments, this should add them to the params * object - particularly important for args that should not be saved */ public boolean getActionParameters(GSParams params) { return true; } protected void extractMetadataNames(Element format, HashSet meta_names) { //NodeList nodes = format.getElementsByTagNameNS("metadata", "http://www.greenstone.org/configformat"); NodeList metadata_nodes = format.getElementsByTagName("gsf:metadata"); for (int i=0; i