| 322 | | return queryProcess(collection+"/"+service, lang, paramList); |
|---|
| 323 | | } |
|---|
| 324 | | |
|---|
| 325 | | /** Values for field Names given in the paramList must exist for the |
|---|
| 326 | | * (Collection-)Service Query that this message is sent To (as given in the |
|---|
| 327 | | * 'to' argument). |
|---|
| 328 | | * @see <a href="http://wiki.greenstone.org/wiki/index.php/Greenstone3">The Greenstone 3 Developer's Manual - page 45</a> |
|---|
| 329 | | * @param to - the (Collection-)Service Query that this message is sent To |
|---|
| 330 | | * @param lang - the language of the display items in the response |
|---|
| 331 | | * @param paramList - XML Dom Element representing the list of field names, |
|---|
| 332 | | * and associated values required for executing the query. |
|---|
| 333 | | * For names of Greenstone-accepted arguments, |
|---|
| 334 | | * @see <a href="http://wiki.greenstone.org/wiki/index.php/Actions_and_Arguments">Greenstone wiki - Actions and Arguments<a> |
|---|
| 335 | | */ |
|---|
| 336 | | protected String queryProcess(String to, String lang, Element paramList) { |
|---|
| 337 | | // must work with whatever Document was used to create the |
|---|
| 338 | | // <paramList>: other elements must be created using this |
|---|
| 339 | | // document object too |
|---|
| 340 | | Document ownerDoc = paramList.getOwnerDocument(); |
|---|
| 341 | | Element message = ownerDoc.createElement(GSXML.MESSAGE_ELEM); |
|---|
| | 323 | |
|---|
| | 324 | Element message = this.doc.createElement(GSXML.MESSAGE_ELEM); |
|---|
| | 334 | } |
|---|
| | 335 | |
|---|
| | 336 | /** |
|---|
| | 337 | * This method is used to perform the most basic query of them: |
|---|
| | 338 | * it assumes defaults for all other parameters and provides only |
|---|
| | 339 | * the query string. It is built on top of a TextQuery. |
|---|
| | 340 | * @param collection is the Greenstone collection to be searched |
|---|
| | 341 | * @param lang is the preferred language of the display content in |
|---|
| | 342 | * the response to be returned. |
|---|
| | 343 | * @param query is the string to be sought in the Greenstone collection |
|---|
| | 344 | * @return a Greenstone 3 XML response message for the query specifying |
|---|
| | 345 | * the search results. |
|---|
| | 346 | */ |
|---|
| | 347 | public String basicQuery(String collection, String lang, String query) { |
|---|
| | 348 | // The basicQuery is built on top of the TextQuery service |
|---|
| | 349 | final String queryService = "TextQuery"; |
|---|
| | 350 | |
|---|
| | 351 | // (1) describe request on the TextQuery |
|---|
| | 352 | String queryDescription = describeCollectionService( |
|---|
| | 353 | collection, queryService, "en", "paramList"); // just get paramList |
|---|
| | 354 | //System.out.println(queryDescription); |
|---|
| | 355 | |
|---|
| | 356 | Document doc = this.converter.getDOM(queryDescription); |
|---|
| | 357 | NodeList nl = doc.getElementsByTagName( |
|---|
| | 358 | GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); |
|---|
| | 359 | |
|---|
| | 360 | Element paramList = null; |
|---|
| | 361 | if(nl.getLength() <= 0) { // no paramList in textQuery description means |
|---|
| | 362 | // no query field either: that means we can't continue |
|---|
| | 363 | return this.error("BasicQuery is not available for this collection" |
|---|
| | 364 | + " as it provides no TextQuery service."); |
|---|
| | 365 | } //else |
|---|
| | 366 | |
|---|
| | 367 | paramList = (Element)nl.item(0); |
|---|
| | 368 | nl = paramList.getElementsByTagName(GSXML.PARAM_ELEM); |
|---|
| | 369 | if(nl.getLength() <= 0) { // no params, means no query field, so return |
|---|
| | 370 | return this.error("BasicQuery is not available for this collection."); |
|---|
| | 371 | } |
|---|
| | 372 | |
|---|
| | 373 | // (2) get the defaults for each parameter and use that to set |
|---|
| | 374 | // the defaults |
|---|
| | 375 | Map params = new HashMap(nl.getLength()); // field name to value map |
|---|
| | 376 | for(int i = 0; i < nl.getLength(); i++) { |
|---|
| | 377 | Element param = (Element)nl.item(i); |
|---|
| | 378 | String paramName = param.getAttribute(GSXML.NAME_ATT); |
|---|
| | 379 | String def = param.getAttribute(GSXML.DEFAULT_ATT); |
|---|
| | 380 | if(def.equals("")) { |
|---|
| | 381 | // if there's no default, the field must want the query String |
|---|
| | 382 | params.put(paramName, query); |
|---|
| | 383 | } else { // there is a default, use the default for this param |
|---|
| | 384 | params.put(paramName, def); |
|---|
| | 385 | } |
|---|
| | 386 | } |
|---|
| | 387 | |
|---|
| | 388 | // (3) Perform the query using defaults and return the response |
|---|
| | 389 | return this.query(collection, queryService, lang, params); |
|---|