Changeset 15481

Show
Ignore:
Timestamp:
15.05.2008 13:27:22 (11 years ago)
Author:
ak19
Message:

Added basicQuery method/operation and merged query with protected queryProcess

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/resources/java/QBRSOAPServer.java.in

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