Changeset 26577


Ignore:
Timestamp:
12/13/12 09:53:54 (8 years ago)
Author:
sjm84
Message:

Reformatting this file ahead of some changes

File:
1 edited

Legend:

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

    r26406 r26577  
    1919package org.greenstone.gsdl3.service;
    2020
     21import java.util.ArrayList;
     22import java.util.HashMap;
     23import java.util.Iterator;
     24import java.util.Map;
     25import java.util.Set;
     26
     27import org.apache.log4j.Logger;
     28import org.greenstone.gsdl3.util.GSPath;
    2129import org.greenstone.gsdl3.util.GSXML;
    22 import org.greenstone.gsdl3.util.GSPath;
    2330import org.greenstone.gsdl3.util.UserContext;
    24 
    2531import org.w3c.dom.Element;
    2632import org.w3c.dom.Node;
    2733import org.w3c.dom.NodeList;
    28 
    29 import java.util.ArrayList;
    30 import java.util.Map;
    31 import java.util.Iterator;
    32 import java.util.Set;
    33 import java.util.HashMap;
    34 
    35 import org.apache.log4j.*;
    3634
    3735/**
     
    5351    protected String[] coll_ids_list = null;
    5452    protected String[] coll_ids_list_no_all = null;
    55   // maps lang to coll names list
    56   protected HashMap<String, String[]> coll_names_map = null;
    57   //protected String[] coll_names_list = null;
     53    // maps lang to coll names list
     54    protected HashMap<String, String[]> coll_names_map = null;
     55
     56    //protected String[] coll_names_list = null;
    5857
    5958    /** constructor */
     
    123122                    initCollectionList(lang);
    124123                }
    125                 if (!coll_names_map.containsKey(lang)) {
    126                   addCollectionNames(lang);
     124                if (!coll_names_map.containsKey(lang))
     125                {
     126                    addCollectionNames(lang);
    127127                }
    128128                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));
     
    153153
    154154        UserContext userContext = new UserContext(request);
    155        
     155
    156156        // Get the parameters of the request
    157157        Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     
    290290            Element c = (Element) colls.item(i);
    291291            String name = c.getAttribute(GSXML.NAME_ATT);
    292             if (i!=0) {
    293               colls_sb.append(",");
     292            if (i != 0)
     293            {
     294                colls_sb.append(",");
    294295            }
    295296            colls_sb.append(name);
     
    317318            // use the name of the response in case we are talking to a remote collection, not the name of the collection.
    318319            String coll_id = response.getAttribute(GSXML.FROM_ATT);
    319             String coll_name = GSXML.getDisplayText(coll, GSXML.DISPLAY_TEXT_NAME, lang, "en"); 
     320            String coll_name = GSXML.getDisplayText(coll, GSXML.DISPLAY_TEXT_NAME, lang, "en");
    320321            valid_colls.add(coll_id);
    321322            valid_coll_names.add(coll_name);
     
    343344    }
    344345
    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   }
     346    protected void addCollectionNames(String lang)
     347    {
     348
     349        UserContext userContext = new UserContext();
     350        userContext.setLanguage(lang);
     351        userContext.setUserID("");
     352
     353        ArrayList<String> coll_names = new ArrayList<String>();
     354        coll_names.add(getTextString("param." + COLLECTION_PARAM + ".all", lang));
     355
     356        // need to request MR for collection descriptions
     357        Element metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     358
     359        // get a comma separated list of coll ids to send to MR
     360        // the first item is the place holder for 'all'
     361        StringBuffer colls_sb = new StringBuffer();
     362        for (int i = 1; i < coll_ids_list.length; i++)
     363        {
     364            if (i != 1)
     365            {
     366                colls_sb.append(",");
     367            }
     368            colls_sb.append(coll_ids_list[i]);
     369        }
     370        Element metadata_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, colls_sb.toString(), userContext);
     371        // param_list to request just displayTextList
     372        Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     373        Element param = GSXML.createParameter(this.doc, GSXML.SUBSET_PARAM, GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER);
     374        param_list.appendChild(param);
     375        metadata_request.appendChild(param_list);
     376        metadata_message.appendChild(metadata_request);
     377        logger.debug("coll names metadata request = " + this.converter.getPrettyString(metadata_message));
     378        Element metadata_response = (Element) this.router.process(metadata_message);
     379        logger.debug("coll names metadata response = " + this.converter.getPrettyString(metadata_response));
     380        NodeList coll_responses = metadata_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
     381        for (int i = 0; i < coll_responses.getLength(); i++)
     382        {
     383            Element response = (Element) coll_responses.item(i);
     384            Element coll = (Element) GSXML.getChildByTagName(response, GSXML.COLLECTION_ELEM);
     385            String coll_name = GSXML.getDisplayText(coll, GSXML.DISPLAY_TEXT_NAME, lang, "en");
     386            coll_names.add(coll_name);
     387        }
     388
     389        String[] coll_names_list = new String[1];
     390        coll_names_list = coll_names.toArray(coll_names_list);
     391        this.coll_names_map.put(lang, coll_names_list);
     392
     393    }
    390394
    391395    protected Element processDocumentMetadataRetrieve(Element request)
Note: See TracChangeset for help on using the changeset viewer.