Changeset 24974


Ignore:
Timestamp:
2012-01-26T10:29:28+13:00 (12 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/core/DefaultReceptionist.java

    r23968 r24974  
    44import org.greenstone.gsdl3.action.*;
    55// XML classes
    6 import org.w3c.dom.Node; 
    7 import org.w3c.dom.NodeList; 
    8 import org.w3c.dom.Document; 
    9 import org.w3c.dom.Element; 
     6import org.w3c.dom.Node;
     7import org.w3c.dom.NodeList;
     8import org.w3c.dom.Document;
     9import org.w3c.dom.Element;
    1010
    1111// other java classes
     
    1616import org.apache.log4j.*;
    1717
    18 /** The default greenstone receptionist - needs some extra info for each page
    19 */
    20 public class DefaultReceptionist extends TransformingReceptionist {
     18/** The default greenstone receptionist - needs some extra info for each page */
     19public class DefaultReceptionist extends TransformingReceptionist
     20{
    2121
    2222    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) {
     23
     24    /**
     25     * add in the collection description to the page, then for each service, add
     26     * in the service description
     27     */
     28    protected void addExtraInfo(Element page)
     29    {
    2630        super.addExtraInfo(page);
    27        
    28         Element page_request = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM);
     31
     32        Element page_request = (Element) GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM);
    2933        // if it is a system request, then we don't bother with this.
    3034        String action = page_request.getAttribute(GSXML.ACTION_ATT);
    31         if (action.equals("s")) {
     35        if (action.equals("s"))
     36        {
    3237            logger.error("HACK: don't ask for coll info if system action");
    3338            return;
    3439        }
    35         logger.debug("add extra info, page request="+this.converter.getString(page_request));
     40        logger.debug("add extra info, page request=" + this.converter.getString(page_request));
    3641        // 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
     42        Element param_list = (Element) GSXML.getChildByTagName(page_request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     43        if (param_list == null)
     44        { // must be the original home page
    3945            logger.debug(" no param list, assuming home page");
    4046            return;
    4147        }
    4248        Element coll_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSParams.COLLECTION);
    43         if (coll_param == null) {
     49        if (coll_param == null)
     50        {
    4451            logger.debug(" coll param is null, returning");
    4552            return;
     
    5057        String lang = page_request.getAttribute(GSXML.LANG_ATT);
    5158        String uid = page_request.getAttribute(GSXML.USER_ID_ATT);
    52        
    53         if (coll_name.equals("")) {
     59
     60        if (coll_name.equals(""))
     61        {
    5462            Element pc_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, "p.c");
    55             if(pc_param != null)
     63            if (pc_param != null)
    5664            {
    5765                coll_name = pc_param.getAttribute(GSXML.VALUE_ATT);
    5866            }
    5967        }
    60        
     68
    6169        boolean get_service_description = false;
    62         Element page_response = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_RESPONSE_ELEM);
    63         if (this.language_list != null) {
     70        Element page_response = (Element) GSXML.getChildByTagName(page, GSXML.PAGE_RESPONSE_ELEM);
     71        if (this.language_list != null)
     72        {
    6473            page_response.appendChild(this.language_list);
    6574        }
    66         Element coll_description = (Element)GSXML.getChildByTagName(page_response, GSXML.COLLECTION_ELEM);
    67         if (coll_description == null) {
     75        Element coll_description = (Element) GSXML.getChildByTagName(page_response, GSXML.COLLECTION_ELEM);
     76        if (coll_description == null)
     77        {
    6878            // try cluster
    69             coll_description = (Element)GSXML.getChildByTagName(page_response, GSXML.CLUSTER_ELEM);
     79            coll_description = (Element) GSXML.getChildByTagName(page_response, GSXML.CLUSTER_ELEM);
    7080        }
    71         if (coll_description == null) {
    72        
     81        if (coll_description == null)
     82        {
     83
    7384            // we dont have one yet - get it
    7485            Element coll_about_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    75             Element coll_about_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE,  coll_name, lang, uid);
     86            Element coll_about_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, coll_name, lang, uid);
    7687            coll_about_message.appendChild(coll_about_request);
    77            
     88
    7889            Node coll_about_response_message = this.mr.process(coll_about_message);
    79             Element coll_about_response = (Element)GSXML.getChildByTagName(coll_about_response_message, GSXML.RESPONSE_ELEM);
    80             if (coll_about_response == null) {
     90            Element coll_about_response = (Element) GSXML.getChildByTagName(coll_about_response_message, GSXML.RESPONSE_ELEM);
     91            if (coll_about_response == null)
     92            {
    8193                return;
    8294            }
    83             coll_description = (Element)GSXML.getChildByTagName(coll_about_response, GSXML.COLLECTION_ELEM);
    84             if (coll_description==null) { // may be a cluster
    85                 coll_description = (Element)GSXML.getChildByTagName(coll_about_response, GSXML.CLUSTER_ELEM);
     95            coll_description = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.COLLECTION_ELEM);
     96            if (coll_description == null)
     97            { // may be a cluster
     98                coll_description = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.CLUSTER_ELEM);
    8699            }
    87            
    88             if (coll_description == null) {
     100
     101            if (coll_description == null)
     102            {
    89103                logger.error(" no collection description, returning");
    90104                return;
    91105            }
    92106            // have found one, append it to the page response
    93             coll_description = (Element)this.doc.importNode(coll_description, true);
     107            coll_description = (Element) this.doc.importNode(coll_description, true);
    94108            page_response.appendChild(coll_description);
    95109            get_service_description = true;
     
    98112        // have got a coll description
    99113        // now get the dispay info for the services
    100         Element service_list = (Element)GSXML.getChildByTagName(coll_description, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
    101         if (service_list == null) {
     114        Element service_list = (Element) GSXML.getChildByTagName(coll_description, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
     115        if (service_list == null)
     116        {
    102117            logger.error(" no service list, returning");
    103118            // something weird has gone wrong
     
    106121
    107122        NodeList services = service_list.getElementsByTagName(GSXML.SERVICE_ELEM);
    108         if (services.getLength()==0) {
    109             logger.error("DefaultReceoptionist: no services found for colllection/cluster "+ coll_name);
     123        if (services.getLength() == 0)
     124        {
     125            logger.error("DefaultReceoptionist: no services found for colllection/cluster " + coll_name);
    110126            return;
    111127        }
    112128        // check one service for display items
    113         if (!get_service_description) {
     129        if (!get_service_description)
     130        {
    114131            // we dont know yet if we need to get these
    115             int i=1;
    116             Element test_s = (Element)services.item(0);
    117             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))) {
    118                 test_s = (Element)services.item(i); i++;
     132            int i = 1;
     133            Element test_s = (Element) services.item(0);
     134            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)))
     135            {
     136                test_s = (Element) services.item(i);
     137                i++;
    119138            }
    120             if (i==services.getLength()) {
     139            if (i == services.getLength())
     140            {
    121141                // we have only found retrieve or oai services, so dont need descripitons anyway
    122142                return;
    123143            }
    124             if (GSXML.getChildByTagName(test_s, GSXML.DISPLAY_TEXT_ELEM) !=null) {
     144            if (GSXML.getChildByTagName(test_s, GSXML.DISPLAY_TEXT_ELEM) != null)
     145            {
    125146                // have got descriptions already,
    126147                return;
     
    129150
    130151        // if get here, we need to get the service descriptions
    131        
     152
    132153        // we will send all the requests in a single message
    133154        Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    134         for (int i=0; i<services.getLength(); i++) {
    135             Element c = (Element)services.item(i);
     155        for (int i = 0; i < services.getLength(); i++)
     156        {
     157            Element c = (Element) services.item(i);
    136158            String name = c.getAttribute(GSXML.NAME_ATT);
    137159            String address = GSPath.appendLink(coll_name, name);
    138             Element info_request = GSXML.createBasicRequest(this.doc,  GSXML.REQUEST_TYPE_DESCRIBE, address, lang, uid);
     160            Element info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, address, lang, uid);
    139161            //Element req_param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    140162            //req_param_list.appendChild(GSXML.createParameter(this.doc, GSXML.SUBSET_PARAM, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER));
    141163            //info_request.appendChild(req_param_list);
    142164            info_message.appendChild(info_request);
    143            
     165
    144166        }
    145167
    146         Element info_response = (Element)this.mr.process(info_message);
     168        Element info_response = (Element) this.mr.process(info_message);
    147169
    148170        NodeList service_responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
    149171        // check that have same number of responses as collections
    150         if (services.getLength() != service_responses.getLength()) {
     172        if (services.getLength() != service_responses.getLength())
     173        {
    151174            logger.error(" didn't get a response for each service - somethings gone wrong!");
    152175            // for now, dont use the metadata
    153         } else {
    154             for (int i=0; i<services.getLength(); i++) {
    155                 Element c1 = (Element)services.item(i);
    156                 Element c2 = (Element)GSXML.getChildByTagName((Element)service_responses.item(i), GSXML.SERVICE_ELEM);
    157                 if (c1 !=null && c2 !=null && c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT))) {
     176        }
     177        else
     178        {
     179            for (int i = 0; i < services.getLength(); i++)
     180            {
     181                Element c1 = (Element) services.item(i);
     182                Element c2 = (Element) GSXML.getChildByTagName((Element) service_responses.item(i), GSXML.SERVICE_ELEM);
     183                if (c1 != null && c2 != null && c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT)))
     184                {
    158185                    //add the service data into the original response
    159186                    GSXML.mergeElements(c1, c2);
    160                 } else {
     187                }
     188                else
     189                {
    161190                    logger.debug(" response does not correspond to request!");
    162                 } 
    163                
     191                }
     192
    164193            }
    165194        }
    166195    }
    167196}
    168 
Note: See TracChangeset for help on using the changeset viewer.