Changeset 24865


Ignore:
Timestamp:
2011-12-06T13:16:48+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/action/GeneralAction.java

    r22135 r24865  
    33import org.greenstone.gsdl3.util.*;
    44// XML classes
    5 import org.w3c.dom.Node; 
    6 import org.w3c.dom.Element; 
     5import org.w3c.dom.Node;
     6import org.w3c.dom.Element;
    77
    88import java.util.HashMap;
    99
    10 public class GeneralAction extends Action {
    11    
    12     /** process a request */
    13     public Node process (Node message_node) {
     10public class GeneralAction extends Action
     11{
     12    /** process a request */
     13    public Node process(Node message_node)
     14    {
     15        Element message = this.converter.nodeToElement(message_node);
    1416
    15     Element message = this.converter.nodeToElement(message_node);
     17        // the result
     18        Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
     19        Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
     20        result.appendChild(page_response);
    1621
    17     // the result
    18     Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
    19     Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
    20     result.appendChild(page_response);
     22        // assume only one request
     23        Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
     24        logger.debug(" request=" + this.converter.getString(request));
    2125
    22     // assume only one request
    23     Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
    24     logger.debug(" request="+this.converter.getString(request));
     26        String lang = request.getAttribute(GSXML.LANG_ATT);
     27        String uid = request.getAttribute(GSXML.USER_ID_ATT);
    2528
    26     String lang = request.getAttribute(GSXML.LANG_ATT);
    27     String uid = request.getAttribute(GSXML.USER_ID_ATT);
     29        // get the param list
     30        Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     31        HashMap params = GSXML.extractParams(cgi_param_list, false);
     32        String service_name = (String) params.get(GSParams.SERVICE);
     33        String cluster_name = (String) params.get(GSParams.CLUSTER);
     34        String response_only_p = (String) params.get(GSParams.RESPONSE_ONLY);
     35        boolean response_only = false;
     36        if (response_only_p != null)
     37        {
     38            response_only = (response_only_p.equals("1") ? true : false);
     39        }
     40        String request_type = (String) params.get(GSParams.REQUEST_TYPE);
     41        // what is carried out depends on the request_type
     42        // if rt=d, then a describe request is done,
     43        // is rt=r, a request and then a describe request is done
     44        // if rt=s, a status request is done.
    2845
    29     // get the param list
    30     Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    31     HashMap params = GSXML.extractParams(cgi_param_list, false);
    32     String service_name = (String) params.get(GSParams.SERVICE);
    33     String cluster_name = (String) params.get(GSParams.CLUSTER);
    34     String response_only_p = (String)params.get(GSParams.RESPONSE_ONLY);
    35     boolean response_only = false;
    36     if (response_only_p!=null) {
    37         response_only = (response_only_p.equals("1")?true:false);
    38     }
    39     String request_type = (String) params.get(GSParams.REQUEST_TYPE);
    40     // what is carried out depends on the request_type
    41     // if rt=d, then a describe request is done,
    42     // is rt=r, a request and then a describe request is done
    43     // if rt=s, a status request is done.
     46        // if ro=1, then this calls for a process only page - we do the request
     47        // (rt should be r or s) and just give the response straight back
     48        // without any page processing
    4449
    45     // if ro=1, then this calls for a process only page - we do the request
    46     // (rt should be r or s) and just give the response straight back
    47     // without any page processing
     50        // where to send requests
     51        String to;
     52        if (cluster_name != null)
     53        {
     54            to = GSPath.appendLink(cluster_name, service_name);
     55        }
     56        else
     57        {
     58            to = service_name;
     59        }
    4860
     61        if (request_type.equals("r"))
     62        {
     63            //do the request
    4964
    50     // where to send requests
    51     String to;
    52     if (cluster_name != null) {
    53         to = GSPath.appendLink(cluster_name, service_name);
    54     } else {
    55         to = service_name;
     65            Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     66            Element mr_query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
     67
     68            mr_query_message.appendChild(mr_query_request);
     69
     70            Element param_list = null;
     71            // add in the service params - except the ones only used by the action
     72            HashMap service_params = (HashMap) params.get("s1");
     73            if (service_params != null)
     74            {
     75                param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     76                GSXML.addParametersToList(this.doc, param_list, service_params);
     77                mr_query_request.appendChild(param_list);
     78            }
     79
     80            Element mr_query_response = (Element) this.mr.process(mr_query_message);
     81            Element result_response = (Element) GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
     82
     83            if (response_only)
     84            {
     85                // just send the reponse as is
     86                addSiteMetadata(result_response, lang, uid);
     87                return result_response;
     88            }
     89            if (result_response != null)
     90            {
     91                // else append the contents of the response to the page
     92                GSXML.copyAllChildren(page_response, result_response);
     93            }
     94        }
     95
     96        // another part of the page is the service description
     97
     98        // request the service info for the selected service - should be cached
     99        Element mr_info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     100        Element mr_info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, uid);
     101        mr_info_message.appendChild(mr_info_request);
     102        Element mr_info_response = (Element) this.mr.process(mr_info_message);
     103
     104        String path = GSXML.RESPONSE_ELEM;
     105        path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
     106
     107        Node desNode = GSXML.getNodeByPath(mr_info_response, path);
     108        if (desNode != null)
     109        {
     110            page_response.appendChild((Element) this.doc.importNode(desNode, true));
     111        }
     112
     113        addSiteMetadata(page_response, lang, uid);
     114        return result;
    56115    }
    57116
    58     if (request_type.equals("r")) {
    59         //do the request
    60        
    61         Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    62         Element mr_query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
    63        
    64         mr_query_message.appendChild(mr_query_request);
    65        
    66         Element param_list = null;
    67         // add in the service params - except the ones only used by the action
    68         HashMap service_params = (HashMap)params.get("s1");
    69         if (service_params != null) {
    70         param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    71         GSXML.addParametersToList(this.doc, param_list, service_params);
    72         mr_query_request.appendChild(param_list);
    73         }
    74        
    75         Element mr_query_response = (Element)this.mr.process(mr_query_message);
    76         Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
    77        
    78         if (response_only) {
    79         // just send the reponse as is
    80         addSiteMetadata(result_response, lang, uid);
    81         return result_response;
    82         }
    83         if (result_response != null){
    84         // else append the contents of the response to the page
    85         GSXML.copyAllChildren(page_response, result_response);
    86         }
    87     }
    88    
    89 
    90     // another part of the page is the service description
    91 
    92     // request the service info for the selected service - should be cached
    93     Element mr_info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    94     Element mr_info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, uid);
    95     mr_info_message.appendChild(mr_info_request);
    96     Element mr_info_response = (Element) this.mr.process(mr_info_message);
    97 
    98        
    99     String path = GSXML.RESPONSE_ELEM;
    100     path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
    101    
    102 
    103     Node desNode = GSXML.getNodeByPath(mr_info_response, path);
    104     if(desNode != null){
    105         page_response.appendChild((Element)this.doc.importNode(desNode, true));
    106     }
    107 
    108     addSiteMetadata(page_response, lang, uid);
    109     return result;
    110     }
    111 
    112117}
Note: See TracChangeset for help on using the changeset viewer.