Changeset 11230


Ignore:
Timestamp:
2006-02-09T15:28:18+13:00 (18 years ago)
Author:
kjdon
Message:

home page now gets descriptions of clusters and services so cna display them if necessary

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/action/PageAction.java

    r6300 r11230  
    5050    String uid = request.getAttribute(GSXML.USER_ID_ATT);
    5151    // first, get the message router info
    52     Element coll_list_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     52    Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    5353    Element coll_list_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", lang, uid);
    54     coll_list_message.appendChild(coll_list_request);
    55     Element coll_list_response = (Element)this.mr.process(coll_list_message);
    56     if (coll_list_response==null) {
     54    info_message.appendChild(coll_list_request);
     55    Element info_response_message = (Element)this.mr.process(info_message);
     56    if (info_response_message==null) {
    5757        System.err.println("PageAction Error: couldn't query the message router!");
    5858        return null;
    5959    }
    60    
     60    Element info_response = (Element)GSXML.getChildByTagName(info_response_message, GSXML.RESPONSE_ELEM);
     61    if (info_response==null) {
     62        System.err.println("PageAction Error: couldn't query the message router!");
     63        return null;
     64    }
     65       
    6166    // second, get the metadata for each collection - we only want specific
    6267    // elements but for now, we'll just get it all
    63     NodeList colls = coll_list_response.getElementsByTagName(GSXML.COLLECTION_ELEM);
    64     // we will send all the requests in a single message
    65     Element metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    66     for (int i=0; i<colls.getLength(); i++) {
    67         Element c = (Element)colls.item(i);
    68         String name = c.getAttribute(GSXML.NAME_ATT);       
    69        
    70         Element metadata_request = GSXML.createBasicRequest(this.doc,  GSXML.REQUEST_TYPE_DESCRIBE, name, lang, uid);
    71         metadata_message.appendChild(metadata_request);
    72     }
    73 
    74     Element metadata_response = (Element)this.mr.process(metadata_message);
    75 
    76     NodeList coll_responses = metadata_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
    77     // check that have same number of responses as collections
    78     if (colls.getLength() != coll_responses.getLength()) {
    79         System.err.println("PageAction Error: didn't get a response for each collection - somethings gone wrong!");
    80         // for now, dont use the metadata
    81     } else {
    82         for (int i=0; i<colls.getLength(); i++) {
    83         Element c1 = (Element)colls.item(i);
    84         Element c2 = (Element)coll_responses.item(i);
    85         if (c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.FROM_ATT))) {
    86             //add the collection data into the original response
    87             GSXML.mergeElements(c1, (Element)GSXML.getChildByTagName(c2, GSXML.COLLECTION_ELEM));
    88         } else {
    89             System.err.println("PageAction Error: response does not correspond to request!");
    90         }
     68    Element collection_list = (Element)GSXML.getChildByTagName(info_response, GSXML.COLLECTION_ELEM+GSXML.LIST_MODIFIER);
     69    if (collection_list != null) {
     70        NodeList colls = GSXML.getChildrenByTagName(collection_list, GSXML.COLLECTION_ELEM);
     71        if (colls.getLength()>0) {
     72        sendMultipleRequests(colls, null, GSXML.REQUEST_TYPE_DESCRIBE, lang, uid);
     73        }
     74    }
     75
     76    // get metadata for any services
     77    Element service_list = (Element)GSXML.getChildByTagName(info_response, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
     78    if (service_list != null) {
     79        NodeList services = GSXML.getChildrenByTagName(service_list, GSXML.SERVICE_ELEM);
     80        if (services.getLength() > 0) {
     81        sendMultipleRequests(services, null, GSXML.REQUEST_TYPE_DESCRIBE, lang, uid);
     82        }
     83    }
     84
     85    // get metadata for service clusters
     86    Element cluster_list = (Element)GSXML.getChildByTagName(info_response, GSXML.CLUSTER_ELEM+GSXML.LIST_MODIFIER);
     87    if (cluster_list != null) {
     88        NodeList clusters = GSXML.getChildrenByTagName(cluster_list, GSXML.CLUSTER_ELEM);
     89        if (clusters.getLength() > 0) {
     90        sendMultipleRequests(clusters, null, GSXML.REQUEST_TYPE_DESCRIBE, lang, uid);
    9191       
    9292        }
    9393    }
    9494   
    95     //now the full response message is in coll_list_response
    96     // return the response element
    97     Element response = (Element) GSXML.getChildByTagName(coll_list_response, GSXML.RESPONSE_ELEM);
    98     return response;
     95    // all the components have been merged into info_response
     96    return info_response;
    9997   
    10098    } // homePage
     
    130128    // but for now, we'll just get it all
    131129    NodeList services = coll_about_response.getElementsByTagName(GSXML.SERVICE_ELEM);
    132     // we will send all the requests in a single message
    133     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);
    136         String name = c.getAttribute(GSXML.NAME_ATT);
    137         String address = GSPath.appendLink(coll_name, name);
    138         Element info_request = GSXML.createBasicRequest(this.doc,  GSXML.REQUEST_TYPE_DESCRIBE, address, lang, uid);
    139         info_message.appendChild(info_request);
    140     }
    141 
    142     Element info_response = (Element)this.mr.process(info_message);
    143 
    144     NodeList service_responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
    145     // check that have same number of responses as collections
    146     if (services.getLength() != service_responses.getLength()) {
    147         System.err.println("PageAction Error: didn't get a response for each service - somethings gone wrong!");
    148         // for now, dont use the metadata
    149     } else {
    150         for (int i=0; i<services.getLength(); i++) {
    151         Element c1 = (Element)services.item(i);
    152         Element c2 = (Element)GSXML.getChildByTagName((Element)service_responses.item(i), GSXML.SERVICE_ELEM);
    153         if (c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT))) {
    154             //add the service data into the original response
    155             GSXML.mergeElements(c1, c2);
    156         } else {
    157             System.err.println("PageAction Error: response does not correspond to request!");
    158         }
    159        
    160         }
    161     }
    162    
    163     //now the full response message is in coll_list_response
    164     // return the response element
     130    if (services.getLength() > 0) {
     131        sendMultipleRequests(services, coll_name, GSXML.REQUEST_TYPE_DESCRIBE, lang, uid);
     132    }
     133   
    165134    Element response = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM);
    166135    return response;
     
    200169    Element coll_about_response = (Element)this.mr.process(coll_about_message);
    201170
    202     // add the response to the page get teh response element and return it
    203171    Element response = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM);
    204172    return response;
    205173   
    206174    }
     175
     176
     177    protected boolean sendMultipleRequests(NodeList items, String path_prefix, String request_type, String lang, String uid) {
     178
     179    // we will send all the requests in a single message
     180    Element message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     181    for (int i=0; i<items.getLength(); i++) {
     182        Element c = (Element)items.item(i);
     183        String path = c.getAttribute(GSXML.NAME_ATT);       
     184        if (path_prefix != null) {
     185        path = GSPath.appendLink(path_prefix, path);
     186        }
     187        Element request = GSXML.createBasicRequest(this.doc, request_type, path, lang, uid);
     188        message.appendChild(request);
     189    }
     190   
     191    Element response_message = (Element)this.mr.process(message);
     192       
     193    NodeList responses = response_message.getElementsByTagName(GSXML.RESPONSE_ELEM);
     194    // check that have same number of responses as requests
     195    if (items.getLength() != responses.getLength()) {
     196        System.err.println("PageAction Error: didn't get a response for each request - somethings gone wrong!");
     197        return false;
     198    }
     199   
     200    for (int i=0; i<items.getLength(); i++) {
     201        Element c1 = (Element)items.item(i);
     202        Element c2 = (Element)GSXML.getChildByTagName((Element)responses.item(i), c1.getTagName());
     203        if (c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT))) {
     204        //add the new data into the original element
     205        GSXML.mergeElements(c1, c2);
     206        } else {
     207        System.err.println("PageAction Error: response does not correspond to request!");
     208        }
     209       
     210    }
     211   
     212    return true;
     213   
     214    }
    207215}
Note: See TracChangeset for help on using the changeset viewer.