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.Text; import org.w3c.dom.Document; import org.w3c.dom.Element; import java.util.HashMap; import java.util.HashSet; import java.util.Vector; import java.util.Map; import java.util.Iterator; import java.io.File; import org.apache.log4j.*; /** action class for queries * this is used when querying isn't collection specific, but it occurs across all collections in the site. The service description is assumed to be known by the xslt so we dont ask for it. we just pass all the service params to the TextQuery service of all the collections */ public class NoCollQueryAction extends Action { static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.NoCollQueryAction.class.getName()); /** process - processes a request. */ public Element process (Element message) { // get the request - assume there is only one Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); // create the return message Element result = this.doc.createElement(GSXML.MESSAGE_ELEM); // for now we only have one type of query - subaction not used Element response = basicQuery(request); result.appendChild(this.doc.importNode(response, true)); return result; } /** a generic query handler * this gets the service description, does the query (just passes all teh * params to the service, then gets the titles for any results */ protected Element basicQuery(Element request) { // the result Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM); // extract the params from the cgi-request, and check that we have a coll specified Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); HashMap params = GSXML.extractParams(cgi_param_list, false); String request_type = (String)params.get(GSParams.REQUEST_TYPE); String lang = request.getAttribute(GSXML.LANG_ATT); String uid = request.getAttribute(GSXML.USER_ID_ATT); if (request_type.equals("d")) { // display the query page // the only info we need to return is the collection list cos the xslt does teh rest Element coll_list = getCollectionList(lang, uid); page_response.appendChild(this.doc.importNode(coll_list, true)); return page_response; } // else we have a query String service_name = (String)params.get(GSParams.SERVICE); if (service_name == null || service_name.equals("")) { service_name = "TextQuery"; } String query_coll_list = (String)params.get(GSParams.COLLECTION); if (query_coll_list == null || query_coll_list.equals("")) { logger.error("no collections were specified!"); Element coll_list = getCollectionList(lang, uid); page_response.appendChild(this.doc.importNode(coll_list, true)); return page_response; } // service paramList HashMap service_params = (HashMap)params.get("s1"); if (service_params == null) { // no query return page_response; } Element query_param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); GSXML.addParametersToList(this.doc, query_param_list, service_params); // we will do a query for each coll String [] colls = query_coll_list.split(","); Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM); for (int i=0; i< colls.length; i++) { String to = GSPath.appendLink(colls[i], service_name); Element mr_query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid); mr_query_message.appendChild(mr_query_request); mr_query_request.appendChild(query_param_list.cloneNode(true)); } // do the query Element mr_query_response = (Element)this.mr.process(mr_query_message); // get the Title metadata for each node - need Node title and root title Element mr_meta_message = this.doc.createElement(GSXML.MESSAGE_ELEM); NodeList responses = mr_query_response.getElementsByTagName(GSXML.RESPONSE_ELEM); for (int j=0; j