Index: /greenstone3/trunk/resources/java/QBRSOAPServer.java.in
===================================================================
--- /greenstone3/trunk/resources/java/QBRSOAPServer.java.in (revision 15480)
+++ /greenstone3/trunk/resources/java/QBRSOAPServer.java.in (revision 15481)
@@ -38,4 +38,5 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
import org.greenstone.gsdl3.core.MessageRouter;
@@ -325,26 +326,9 @@
this.doc, name, value));
}
- return queryProcess(collection+"/"+service, lang, paramList);
- }
-
- /** Values for field Names given in the paramList must exist for the
- * (Collection-)Service Query that this message is sent To (as given in the
- * 'to' argument).
- * @see The Greenstone 3 Developer's Manual - page 45
- * @param to - the (Collection-)Service Query that this message is sent To
- * @param lang - the language of the display items in the response
- * @param paramList - XML Dom Element representing the list of field names,
- * and associated values required for executing the query.
- * For names of Greenstone-accepted arguments,
- * @see Greenstone wiki - Actions and Arguments
- */
- protected String queryProcess(String to, String lang, Element paramList) {
- // must work with whatever Document was used to create the
- // : other elements must be created using this
- // document object too
- Document ownerDoc = paramList.getOwnerDocument();
- Element message = ownerDoc.createElement(GSXML.MESSAGE_ELEM);
+
+ Element message = this.doc.createElement(GSXML.MESSAGE_ELEM);
Element request = GSXML.createBasicRequest(
- ownerDoc, GSXML.REQUEST_TYPE_PROCESS, to, lang, "");
+ this.doc, GSXML.REQUEST_TYPE_PROCESS,
+ collection+"/"+service, lang, "");
request.appendChild(paramList);
@@ -352,6 +336,63 @@
// Send it off to the Message Router and return the response
- return this.processInternal(message);
- }
+ return this.processInternal(message);
+ }
+
+ /**
+ * This method is used to perform the most basic query:
+ * it assumes defaults for all other parameters and provides only
+ * the query string. It is built on top of a TextQuery.
+ * @param collection is the Greenstone collection to be searched
+ * @param lang is the preferred language of the display content in
+ * the response to be returned.
+ * @param query is the string to be sought in the Greenstone collection
+ * @return a Greenstone 3 XML response message for the query specifying
+ * the search results.
+ */
+ public String basicQuery(String collection, String lang, String query) {
+ // The basicQuery is built on top of the TextQuery service
+ final String queryService = "TextQuery";
+
+ // (1) describe request on the TextQuery
+ String queryDescription = describeCollectionService(
+ collection, queryService, "en", "paramList"); // just get paramList
+ //System.out.println(queryDescription);
+
+ Document doc = this.converter.getDOM(queryDescription);
+ NodeList nl = doc.getElementsByTagName(
+ GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
+
+ Element paramList = null;
+ if(nl.getLength() <= 0) { // no paramList in textQuery description means
+ // no query field either: that means we can't continue
+ return this.error("BasicQuery is not available for this collection"
+ + " as it provides no TextQuery service.");
+ } //else
+
+ paramList = (Element)nl.item(0);
+ nl = paramList.getElementsByTagName(GSXML.PARAM_ELEM);
+ if(nl.getLength() <= 0) { // no params, means no query field, so return
+ return this.error("BasicQuery is not available for this collection.");
+ }
+
+ // (2) get the defaults for each parameter and use that to set
+ // the defaults
+ Map params = new HashMap(nl.getLength()); // field name to value map
+ for(int i = 0; i < nl.getLength(); i++) {
+ Element param = (Element)nl.item(i);
+ String paramName = param.getAttribute(GSXML.NAME_ATT);
+ String def = param.getAttribute(GSXML.DEFAULT_ATT);
+ if(def.equals("")) {
+ // if there's no default, the field must want the query String
+ params.put(paramName, query);
+ } else { // there is a default, use the default for this param
+ params.put(paramName, def);
+ }
+ }
+
+ // (3) Perform the query using defaults and return the response
+ return this.query(collection, queryService, lang, params);
+ }
+
/* (3) RETRIEVE PROCESS METHODS - Manual, pp.47-49 */