Changeset 24991

Show
Ignore:
Timestamp:
26.01.2012 11:40:18 (8 years ago)
Author:
sjm84
Message:

Reformatting this file ahead of some changes

Files:
1 modified

Legend:

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

    r16688 r24991  
    44import org.greenstone.gsdl3.util.*; 
    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 
    1111import java.util.HashMap; 
     
    1414import java.io.File; 
    1515 
    16 public class ProcessAction extends Action { 
    17      
    18     /** process a request */ 
    19     public Node process (Node message_node) { 
     16public class ProcessAction extends Action 
     17{ 
    2018 
    21     Element message = this.converter.nodeToElement(message_node); 
     19    /** process a request */ 
     20    public Node process(Node message_node) 
     21    { 
    2222 
    23     // the result 
    24     Element result = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    25     Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM); 
    26     result.appendChild(page_response); 
     23        Element message = this.converter.nodeToElement(message_node); 
    2724 
    28     // assume only one request 
    29     Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 
     25        // the result 
     26        Element result = this.doc.createElement(GSXML.MESSAGE_ELEM); 
     27        Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM); 
     28        result.appendChild(page_response); 
    3029 
    31     // get the param list 
    32     Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 
    33     HashMap params = GSXML.extractParams(cgi_param_list, false); 
    34     String service_name = (String) params.get(GSParams.SERVICE); 
    35     String cluster_name = (String) params.get(GSParams.CLUSTER); 
    36     String response_only_p = (String)params.get(GSParams.RESPONSE_ONLY); 
    37     boolean response_only = false; 
    38     if (response_only_p!=null) { 
    39         response_only = (response_only_p.equals("1")?true:false); 
    40     } 
    41     String request_type = (String) params.get(GSParams.REQUEST_TYPE); 
    42     String lang = request.getAttribute(GSXML.LANG_ATT); 
    43     String uid = request.getAttribute(GSXML.USER_ID_ATT); 
    44     // what is carried out depends on the request_type 
    45     // if rt=d, then a describe request is done, 
    46     // is rt=r, a request and then a describe request is done 
    47     // if rt=s, a status request is done. 
     30        // assume only one request 
     31        Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 
    4832 
    49     // if ro=1, then this calls for a process only page - we do the request 
    50     // (rt should be r or s) and just give the response straight back 
    51     // without any page processing 
     33        // get the param list 
     34        Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     35        HashMap params = GSXML.extractParams(cgi_param_list, false); 
     36        String service_name = (String) params.get(GSParams.SERVICE); 
     37        String cluster_name = (String) params.get(GSParams.CLUSTER); 
     38        String response_only_p = (String) params.get(GSParams.RESPONSE_ONLY); 
     39        boolean response_only = false; 
     40        if (response_only_p != null) 
     41        { 
     42            response_only = (response_only_p.equals("1") ? true : false); 
     43        } 
     44        String request_type = (String) params.get(GSParams.REQUEST_TYPE); 
     45        String lang = request.getAttribute(GSXML.LANG_ATT); 
     46        String uid = request.getAttribute(GSXML.USER_ID_ATT); 
     47        // what is carried out depends on the request_type 
     48        // if rt=d, then a describe request is done, 
     49        // is rt=r, a request and then a describe request is done 
     50        // if rt=s, a status request is done. 
    5251 
     52        // if ro=1, then this calls for a process only page - we do the request 
     53        // (rt should be r or s) and just give the response straight back 
     54        // without any page processing 
    5355 
    54     // where to send requests 
    55     String to; 
    56     if (cluster_name != null) { 
    57          
    58         to = GSPath.appendLink(cluster_name, service_name); 
    59     } else { 
    60         to = service_name; 
     56        // where to send requests 
     57        String to; 
     58        if (cluster_name != null) 
     59        { 
     60 
     61            to = GSPath.appendLink(cluster_name, service_name); 
     62        } 
     63        else 
     64        { 
     65            to = service_name; 
     66        } 
     67 
     68        if (!request_type.equals("d")) 
     69        { 
     70            // if rt=s or rt=r, do the request 
     71 
     72            Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 
     73            String request_type_att; 
     74            Element param_list = null; 
     75            if (request_type.equals("s")) 
     76            { // status 
     77                request_type_att = GSXML.REQUEST_TYPE_STATUS; 
     78                param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     79                Element param = this.doc.createElement(GSXML.PARAM_ELEM); 
     80                param.setAttribute(GSXML.NAME_ATT, GSParams.PROCESS_ID); 
     81                param.setAttribute(GSXML.VALUE_ATT, (String) params.get(GSParams.PROCESS_ID)); 
     82                param_list.appendChild(param); 
     83            } 
     84            else 
     85            { 
     86                request_type_att = GSXML.REQUEST_TYPE_PROCESS; 
     87                // add in the service params - except the ones only used by the action 
     88                HashMap service_params = (HashMap) params.get("s1"); 
     89                if (service_params != null) 
     90                { 
     91                    param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     92                    GSXML.addParametersToList(this.doc, param_list, service_params); 
     93                } 
     94 
     95            } 
     96            Element mr_query_request = GSXML.createBasicRequest(this.doc, request_type_att, to, lang, uid); 
     97            if (param_list != null) 
     98            { 
     99                mr_query_request.appendChild(param_list); 
     100            } 
     101            mr_query_message.appendChild(mr_query_request); 
     102 
     103            Element mr_query_response = (Element) this.mr.process(mr_query_message); 
     104            Element result_response = (Element) GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 
     105 
     106            if (response_only) 
     107            { 
     108                // just send the reponse as is 
     109                return result_response; 
     110            } 
     111 
     112            // else append the contents of the response to the page - just the status elem for now 
     113            Element status = (Element) GSXML.getChildByTagName(result_response, GSXML.STATUS_ELEM); 
     114            page_response.appendChild(this.doc.importNode(status, true)); 
     115        } 
     116 
     117        // another part of the page is the service description 
     118 
     119        // request the service info for the selected service - should be cached 
     120        Element mr_info_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 
     121        Element mr_info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, uid); 
     122        mr_info_message.appendChild(mr_info_request); 
     123        Element mr_info_response = (Element) this.mr.process(mr_info_message); 
     124 
     125        String path = GSXML.RESPONSE_ELEM; 
     126        path = GSPath.appendLink(path, GSXML.SERVICE_ELEM); 
     127        Element description = (Element) this.doc.importNode(GSXML.getNodeByPath(mr_info_response, path), true); 
     128 
     129        page_response.appendChild(description); 
     130 
     131        return result; 
    61132    } 
    62133 
    63     if (!request_type.equals("d")) { 
    64         // if rt=s or rt=r, do the request 
    65          
    66         Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    67         String request_type_att; 
    68         Element param_list = null; 
    69         if (request_type.equals("s")) { // status 
    70         request_type_att = GSXML.REQUEST_TYPE_STATUS; 
    71         param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 
    72         Element param = this.doc.createElement(GSXML.PARAM_ELEM); 
    73         param.setAttribute(GSXML.NAME_ATT, GSParams.PROCESS_ID); 
    74         param.setAttribute(GSXML.VALUE_ATT, (String)params.get(GSParams.PROCESS_ID)); 
    75         param_list.appendChild(param); 
    76         } else { 
    77         request_type_att = GSXML.REQUEST_TYPE_PROCESS; 
    78         // add in the service params - except the ones only used by the action 
    79         HashMap service_params = (HashMap)params.get("s1"); 
    80         if (service_params != null) {  
    81             param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 
    82             GSXML.addParametersToList(this.doc, param_list, service_params); 
     134    protected Element getServiceParamList(Element cgi_param_list) 
     135    { 
     136 
     137        Element new_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 
     138        Element param; 
     139        NodeList cgi_params = cgi_param_list.getChildNodes(); 
     140        for (int i = 0; i < cgi_params.getLength(); i++) 
     141        { 
     142            Element p = (Element) cgi_params.item(i); 
     143            String name = p.getAttribute(GSXML.NAME_ATT); 
     144            if (name.equals(GSParams.SERVICE) || name.equals(GSParams.REQUEST_TYPE) || name.equals(GSParams.CLUSTER)) 
     145            { 
     146                continue; 
     147            } 
     148            // else add it in to the list 
     149            new_param_list.appendChild(this.doc.importNode(p, true)); 
    83150        } 
    84          
    85         } 
    86         Element mr_query_request = GSXML.createBasicRequest(this.doc, request_type_att, to, lang, uid); 
    87         if (param_list != null) { 
    88         mr_query_request.appendChild(param_list); 
    89         } 
    90         mr_query_message.appendChild(mr_query_request); 
    91          
    92         Element mr_query_response = (Element)this.mr.process(mr_query_message); 
    93         Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 
    94          
    95         if (response_only) { 
    96         // just send the reponse as is 
    97         return result_response; 
    98         } 
    99          
    100         // else append the contents of the response to the page - just the status elem for now 
    101         Element status = (Element)GSXML.getChildByTagName(result_response, GSXML.STATUS_ELEM); 
    102         page_response.appendChild(this.doc.importNode(status, true)); 
     151        return new_param_list; 
    103152    } 
    104      
    105  
    106     // another part of the page is the service description 
    107  
    108     // request the service info for the selected service - should be cached 
    109     Element mr_info_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 
    110     Element mr_info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, uid); 
    111     mr_info_message.appendChild(mr_info_request); 
    112     Element mr_info_response = (Element) this.mr.process(mr_info_message); 
    113  
    114     String path = GSXML.RESPONSE_ELEM; 
    115     path = GSPath.appendLink(path, GSXML.SERVICE_ELEM); 
    116     Element description = (Element)this.doc.importNode(GSXML.getNodeByPath(mr_info_response, path), true); 
    117  
    118     page_response.appendChild(description); 
    119  
    120     return result; 
    121     } 
    122  
    123     protected Element getServiceParamList(Element cgi_param_list) { 
    124  
    125     Element new_param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 
    126     Element param; 
    127     NodeList cgi_params = cgi_param_list.getChildNodes(); 
    128     for (int i=0; i<cgi_params.getLength(); i++) { 
    129         Element p = (Element) cgi_params.item(i); 
    130         String name = p.getAttribute(GSXML.NAME_ATT); 
    131         if (name.equals(GSParams.SERVICE) || name.equals(GSParams.REQUEST_TYPE) || name.equals(GSParams.CLUSTER)) { 
    132         continue; 
    133         } 
    134         // else add it in to the list 
    135         new_param_list.appendChild(this.doc.importNode(p, true)); 
    136     } 
    137     return new_param_list; 
    138     } 
    139153}