Ignore:
Timestamp:
2011-03-25T11:18:17+13:00 (13 years ago)
Author:
sjm84
Message:

Some small modifications to allow a permanent search bar to be present in GS3 collections

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/DefaultReceptionist.java

    r19852 r23814  
    1717
    1818/** The default greenstone receptionist - needs some extra info for each page
    19  */
     19*/
    2020public class DefaultReceptionist extends TransformingReceptionist {
    2121
    22      static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.DefaultReceptionist.class.getName());
    23    
    24   /** add in the collection description to the page, then for each service, add in the service description */
    25     protected void addExtraInfo(Element page) {
    26       super.addExtraInfo(page);
     22    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.DefaultReceptionist.class.getName());
    2723   
    28     Element page_request = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM);
    29     // if it is a system request, then we don't bother with this.
    30     String action = page_request.getAttribute(GSXML.ACTION_ATT);
    31     if (action.equals("s")) {
    32         logger.error("HACK: don't ask for coll info if system action");
    33         return;
     24    /** add in the collection description to the page, then for each service, add in the service description */
     25    protected void addExtraInfo(Element page) {
     26        super.addExtraInfo(page);
     27       
     28        Element page_request = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM);
     29        // if it is a system request, then we don't bother with this.
     30        String action = page_request.getAttribute(GSXML.ACTION_ATT);
     31        if (action.equals("s")) {
     32            logger.error("HACK: don't ask for coll info if system action");
     33            return;
     34        }
     35        logger.debug("add extra info, page request="+this.converter.getString(page_request));
     36        // is a collection defined?
     37        Element param_list = (Element)GSXML.getChildByTagName(page_request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     38        if (param_list==null) { // must be the original home page
     39            logger.debug(" no param list, assuming home page");
     40            return;
     41        }
     42        Element coll_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSParams.COLLECTION);
     43        if (coll_param == null) {
     44            logger.debug(" coll param is null, returning");
     45            return;
     46        }
     47
     48        // see if the collection/cluster element is already there
     49        String coll_name = coll_param.getAttribute(GSXML.VALUE_ATT);
     50        String lang = page_request.getAttribute(GSXML.LANG_ATT);
     51        String uid = page_request.getAttribute(GSXML.USER_ID_ATT);
     52       
     53        if (coll_name.equals("")) {
     54            coll_name = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, "p.c").getAttribute(GSXML.VALUE_ATT);
     55            logger.debug("*%*%*%* new collname = " + coll_name);
     56        }
     57       
     58        boolean get_service_description = false;
     59        Element page_response = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_RESPONSE_ELEM);
     60        if (this.language_list != null) {
     61            page_response.appendChild(this.language_list);
     62        }
     63        Element coll_description = (Element)GSXML.getChildByTagName(page_response, GSXML.COLLECTION_ELEM);
     64        if (coll_description == null) {
     65            // try cluster
     66            coll_description = (Element)GSXML.getChildByTagName(page_response, GSXML.CLUSTER_ELEM);
     67        }
     68        if (coll_description == null) {
     69       
     70            logger.debug("*%*%*%* No collection element, getting one");
     71       
     72            // we dont have one yet - get it
     73            Element coll_about_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     74            Element coll_about_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE,  coll_name, lang, uid);
     75            coll_about_message.appendChild(coll_about_request);
     76           
     77            Node coll_about_response_message = this.mr.process(coll_about_message);
     78            Element coll_about_response = (Element)GSXML.getChildByTagName(coll_about_response_message, GSXML.RESPONSE_ELEM);
     79            if (coll_about_response == null) {
     80                return;
     81            }
     82            coll_description = (Element)GSXML.getChildByTagName(coll_about_response, GSXML.COLLECTION_ELEM);
     83            if (coll_description==null) { // may be a cluster
     84                coll_description = (Element)GSXML.getChildByTagName(coll_about_response, GSXML.CLUSTER_ELEM);
     85            }
     86           
     87            if (coll_description == null) {
     88                logger.error(" no collection description, returning");
     89                return;
     90            }
     91            // have found one, append it to the page response
     92            coll_description = (Element)this.doc.importNode(coll_description, true);
     93            page_response.appendChild(coll_description);
     94            get_service_description = true;
     95        }
     96
     97        // have got a coll description
     98       
     99        logger.debug("*%*%*%* Getting display information about the services");
     100       
     101        // now get the dispay info for the services
     102        Element service_list = (Element)GSXML.getChildByTagName(coll_description, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
     103        if (service_list == null) {
     104            logger.error(" no service list, returning");
     105            // something weird has gone wrong
     106            return;
     107        }
     108
     109        NodeList services = service_list.getElementsByTagName(GSXML.SERVICE_ELEM);
     110        if (services.getLength()==0) {
     111            logger.error("DefaultReceoptionist: no services found for colllection/cluster "+ coll_name);
     112            return;
     113        }
     114        // check one service for display items
     115        if (!get_service_description) {
     116            // we dont know yet if we need to get these
     117            int i=1;
     118            Element test_s = (Element)services.item(0);
     119            while (i<services.getLength() && (test_s.getAttribute(GSXML.TYPE_ATT).equals(GSXML.SERVICE_TYPE_RETRIEVE) || test_s.getAttribute(GSXML.TYPE_ATT).equals(GSXML.SERVICE_TYPE_OAI))) {
     120                test_s = (Element)services.item(i); i++;
     121            }
     122            if (i==services.getLength()) {
     123                // we have only found retrieve or oai services, so dont need descripitons anyway
     124                return;
     125            }
     126            if (GSXML.getChildByTagName(test_s, GSXML.DISPLAY_TEXT_ELEM) !=null) {
     127                // have got descriptions already,
     128                return;
     129            }
     130        }
     131       
     132       
     133        logger.debug("*%*%*%* Off to get the service descriptions");
     134
     135        // if get here, we need to get the service descriptions
     136       
     137        // we will send all the requests in a single message
     138        Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     139        for (int i=0; i<services.getLength(); i++) {
     140            Element c = (Element)services.item(i);
     141            String name = c.getAttribute(GSXML.NAME_ATT);
     142            String address = GSPath.appendLink(coll_name, name);
     143            Element info_request = GSXML.createBasicRequest(this.doc,  GSXML.REQUEST_TYPE_DESCRIBE, address, lang, uid);
     144            //Element req_param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     145            //req_param_list.appendChild(GSXML.createParameter(this.doc, GSXML.SUBSET_PARAM, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER));
     146            //info_request.appendChild(req_param_list);
     147            info_message.appendChild(info_request);
     148           
     149        }
     150
     151        Element info_response = (Element)this.mr.process(info_message);
     152
     153        NodeList service_responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
     154        // check that have same number of responses as collections
     155        if (services.getLength() != service_responses.getLength()) {
     156            logger.error(" didn't get a response for each service - somethings gone wrong!");
     157            // for now, dont use the metadata
     158        } else {
     159            for (int i=0; i<services.getLength(); i++) {
     160                Element c1 = (Element)services.item(i);
     161                Element c2 = (Element)GSXML.getChildByTagName((Element)service_responses.item(i), GSXML.SERVICE_ELEM);
     162                if (c1 !=null && c2 !=null && c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT))) {
     163                    //add the service data into the original response
     164                    GSXML.mergeElements(c1, c2);
     165                } else {
     166                    logger.debug(" response does not correspond to request!");
     167                }
     168               
     169            }
     170        }
    34171    }
    35     logger.debug("add extra info, page request="+this.converter.getString(page_request));
    36     // is a collection defined?
    37     Element param_list = (Element)GSXML.getChildByTagName(page_request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    38     if (param_list==null) { // must be the original home page
    39         logger.debug(" no param list, assuming home page");
    40         return;
    41     }
    42     Element coll_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSParams.COLLECTION);
    43     if (coll_param == null) {
    44         logger.debug(" coll param is null, returning");
    45         return;
    46     }
    47 
    48     // see if the collection/cluster element is already there
    49     String coll_name = coll_param.getAttribute(GSXML.VALUE_ATT);
    50     String lang = page_request.getAttribute(GSXML.LANG_ATT);
    51     String uid = page_request.getAttribute(GSXML.USER_ID_ATT);
    52    
    53     boolean get_service_description = false;
    54     Element page_response = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_RESPONSE_ELEM);
    55     if (this.language_list != null) {
    56         page_response.appendChild(this.language_list);
    57     }
    58     Element coll_description = (Element)GSXML.getChildByTagName(page_response, GSXML.COLLECTION_ELEM);
    59     if (coll_description == null) {
    60         // try cluster
    61         coll_description = (Element)GSXML.getChildByTagName(page_response, GSXML.CLUSTER_ELEM);
    62     }
    63     if (coll_description == null) {
    64         // we dont have one yet - get it
    65         Element coll_about_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    66         Element coll_about_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE,  coll_name, lang, uid);
    67         coll_about_message.appendChild(coll_about_request);
    68        
    69         Node coll_about_response_message = this.mr.process(coll_about_message);
    70         Element coll_about_response = (Element)GSXML.getChildByTagName(coll_about_response_message, GSXML.RESPONSE_ELEM);
    71         if (coll_about_response == null) {
    72         return;
    73         }
    74         coll_description = (Element)GSXML.getChildByTagName(coll_about_response, GSXML.COLLECTION_ELEM);
    75         if (coll_description==null) { // may be a cluster
    76         coll_description = (Element)GSXML.getChildByTagName(coll_about_response, GSXML.CLUSTER_ELEM);
    77         }
    78        
    79         if (coll_description == null) {
    80         logger.error(" no collection description, returning");
    81         return;
    82         }
    83         // have found one, append it to the page response
    84         coll_description = (Element)this.doc.importNode(coll_description, true);
    85         page_response.appendChild(coll_description);
    86         get_service_description = true;
    87     }
    88 
    89     // have got a coll description
    90    
    91     // now get the dispay info for the services
    92     Element service_list = (Element)GSXML.getChildByTagName(coll_description, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
    93     if (service_list == null) {
    94         logger.error(" no service list, returning");
    95         // something weird has gone wrong
    96         return;
    97     }
    98 
    99     NodeList services = service_list.getElementsByTagName(GSXML.SERVICE_ELEM);
    100     if (services.getLength()==0) {
    101         logger.error("DefaultReceoptionist: no services found for colllection/cluster "+ coll_name);
    102         return;
    103     }
    104     // check one service for display items
    105     if (!get_service_description) {
    106         // we dont know yet if we need to get these
    107         int i=1;
    108         Element test_s = (Element)services.item(0);
    109         while (i<services.getLength() && (test_s.getAttribute(GSXML.TYPE_ATT).equals(GSXML.SERVICE_TYPE_RETRIEVE) || test_s.getAttribute(GSXML.TYPE_ATT).equals(GSXML.SERVICE_TYPE_OAI))) {
    110         test_s = (Element)services.item(i); i++;
    111         }
    112         if (i==services.getLength()) {
    113         // we have only found retrieve or oai services, so dont need descripitons anyway
    114         return;
    115         }
    116         if (GSXML.getChildByTagName(test_s, GSXML.DISPLAY_TEXT_ELEM) !=null) {
    117         // have got descriptions already,
    118         return;
    119         }
    120     }
    121 
    122     // if get here, we need to get the service descriptions
    123        
    124     // we will send all the requests in a single message
    125     Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    126     for (int i=0; i<services.getLength(); i++) {
    127         Element c = (Element)services.item(i);
    128         String name = c.getAttribute(GSXML.NAME_ATT);
    129         String address = GSPath.appendLink(coll_name, name);
    130         Element info_request = GSXML.createBasicRequest(this.doc,  GSXML.REQUEST_TYPE_DESCRIBE, address, lang, uid);
    131         Element req_param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    132         req_param_list.appendChild(GSXML.createParameter(this.doc, GSXML.SUBSET_PARAM, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER));
    133         info_request.appendChild(req_param_list);
    134         info_message.appendChild(info_request);
    135        
    136     }
    137 
    138     Element info_response = (Element)this.mr.process(info_message);
    139 
    140     NodeList service_responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
    141     // check that have same number of responses as collections
    142     if (services.getLength() != service_responses.getLength()) {
    143         logger.error(" didn't get a response for each service - somethings gone wrong!");
    144         // for now, dont use the metadata
    145     } else {
    146         for (int i=0; i<services.getLength(); i++) {
    147         Element c1 = (Element)services.item(i);
    148         Element c2 = (Element)GSXML.getChildByTagName((Element)service_responses.item(i), GSXML.SERVICE_ELEM);
    149         if (c1 !=null && c2 !=null && c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT))) {
    150             //add the service data into the original response
    151             GSXML.mergeElements(c1, c2);
    152         } else {
    153             logger.debug(" response does not correspond to request!");
    154         }
    155        
    156         }
    157     }
    158    
    159     }
    160172}
    161173
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/BerryBasket.java

    r22085 r23814  
    449449
    450450    protected Element processDisplayList(Element request) {
    451     // Create a new (empty) result message
    452451        Hashtable docsMap =  updateDocMap(request);
    453452
     
    457456        Iterator keys = docsMap.keySet().iterator();
    458457   
    459          while(keys.hasNext()){     
    460          String collection = (String)keys.next();
    461              Hashtable items = (Hashtable)docsMap.get(collection);
    462          Iterator itemItr = items.values().iterator();
    463 
    464              Element collectionNode = this.doc.createElement("collection");
    465              collectionNode.setAttribute("name",collection);
    466          result.appendChild(collectionNode);
    467 
    468          while(itemItr.hasNext()){ 
     458    while(keys.hasNext()){     
     459        String collection = (String)keys.next();
     460        Hashtable items = (Hashtable)docsMap.get(collection);
     461        Iterator itemItr = items.values().iterator();
     462       
     463        Element collectionNode = this.doc.createElement("berryList");
     464        collectionNode.setAttribute("name",collection);
     465        result.appendChild(collectionNode);
     466       
     467        while(itemItr.hasNext()){ 
    469468                Item item = (Item)itemItr.next();
    470469            Element itemElement = this.doc.createElement("item");
     
    476475        itemElement.setAttribute("date",item.date);
    477476                itemElement.setAttribute("root_title",item.rootTitle);               
    478          }       
    479      }
     477        }       
     478    }
    480479       
    481480    return result;
    482481
    483    }
     482    }
    484483
    485484
Note: See TracChangeset for help on using the changeset viewer.