Changeset 15485
- Timestamp:
- 2008-05-15T13:32:29+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/trunk/gs3-webservices-democlient/src/GS3DemoClient/org/greenstone/gs3services/QBRSOAPServer.java
r15222 r15485 35 35 import org.w3c.dom.Document; 36 36 import org.w3c.dom.Element; 37 import org.w3c.dom.NodeList; 37 38 38 39 import org.greenstone.gsdl3.core.MessageRouter; … … 288 289 return this.processInternal(message); 289 290 } 290 291 291 292 /* (2) Process-type message, QUERY-TYPE SERVICES - p.45 */ 292 293 /** For executing a (process-type message) query-type service. … … 320 321 this.doc, name, value)); 321 322 } 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); 342 325 Element request = GSXML.createBasicRequest( 343 ownerDoc, GSXML.REQUEST_TYPE_PROCESS, to, lang, ""); 326 this.doc, GSXML.REQUEST_TYPE_PROCESS, 327 collection+"/"+service, lang, ""); 344 328 345 329 request.appendChild(paramList); … … 348 332 // Send it off to the Message Router and return the response 349 333 return this.processInternal(message); 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); 350 390 } 351 391 … … 782 822 System.out.println(ws.describeService("AddItem", "", "")); 783 823 784 // (2) try 3 query methods (simplerFieldQuery twice) + getFieldNameMappings()824 // (2) try 2 query methods: query and basicQuery 785 825 HashMap map = new HashMap(); 786 826 map.put("maxDocs", "100"); … … 796 836 System.out.println("Regular query: " + response); 797 837 838 // basicQuery 839 response = ws.basicQuery("gs2mgppdemo", "", "cat"); 840 System.out.println("Basic query on 'cat' over collection gs2mgppdemo:" 841 + response); 842 798 843 // (3) try 2 browse 799 844 System.out.println("describe browse:\n" … … 854 899 System.out.println(ws.helpWithMethod("helpWithMethod")); 855 900 901 856 902 System.out.println("Finished executing"); 857 903
Note:
See TracChangeset
for help on using the changeset viewer.