Changeset 26406 for main

Show
Ignore:
Timestamp:
30.10.2012 14:37:16 (7 years ago)
Author:
kjdon
Message:

made the list of collections use language dependent descriptions. added a hashmap to store descriptions by language

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/CrossCollectionSearch.java

    r26055 r26406  
    4949    // the services on offer - these proxy the actual collection ones 
    5050    protected static final String TEXT_QUERY_SERVICE = "TextQuery"; 
    51     protected static final String ADV_QUERY_SERVICE = "AdvTextQuery"; 
    5251    protected static final String DOCUMENT_METADATA_RETRIEVE_SERVICE = "DocumentMetadataRetrieve"; 
    5352 
    5453    protected String[] coll_ids_list = null; 
    5554    protected String[] coll_ids_list_no_all = null; 
    56     protected String[] coll_names_list = null; 
     55  // maps lang to coll names list 
     56  protected HashMap<String, String[]> coll_names_map = null; 
     57  //protected String[] coll_names_list = null; 
    5758 
    5859    /** constructor */ 
     
    120121                if (coll_ids_list == null) 
    121122                { 
    122                     initCollectionList(); 
     123                    initCollectionList(lang); 
    123124                } 
    124                 Element param = GSXML.createParameterDescription(this.doc, COLLECTION_PARAM, getTextString("param." + COLLECTION_PARAM, lang), GSXML.PARAM_TYPE_ENUM_MULTI, "all", coll_ids_list, coll_names_list); 
     125                if (!coll_names_map.containsKey(lang)) { 
     126                  addCollectionNames(lang); 
     127                } 
     128                Element param = GSXML.createParameterDescription(this.doc, COLLECTION_PARAM, getTextString("param." + COLLECTION_PARAM, lang), GSXML.PARAM_TYPE_ENUM_MULTI, "all", coll_ids_list, coll_names_map.get(lang)); 
    125129                param_list.appendChild(param); 
    126130                // query param 
     
    257261 
    258262    //     } 
    259     protected boolean initCollectionList() 
     263    protected boolean initCollectionList(String lang) 
    260264    { 
    261265        UserContext userContext = new UserContext(); 
    262         userContext.setLanguage("en"); 
     266        userContext.setLanguage(lang); 
    263267        userContext.setUserID(""); 
    264268 
     
    279283 
    280284        NodeList colls = coll_list_response.getElementsByTagName(GSXML.COLLECTION_ELEM); 
    281         // we will send all the requests in a single message 
     285        // we can send the same request to multiple collections at once by using a comma separated list 
    282286        Element metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 
     287        StringBuffer colls_sb = new StringBuffer(); 
    283288        for (int i = 0; i < colls.getLength(); i++) 
    284289        { 
    285290            Element c = (Element) colls.item(i); 
    286291            String name = c.getAttribute(GSXML.NAME_ATT); 
    287             Element metadata_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, name, userContext); 
    288             metadata_message.appendChild(metadata_request); 
    289         } 
     292            if (i!=0) { 
     293              colls_sb.append(","); 
     294            } 
     295            colls_sb.append(name); 
     296            //Element metadata_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, name, userContext); 
     297            //metadata_message.appendChild(metadata_request); 
     298        } 
     299        Element metadata_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, colls_sb.toString(), userContext); 
     300        metadata_message.appendChild(metadata_request); 
    290301        logger.debug("metadata request = " + this.converter.getPrettyString(metadata_message)); 
    291302        Element metadata_response = (Element) this.router.process(metadata_message); 
     
    306317            // use the name of the response in case we are talking to a remote collection, not the name of the collection. 
    307318            String coll_id = response.getAttribute(GSXML.FROM_ATT); 
    308             String coll_name = coll_id + ": " + GSXML.getDisplayText(coll, GSXML.DISPLAY_TEXT_NAME, "en", "en"); // just use english for now until we do some caching or something 
     319            String coll_name = GSXML.getDisplayText(coll, GSXML.DISPLAY_TEXT_NAME, lang, "en");  
    309320            valid_colls.add(coll_id); 
    310321            valid_coll_names.add(coll_name); 
     
    320331 
    321332        valid_colls.add(0, "all"); 
    322         valid_coll_names.add(0, getTextString("param." + COLLECTION_PARAM + ".all", "en")); 
     333        valid_coll_names.add(0, getTextString("param." + COLLECTION_PARAM + ".all", lang)); 
     334 
    323335        this.coll_ids_list = new String[1]; 
    324         this.coll_names_list = new String[1]; 
    325336        this.coll_ids_list = valid_colls.toArray(coll_ids_list); 
    326         this.coll_names_list = valid_coll_names.toArray(coll_names_list); 
     337 
     338        this.coll_names_map = new HashMap<String, String[]>(); 
     339        String[] coll_names_list = new String[1]; 
     340        coll_names_list = valid_coll_names.toArray(coll_names_list); 
     341        this.coll_names_map.put(lang, coll_names_list); 
    327342        return true; 
    328343    } 
     344 
     345  protected void addCollectionNames(String lang) { 
     346 
     347    UserContext userContext = new UserContext(); 
     348    userContext.setLanguage(lang); 
     349    userContext.setUserID(""); 
     350 
     351    ArrayList<String> coll_names = new ArrayList<String>(); 
     352    coll_names.add(getTextString("param." + COLLECTION_PARAM + ".all", lang)); 
     353 
     354    // need to request MR for collection descriptions 
     355    Element metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 
     356 
     357    // get a comma separated list of coll ids to send to MR 
     358    // the first item is the place holder for 'all' 
     359    StringBuffer colls_sb = new StringBuffer(); 
     360    for (int i=1; i<coll_ids_list.length; i++) { 
     361      if (i!=1) { 
     362    colls_sb.append(","); 
     363      } 
     364      colls_sb.append(coll_ids_list[i]); 
     365    } 
     366    Element metadata_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, colls_sb.toString(), userContext); 
     367    // param_list to request just displayTextList 
     368    Element param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 
     369    Element param = GSXML.createParameter(this.doc, GSXML.SUBSET_PARAM, GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER); 
     370    param_list.appendChild(param); 
     371    metadata_request.appendChild(param_list); 
     372    metadata_message.appendChild(metadata_request); 
     373    logger.debug("coll names metadata request = " + this.converter.getPrettyString(metadata_message)); 
     374    Element metadata_response = (Element) this.router.process(metadata_message); 
     375    logger.debug("coll names metadata response = " + this.converter.getPrettyString(metadata_response)); 
     376    NodeList coll_responses = metadata_response.getElementsByTagName(GSXML.RESPONSE_ELEM); 
     377    for (int i = 0; i < coll_responses.getLength(); i++) 
     378      {      
     379    Element response = (Element) coll_responses.item(i); 
     380    Element coll = (Element) GSXML.getChildByTagName(response, GSXML.COLLECTION_ELEM); 
     381    String coll_name = GSXML.getDisplayText(coll, GSXML.DISPLAY_TEXT_NAME, lang, "en");  
     382    coll_names.add(coll_name); 
     383      } 
     384 
     385    String[] coll_names_list = new String[1]; 
     386    coll_names_list = coll_names.toArray(coll_names_list); 
     387    this.coll_names_map.put(lang, coll_names_list); 
     388 
     389  } 
    329390 
    330391    protected Element processDocumentMetadataRetrieve(Element request)