Changeset 32996

Show
Ignore:
Timestamp:
09.04.2019 09:59:11 (6 months ago)
Author:
kjdon
Message:

re-indented the code

Files:
1 modified

Legend:

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

    r32991 r32996  
    2020{ 
    2121   
    22     static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.PageAction.class.getName()); 
    23  
    24         public static final String HOME_PAGE = "home"; 
    25     public static final String ABOUT_PAGE = "about"; 
    26     public static final String PREFS_PAGE = "pref"; 
    27     public static final String GLI4GS3_PAGE = "gli4gs3"; 
     22  static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.PageAction.class.getName()); 
     23 
     24  public static final String HOME_PAGE = "home"; 
     25  public static final String ABOUT_PAGE = "about"; 
     26  public static final String PREFS_PAGE = "pref"; 
     27  public static final String GLI4GS3_PAGE = "gli4gs3"; 
    2828  public static final String VERIFY_PAGE = "verify"; 
    2929 
     
    3131  protected String groupInfoServiceName = null; 
    3232 
    33     public Node process(Node message_node) 
     33  public Node process(Node message_node) 
    3434     
    35     { 
    36         Element message = GSXML.nodeToElement(message_node); 
    37         Document doc = XMLConverter.newDOM(); 
     35  { 
     36    Element message = GSXML.nodeToElement(message_node); 
     37    Document doc = XMLConverter.newDOM(); 
    3838         
    39         Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 
    40         Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
    41         String collection = ""; 
    42         if (paramList != null) 
    43         { 
    44             HashMap<String, Serializable> params = GSXML.extractParams(paramList, false); 
    45             if (params != null && params.get(GSParams.COLLECTION) != null) 
    46             { 
    47                 collection = (String) params.get(GSParams.COLLECTION); 
    48             } 
    49         } 
    50  
    51         // the page name is the subaction 
    52         String page_name = request.getAttribute(GSXML.SUBACTION_ATT); 
    53         if (page_name.equals("")) 
    54         { // if no page specified, assume home page 
    55             page_name = HOME_PAGE; 
    56         } 
    57  
    58         Element result = doc.createElement(GSXML.MESSAGE_ELEM); 
    59         Element response; 
    60         if (page_name.equals(HOME_PAGE)) 
    61         { 
    62           response = homePage(request); 
     39    Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 
     40    Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     41    String collection = ""; 
     42    if (paramList != null) 
     43      { 
     44    HashMap<String, Serializable> params = GSXML.extractParams(paramList, false); 
     45    if (params != null && params.get(GSParams.COLLECTION) != null) 
     46      { 
     47        collection = (String) params.get(GSParams.COLLECTION); 
     48      } 
     49      } 
     50 
     51    // the page name is the subaction 
     52    String page_name = request.getAttribute(GSXML.SUBACTION_ATT); 
     53    if (page_name.equals("")) 
     54      { // if no page specified, assume home page 
     55    page_name = HOME_PAGE; 
     56      } 
     57 
     58    Element result = doc.createElement(GSXML.MESSAGE_ELEM); 
     59    Element response; 
     60    if (page_name.equals(HOME_PAGE)) 
     61      { 
     62    response = homePage(request); 
    6363             
    64         } 
    65         else if (page_name.equals(GLI4GS3_PAGE)) 
    66         { 
    67           response = gli4gs3Page(request); 
    68         } else  if (collection.equals("")) { 
    69           // we are not in a collection. eg could be library prefs or other page 
    70           response = generalLibraryPage(request, page_name); 
    71         } else { 
    72           // we are in a collection 
    73           response = collectionPage(request, page_name, collection); 
    74         } 
    75          
    76  
    77         result.appendChild(doc.importNode(response, true)); 
    78         logger.debug("page action result: " + this.converter.getPrettyString(result)); 
    79  
    80         return result; 
    81     } 
     64      } 
     65    else if (page_name.equals(GLI4GS3_PAGE)) 
     66      { 
     67    response = gli4gs3Page(request); 
     68      } else    if (collection.equals("")) { 
     69      // we are not in a collection. eg could be library prefs or other page 
     70      response = generalLibraryPage(request, page_name); 
     71    } else { 
     72      // we are in a collection 
     73      response = collectionPage(request, page_name, collection); 
     74    } 
     75         
     76 
     77    result.appendChild(doc.importNode(response, true)); 
     78    logger.debug("page action result: " + this.converter.getPrettyString(result)); 
     79 
     80    return result; 
     81  } 
    8282 
    8383  // A general library page just adds site metadata and interface options. 
     
    173173 
    174174  protected Element homePage(Element request) 
    175     { 
    176       Document doc = XMLConverter.newDOM(); 
    177  
    178         UserContext userContext = new UserContext(request); 
    179         // first, get the message router info 
    180         Element info_message = doc.createElement(GSXML.MESSAGE_ELEM); 
    181         Element info_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext); 
    182         //Create param list 
    183         Element param_list_element = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
    184         info_request.appendChild(param_list_element); 
    185         //Describe params without collectionlist. Collectionlist provided by CollectionGroup service 
    186         GSXML.addParameterToList(param_list_element, GSXML.SUBSET_PARAM, GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER); 
    187         GSXML.addParameterToList(param_list_element, GSXML.SUBSET_PARAM, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 
    188         GSXML.addParameterToList(param_list_element, GSXML.SUBSET_PARAM, GSXML.SITE_ELEM + GSXML.LIST_MODIFIER); 
    189         GSXML.addParameterToList(param_list_element, GSXML.SUBSET_PARAM, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 
    190         GSXML.addParameterToList(param_list_element, GSXML.SUBSET_PARAM, GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER); 
    191         info_message.appendChild(info_request); 
    192         //Send request to message router 
    193         Element info_response_message = (Element) this.mr.process(info_message); 
    194         //Check if it is not null 
    195         if (info_response_message == null) 
    196         { 
    197             logger.error(" couldn't query the message router!"); 
    198             return null; 
    199         } 
    200         //Check if it is not null 
    201         Element info_response = (Element) GSXML.getChildByTagName(info_response_message, GSXML.RESPONSE_ELEM); 
    202         if (info_response == null) 
    203         { 
    204             logger.error("couldn't query the message router!"); 
    205             return null; 
    206         } 
    207  
    208         // import it into our current doc. 
    209         info_response = (Element) doc.importNode(info_response, true); 
    210          
    211         Element resp_service_list = (Element) GSXML.getChildByTagName(info_response, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 
    212  
    213         // TODO - is this true? can we run with no MR services? can't we still query for the collections/MR info? 
    214         if (resp_service_list == null) { 
    215             logger.error("No services available. Couldn't query the message router!"); 
    216             return null; 
    217         } 
    218  
    219         // if we haven't done so already, check for group info type service 
    220         if (this.groupInfoServiceName ==  null) { 
    221  
    222           Element groupInfoService = GSXML.getNamedElement(resp_service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, 
    223                                    CollectionGroups.GROUP_CONTENT); 
     175  { 
     176    Document doc = XMLConverter.newDOM(); 
     177 
     178    UserContext userContext = new UserContext(request); 
     179    // first, get the message router info 
     180    Element info_message = doc.createElement(GSXML.MESSAGE_ELEM); 
     181    Element info_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext); 
     182    //Create param list 
     183    Element param_list_element = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     184    info_request.appendChild(param_list_element); 
     185    //Describe params without collectionlist. Collectionlist provided by CollectionGroup service 
     186    GSXML.addParameterToList(param_list_element, GSXML.SUBSET_PARAM, GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER); 
     187    GSXML.addParameterToList(param_list_element, GSXML.SUBSET_PARAM, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 
     188    GSXML.addParameterToList(param_list_element, GSXML.SUBSET_PARAM, GSXML.SITE_ELEM + GSXML.LIST_MODIFIER); 
     189    GSXML.addParameterToList(param_list_element, GSXML.SUBSET_PARAM, GSXML.METADATA_ELEM + GSXML.LIST_MODIFIER); 
     190    GSXML.addParameterToList(param_list_element, GSXML.SUBSET_PARAM, GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER); 
     191    info_message.appendChild(info_request); 
     192    //Send request to message router 
     193    Element info_response_message = (Element) this.mr.process(info_message); 
     194    //Check if it is not null 
     195    if (info_response_message == null) 
     196      { 
     197    logger.error(" couldn't query the message router!"); 
     198    return null; 
     199      } 
     200    //Check if it is not null 
     201    Element info_response = (Element) GSXML.getChildByTagName(info_response_message, GSXML.RESPONSE_ELEM); 
     202    if (info_response == null) 
     203      { 
     204    logger.error("couldn't query the message router!"); 
     205    return null; 
     206      } 
     207 
     208    // import it into our current doc. 
     209    info_response = (Element) doc.importNode(info_response, true); 
     210         
     211    Element resp_service_list = (Element) GSXML.getChildByTagName(info_response, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 
     212 
     213    // TODO - is this true? can we run with no MR services? can't we still query for the collections/MR info? 
     214    if (resp_service_list == null) { 
     215      logger.error("No services available. Couldn't query the message router!"); 
     216      return null; 
     217    } 
     218 
     219    // if we haven't done so already, check for group info type service 
     220    if (this.groupInfoServiceName ==  null) { 
     221 
     222      Element groupInfoService = GSXML.getNamedElement(resp_service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, 
     223                               CollectionGroups.GROUP_CONTENT); 
    224224           
    225           if (groupInfoService != null) { 
    226             this.groupInfoServiceName = CollectionGroups.GROUP_CONTENT;  
    227           } else { 
    228             this.groupInfoServiceName = "NO_GROUPS"; 
    229           } 
    230         } 
    231          
    232         if (!this.groupInfoServiceName.equals("NO_GROUPS")) { 
    233           String group = null; 
    234           Element cgi_paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
    235           HashMap<String, Serializable> params = GSXML.extractParams(cgi_paramList, false); 
    236           if (params != null) { 
    237             group = (String) params.get(GSParams.GROUP); 
    238             if (group != null && group.equals("")) { 
    239               group = null; 
    240             } 
    241           } 
     225      if (groupInfoService != null) { 
     226    this.groupInfoServiceName = CollectionGroups.GROUP_CONTENT;  
     227      } else { 
     228    this.groupInfoServiceName = "NO_GROUPS"; 
     229      } 
     230    } 
     231         
     232    if (!this.groupInfoServiceName.equals("NO_GROUPS")) { 
     233      String group = null; 
     234      Element cgi_paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     235      HashMap<String, Serializable> params = GSXML.extractParams(cgi_paramList, false); 
     236      if (params != null) { 
     237    group = (String) params.get(GSParams.GROUP); 
     238    if (group != null && group.equals("")) { 
     239      group = null; 
     240    } 
     241      } 
    242242           
    243           Element group_info_response = getGroupInfo(group, userContext); 
    244  
    245           // Add all the needed parts of the response to the main page response 
    246           Element collection_list = (Element) GSXML.getChildByTagName(group_info_response, 
    247                                           GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 
     243      Element group_info_response = getGroupInfo(group, userContext); 
     244 
     245      // Add all the needed parts of the response to the main page response 
     246      Element collection_list = (Element) GSXML.getChildByTagName(group_info_response, 
     247                                  GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 
    248248             
    249           if (collection_list != null) { 
    250             info_response.appendChild(doc.importNode(collection_list, true)); 
    251           } else { 
    252             logger.warn("Home page had no collection list"); 
    253           } 
    254           Element group_list = (Element) GSXML.getChildByTagName(group_info_response, 
    255                                     GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER); 
    256           if (group_list != null) { 
    257             info_response.appendChild(doc.importNode(group_list, true)); 
    258           } 
    259           Element path_list = (Element) GSXML.getChildByTagName(group_info_response, 
    260                                     GSXML.PATH_ELEM + GSXML.LIST_MODIFIER); 
    261           if (path_list != null) { 
    262             info_response.appendChild(doc.importNode(path_list, true)); 
    263           } 
     249      if (collection_list != null) { 
     250    info_response.appendChild(doc.importNode(collection_list, true)); 
     251      } else { 
     252    logger.warn("Home page had no collection list"); 
     253      } 
     254      Element group_list = (Element) GSXML.getChildByTagName(group_info_response, 
     255                                GSXML.GROUP_ELEM + GSXML.LIST_MODIFIER); 
     256      if (group_list != null) { 
     257    info_response.appendChild(doc.importNode(group_list, true)); 
     258      } 
     259      Element path_list = (Element) GSXML.getChildByTagName(group_info_response, 
     260                                GSXML.PATH_ELEM + GSXML.LIST_MODIFIER); 
     261      if (path_list != null) { 
     262    info_response.appendChild(doc.importNode(path_list, true)); 
     263      } 
    264264           
    265         } else { 
     265    } else { 
    266266           
    267             // If no service with type SERVICE_TYPE_GROUPINFO could be provided 
    268             // request message router for all available collections 
    269             GSXML.addParameterToList(param_list_element, GSXML.SUBSET_PARAM, 
    270                     GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 
    271             info_response_message = (Element) this.mr.process(info_message); 
    272  
    273             if (info_response_message == null) { 
    274                 logger.error(" couldn't query the message router!"); 
    275                 return null; 
    276             } 
    277             info_response = (Element) GSXML.getChildByTagName(info_response_message, GSXML.RESPONSE_ELEM); 
    278             if (info_response == null) { 
    279                 logger.error("couldn't query the message router!"); 
    280                 return null; 
    281             } 
    282         } 
    283  
    284         // second, get the metadata for each collection - we only want specific 
    285         // elements but for now, we'll just get it all 
    286         Element collection_list = (Element) GSXML.getChildByTagName(info_response, GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 
    287         if (collection_list != null) 
    288         { 
    289             NodeList colls = GSXML.getChildrenByTagName(collection_list, GSXML.COLLECTION_ELEM); 
    290             if (colls.getLength() > 0) 
    291             { 
    292                 sendMultipleRequests(doc, colls, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext); 
    293             } 
    294         }  
    295  
    296         // get metadata for any services 
    297         Element service_list = (Element) GSXML.getChildByTagName(info_response, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 
    298         if (service_list != null) 
    299         { 
    300             NodeList services = GSXML.getChildrenByTagName(service_list, GSXML.SERVICE_ELEM); 
    301             if (services.getLength() > 0) 
    302             { 
    303                 sendMultipleRequests(doc, services, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext); 
    304             } 
    305         } 
    306  
    307         // get metadata for service clusters 
    308         Element cluster_list = (Element) GSXML.getChildByTagName(info_response, GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER); 
    309         if (cluster_list != null) 
    310         { 
    311             NodeList clusters = GSXML.getChildrenByTagName(cluster_list, GSXML.CLUSTER_ELEM); 
    312             if (clusters.getLength() > 0) 
    313             { 
    314                 sendMultipleRequests(doc, clusters, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext); 
    315  
    316             } 
    317         } 
    318  
    319         addSiteMetadata(info_response, userContext); 
    320         addInterfaceOptions(info_response); 
    321         // all the components have been merged into info_response 
    322         return info_response; 
    323  
    324     } // homePage 
     267      // If no service with type SERVICE_TYPE_GROUPINFO could be provided 
     268      // request message router for all available collections 
     269      GSXML.addParameterToList(param_list_element, GSXML.SUBSET_PARAM, 
     270                   GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 
     271      info_response_message = (Element) this.mr.process(info_message); 
     272 
     273      if (info_response_message == null) { 
     274    logger.error(" couldn't query the message router!"); 
     275    return null; 
     276      } 
     277      info_response = (Element) GSXML.getChildByTagName(info_response_message, GSXML.RESPONSE_ELEM); 
     278      if (info_response == null) { 
     279    logger.error("couldn't query the message router!"); 
     280    return null; 
     281      } 
     282    } 
     283 
     284    // second, get the metadata for each collection - we only want specific 
     285    // elements but for now, we'll just get it all 
     286    Element collection_list = (Element) GSXML.getChildByTagName(info_response, GSXML.COLLECTION_ELEM + GSXML.LIST_MODIFIER); 
     287    if (collection_list != null) 
     288      { 
     289    NodeList colls = GSXML.getChildrenByTagName(collection_list, GSXML.COLLECTION_ELEM); 
     290    if (colls.getLength() > 0) 
     291      { 
     292        sendMultipleRequests(doc, colls, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext); 
     293      } 
     294      }  
     295 
     296    // get metadata for any services 
     297    Element service_list = (Element) GSXML.getChildByTagName(info_response, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 
     298    if (service_list != null) 
     299      { 
     300    NodeList services = GSXML.getChildrenByTagName(service_list, GSXML.SERVICE_ELEM); 
     301    if (services.getLength() > 0) 
     302      { 
     303        sendMultipleRequests(doc, services, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext); 
     304      } 
     305      } 
     306 
     307    // get metadata for service clusters 
     308    Element cluster_list = (Element) GSXML.getChildByTagName(info_response, GSXML.CLUSTER_ELEM + GSXML.LIST_MODIFIER); 
     309    if (cluster_list != null) 
     310      { 
     311    NodeList clusters = GSXML.getChildrenByTagName(cluster_list, GSXML.CLUSTER_ELEM); 
     312    if (clusters.getLength() > 0) 
     313      { 
     314        sendMultipleRequests(doc, clusters, null, GSXML.REQUEST_TYPE_DESCRIBE, userContext); 
     315 
     316      } 
     317      } 
     318 
     319    addSiteMetadata(info_response, userContext); 
     320    addInterfaceOptions(info_response); 
     321    // all the components have been merged into info_response 
     322    return info_response; 
     323 
     324  } // homePage 
    325325 
    326326  /** sends a request to GroupCurrentContent service to get group info. null group will give top level info, 
     
    368368  } 
    369369 
    370     protected boolean sendMultipleRequests(Document doc, NodeList items, String path_prefix, String request_type, UserContext userContext) 
    371     { 
    372         // we will send all the requests in a single message 
    373         Element message = doc.createElement(GSXML.MESSAGE_ELEM); 
    374         for (int i = 0; i < items.getLength(); i++) 
    375         { 
    376             Element c = (Element) items.item(i); 
    377             String path = c.getAttribute(GSXML.NAME_ATT); 
    378             if (path_prefix != null) 
    379             { 
    380                 path = GSPath.appendLink(path_prefix, path); 
    381             } 
    382             Element request = GSXML.createBasicRequest(doc, request_type, path, userContext); 
    383             message.appendChild(request); 
    384         } 
    385  
    386         Element response_message = (Element) this.mr.process(message); 
    387  
    388         NodeList responses = response_message.getElementsByTagName(GSXML.RESPONSE_ELEM); 
    389         // check that have same number of responses as requests 
    390         if (items.getLength() != responses.getLength()) 
    391         { 
    392             logger.error("didn't get a response for each request - somethings gone wrong!"); 
    393             return false; 
    394         } 
    395  
    396         for (int i = 0; i < items.getLength(); i++) 
    397         { 
    398             Element c1 = (Element) items.item(i); 
    399             Element c2 = (Element) GSXML.getChildByTagName((Element) responses.item(i), c1.getTagName()); 
    400             if (c1 != null && c2 != null && c1.getAttribute(GSXML.NAME_ATT).endsWith(c2.getAttribute(GSXML.NAME_ATT))) 
    401             { 
    402                 //add the new data into the original element 
    403                 GSXML.mergeElements(c1, c2); 
    404             } 
    405             else 
    406             { 
    407                 logger.debug(" response does not correspond to request!"); 
    408             } 
    409  
    410         } 
    411  
    412         return true; 
    413  
    414     } 
    415  
    416     protected Element gli4gs3Page(Element request) 
    417     { 
    418       Document doc = XMLConverter.newDOM(); 
    419          
    420         String lang = request.getAttribute(GSXML.LANG_ATT); 
    421         String uid = request.getAttribute(GSXML.USER_ID_ATT); 
    422  
    423         Element page_response = doc.createElement(GSXML.RESPONSE_ELEM); 
    424  
    425         Element applet_elem = doc.createElement("Applet"); 
    426         page_response.appendChild(applet_elem); 
    427         applet_elem.setAttribute("ARCHIVE", "SignedGatherer.jar"); // SignedGatherer.jar should be placed in web/applet.  
    428         applet_elem.setAttribute("CODE", "org.greenstone.gatherer.WebGatherer"); 
    429         applet_elem.setAttribute("CODEBASE", "applet"); // SignedGatherer.jar is in web/applet. But CODEBASE is the *URL* path to the (jar) file containing the main class, and is relative to documentroot "web". 
    430         applet_elem.setAttribute("HEIGHT", "50"); 
    431         applet_elem.setAttribute("WIDTH", "380"); 
    432          
    433         Element gwcgi_param_elem = doc.createElement("PARAM"); 
    434         gwcgi_param_elem.setAttribute("name", "gwcgi"); 
    435         String library_name = GlobalProperties.getGSDL3WebAddress(); 
    436         gwcgi_param_elem.setAttribute("value", library_name); 
    437         applet_elem.appendChild(gwcgi_param_elem); 
    438  
    439         Element gsdl3_param_elem = doc.createElement("PARAM"); 
    440         gsdl3_param_elem.setAttribute("name", "gsdl3"); 
    441         gsdl3_param_elem.setAttribute("value", "true"); 
    442         applet_elem.appendChild(gsdl3_param_elem); 
     370  protected boolean sendMultipleRequests(Document doc, NodeList items, String path_prefix, String request_type, UserContext userContext) 
     371  { 
     372    // we will send all the requests in a single message 
     373    Element message = doc.createElement(GSXML.MESSAGE_ELEM); 
     374    for (int i = 0; i < items.getLength(); i++) 
     375      { 
     376    Element c = (Element) items.item(i); 
     377    String path = c.getAttribute(GSXML.NAME_ATT); 
     378    if (path_prefix != null) 
     379      { 
     380        path = GSPath.appendLink(path_prefix, path); 
     381      } 
     382    Element request = GSXML.createBasicRequest(doc, request_type, path, userContext); 
     383    message.appendChild(request); 
     384      } 
     385 
     386    Element response_message = (Element) this.mr.process(message); 
     387 
     388    NodeList responses = response_message.getElementsByTagName(GSXML.RESPONSE_ELEM); 
     389    // check that have same number of responses as requests 
     390    if (items.getLength() != responses.getLength()) 
     391      { 
     392    logger.error("didn't get a response for each request - somethings gone wrong!"); 
     393    return false; 
     394      } 
     395 
     396    for (int i = 0; i < items.getLength(); i++) 
     397      { 
     398    Element c1 = (Element) items.item(i); 
     399    Element c2 = (Element) GSXML.getChildByTagName((Element) responses.item(i), c1.getTagName()); 
     400    if (c1 != null && c2 != null && c1.getAttribute(GSXML.NAME_ATT).endsWith(c2.getAttribute(GSXML.NAME_ATT))) 
     401      { 
     402        //add the new data into the original element 
     403        GSXML.mergeElements(c1, c2); 
     404      } 
     405    else 
     406      { 
     407        logger.debug(" response does not correspond to request!"); 
     408      } 
     409 
     410      } 
     411 
     412    return true; 
     413 
     414  } 
     415 
     416  protected Element gli4gs3Page(Element request) 
     417  { 
     418    Document doc = XMLConverter.newDOM(); 
     419         
     420    String lang = request.getAttribute(GSXML.LANG_ATT); 
     421    String uid = request.getAttribute(GSXML.USER_ID_ATT); 
     422 
     423    Element page_response = doc.createElement(GSXML.RESPONSE_ELEM); 
     424 
     425    Element applet_elem = doc.createElement("Applet"); 
     426    page_response.appendChild(applet_elem); 
     427    applet_elem.setAttribute("ARCHIVE", "SignedGatherer.jar"); // SignedGatherer.jar should be placed in web/applet.  
     428    applet_elem.setAttribute("CODE", "org.greenstone.gatherer.WebGatherer"); 
     429    applet_elem.setAttribute("CODEBASE", "applet"); // SignedGatherer.jar is in web/applet. But CODEBASE is the *URL* path to the (jar) file containing the main class, and is relative to documentroot "web". 
     430    applet_elem.setAttribute("HEIGHT", "50"); 
     431    applet_elem.setAttribute("WIDTH", "380"); 
     432         
     433    Element gwcgi_param_elem = doc.createElement("PARAM"); 
     434    gwcgi_param_elem.setAttribute("name", "gwcgi"); 
     435    String library_name = GlobalProperties.getGSDL3WebAddress(); 
     436    gwcgi_param_elem.setAttribute("value", library_name); 
     437    applet_elem.appendChild(gwcgi_param_elem); 
     438 
     439    Element gsdl3_param_elem = doc.createElement("PARAM"); 
     440    gsdl3_param_elem.setAttribute("name", "gsdl3"); 
     441    gsdl3_param_elem.setAttribute("value", "true"); 
     442    applet_elem.appendChild(gsdl3_param_elem); 
    443443                 
    444         // When an applet doesn't work in the browser, set the default display text to provide a link to the JNLP file to run with Java Web Start 
    445         // The display text will be: 
    446         //      Applets don't seem to work in your browser. In place of the GLI Applet, try running its alternative <a href="applet/GLIappWebStart.jnlp">Java Web Start (JNLP) version</a> 
    447         Node default_text = doc.createTextNode("Applets don't seem to work in your browser. In place of the GLI Applet, try running its alternative "); 
    448         Element link_to_jnlp = doc.createElement("a"); 
    449         link_to_jnlp.setAttribute("href", "applet/GLIappWebStart.jnlp"); 
    450         Node anchor_text = doc.createTextNode("Java Web Start (JNLP) version"); 
    451         link_to_jnlp.appendChild(anchor_text);       
    452         applet_elem.appendChild(default_text); 
    453         applet_elem.appendChild(link_to_jnlp); 
    454          
    455         return page_response; 
    456     } 
     444    // When an applet doesn't work in the browser, set the default display text to provide a link to the JNLP file to run with Java Web Start 
     445    // The display text will be: 
     446    //      Applets don't seem to work in your browser. In place of the GLI Applet, try running its alternative <a href="applet/GLIappWebStart.jnlp">Java Web Start (JNLP) version</a> 
     447    Node default_text = doc.createTextNode("Applets don't seem to work in your browser. In place of the GLI Applet, try running its alternative "); 
     448    Element link_to_jnlp = doc.createElement("a"); 
     449    link_to_jnlp.setAttribute("href", "applet/GLIappWebStart.jnlp"); 
     450    Node anchor_text = doc.createTextNode("Java Web Start (JNLP) version"); 
     451    link_to_jnlp.appendChild(anchor_text);       
     452    applet_elem.appendChild(default_text); 
     453    applet_elem.appendChild(link_to_jnlp); 
     454         
     455    return page_response; 
     456  } 
    457457}