Ignore:
Timestamp:
2003-03-26T12:12:10+12:00 (21 years ago)
Author:
kjdon
Message:

now gets the collection info if a collection is specified - this is needed for the httpPath metadata used to find the coll image

File:
1 edited

Legend:

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

    r3948 r3996  
    1818    public Element process (Element message) {
    1919   
    20 
    21     // find the stylesheet
    22     String stylesheet = GSFile.stylesheetFile(config_, "applet.xsl");
    23 
    24     if (stylesheet==null) {
    25         System.err.println("AppletAction Error: applet stylesheet not found!");
    26         return null;
    27     }
    28    
    2920    Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
    3021   
    31    
    32     // get the collection and service param
     22    // get the collection and service params
    3323    Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    3424    HashMap params = GSXML.extractParams(cgi_param_list, false);
     
    4030        return null;
    4131    }
    42 
     32   
    4333    String collection = (String)params.get(GSCGI.COLLECTION_ARG);
     34    boolean coll_specified = true;
    4435    String service_name=(String)params.get(GSCGI.SERVICE_ARG);
    45    
     36    String lang = request.getAttribute(GSXML.LANG_ATT);
    4637    String to=null;
    4738    if (collection==null||collection.equals("") ) {
     39        coll_specified = false;
    4840        to = service_name;
    4941    } else {
     
    5143    }
    5244
    53     if (request_type.equals("d")) {
    54         // we are just displaying the applet - get the description from
    55         // the service, and process using xslt
    56 
    57         //build up the mr request
    58    
    59         Element mr_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    60         Element mr_request = doc_.createElement(GSXML.REQUEST_ELEM);
    61         mr_message.appendChild(mr_request);
    62         mr_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
    63         mr_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
    64         mr_request.setAttribute(GSXML.TO_ATT, to);
    65        
    66         Element mr_response = (Element)mr_.process(mr_message);
    67        
    68         // create the return page tree
    69         Element page = doc_.createElement(GSXML.PAGE_ELEM);
    70         page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
    71         // add the lang stuff from message
    72         page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true));
    73         // add the config stuff from message
    74         page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
    75        
    76         page.appendChild(doc_.importNode(request, true));
    77 
    78         // add in the applet info
    79         String path = GSXML.RESPONSE_ELEM;
    80         path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
    81         path = GSPath.appendLink(path, GSXML.APPLET_ELEM);
    82         Element app_desc = (Element)doc_.importNode(GSXML.getNodeByPath(mr_response, path), true);
    83         // must handle any params that have values that are not
    84         // necessarily known by the service
    85         editLocalParams(app_desc, config_.library_name_, collection);
    86         page.appendChild(app_desc);
    87 
    88         // process using the stylesheet
    89         Document style_doc = converter_.getDOM(new File(stylesheet));
    90         GSXSLT.absoluteIncludePaths(style_doc, config_);
    91         return (Element)transformer_.transform(style_doc, page);   
    92 
    93     }
    94     else if (request_type.equals("r")) {
     45    if (request_type.equals("r")) {
    9546        // we are processing stuff for the applet send a message to the service, type="query", and take out the something element, and return that as our result - the applet must take xml
    9647
    9748        Element mr_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    98         Element mr_request = doc_.createElement(GSXML.REQUEST_ELEM);
     49        Element mr_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_PROCESS, to, lang);
    9950        mr_message.appendChild(mr_request);
    100         mr_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
    101         mr_request.setAttribute(GSXML.TO_ATT, to);
    102         mr_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
    103 
    104         // just append the params for now
     51        // just append all the params for now - should filter out unneeded ones
    10552        mr_request.appendChild(doc_.importNode(cgi_param_list, true));
    106        
     53       
     54        // process the request
    10755        Element mr_response = (Element)mr_.process(mr_message);
    108         // add in the applet data
    109         String path = GSXML.RESPONSE_ELEM;
    110         path = GSPath.appendLink(path, GSXML.APPLET_DATA_ELEM);
     56        // get the applet data out and pass it back as is.
     57        String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.APPLET_DATA_ELEM);
    11158        Element applet_info = (Element)GSXML.getNodeByPath(mr_response, path).getFirstChild();
    11259        return applet_info;
     60       
     61    }
     62   
     63    // else request type  = 'd'
     64    // find the stylesheet
     65    String stylesheet = GSFile.stylesheetFile(config_, "applet.xsl");
     66   
     67    if (stylesheet==null) {
     68        System.err.println("AppletAction Error: applet stylesheet not found!");
     69        return null;
     70    }
     71 
     72    // we are just displaying the applet - get the description from
     73    // the service, and process using xslt
     74   
     75   
     76    // create the return page tree
     77    Element page = doc_.createElement(GSXML.PAGE_ELEM);
     78    page.setAttribute(GSXML.LANG_ATT, lang);
     79    // add the lang stuff from message
     80    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true));
     81    // add the config stuff from message
     82    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
    11383
     84    // add in the page Request
     85    Element page_request = GSXML.duplicateWithNewName(doc_, request, "pageRequest", true);
     86    page.appendChild(page_request);
     87
     88    // get the applet description, and the collection info if a collection is specified
     89
     90    Element mr_message = doc_.createElement(GSXML.MESSAGE_ELEM);
     91    Element applet_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_DESCRIBE, to, lang);
     92    mr_message.appendChild(applet_request);
     93
     94    if (coll_specified) {
     95        Element coll_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_DESCRIBE, collection, lang);
     96        mr_message.appendChild(coll_request);
    11497    }
    115     // should never get here
    116     return null;
     98   
     99    Element mr_response = (Element)mr_.process(mr_message);
     100       
     101    Element page_response = doc_.createElement(GSXML.PAGE_RESPONSE_ELEM);
     102    page.appendChild(page_response);
     103    // add in the applet info
     104    String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.SERVICE_ELEM);
     105    path = GSPath.appendLink(path, GSXML.APPLET_ELEM);
     106    Element app_desc = (Element)doc_.importNode(GSXML.getNodeByPath(mr_response, path), true);
     107    // must handle any params that have values that are not
     108    // necessarily known by the service
     109    editLocalParams(app_desc, config_.library_name_, collection);
     110    page_response.appendChild(app_desc);
     111   
     112    if (coll_specified) {
     113        Element coll_response = (Element) mr_response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1);
     114        Element coll_elem = (Element)GSXML.getChildByTagName(coll_response, GSXML.COLLECTION_ELEM);
     115        page_response.appendChild(doc_.importNode(coll_elem, true));
     116    }
     117   
     118    // process using the stylesheet
     119    Document style_doc = converter_.getDOM(new File(stylesheet));
     120    GSXSLT.absoluteIncludePaths(style_doc, config_);
     121    return (Element)transformer_.transform(style_doc, page);   
     122   
    117123    }
    118124
    119125    /** this method looks through the PARAMs of the applet description for
    120      * one with the name 'library'. If its found, it sets the value to be
    121      * library_name
     126     * 'library' or 'collection'. If found, the params are set to
     127     * the appropriate values
    122128     */
    123129    protected void editLocalParams(Element description, String library_name,
Note: See TracChangeset for help on using the changeset viewer.