source: trunk/gsdl3/src/java/org/greenstone/gsdl3/action/ProcessAction.java@ 4980

Last change on this file since 4980 was 4694, checked in by kjdon, 21 years ago

GSCGI.REQUEST_ONLY_ARG has changed to GSCGI.RESPONSE_ONLY_ARG - I thought it made more sense, but does it??

  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1package org.greenstone.gsdl3.action;
2
3import org.greenstone.gsdl3.core.ModuleInterface;
4import org.greenstone.gsdl3.util.*;
5// XML classes
6import org.w3c.dom.Node;
7import org.w3c.dom.NodeList;
8import org.w3c.dom.Document;
9import org.w3c.dom.Element;
10
11import java.util.HashMap;
12import java.util.Map;
13import java.util.Iterator;
14import java.io.File;
15
16public class ProcessAction extends Action {
17
18 /** process a request */
19 public Element process (Element message) {
20
21 // the result
22 Element result = doc_.createElement(GSXML.MESSAGE_ELEM);
23 Element page_response = doc_.createElement(GSXML.RESPONSE_ELEM);
24 result.appendChild(page_response);
25
26 // assume only one request
27 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
28
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(GSCGI.SERVICE_ARG);
33 String cluster_name = (String) params.get(GSCGI.CLUSTER_ARG);
34 String response_only_p = (String)params.get(GSCGI.RESPONSE_ONLY_ARG);
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(GSCGI.REQUEST_TYPE_ARG);
40 String lang = request.getAttribute(GSXML.LANG_ATT);
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.
45
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
49
50
51 // where to send requests
52 String to = cluster_name;
53 to = GSPath.appendLink(to, service_name);
54
55 if (!request_type.equals("d")) {
56 // if rt=s or rt=r, do the request
57
58 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);
59 String request_type_att;
60 Element param_list;
61 if (request_type.equals("s")) { // status
62 request_type_att = GSXML.REQUEST_TYPE_STATUS;
63 param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
64 Element param = doc_.createElement(GSXML.PARAM_ELEM);
65 param.setAttribute(GSXML.NAME_ATT, GSCGI.PROCESS_ID_ARG);
66 param.setAttribute(GSXML.VALUE_ATT, (String)params.get(GSCGI.PROCESS_ID_ARG));
67 param_list.appendChild(param);
68 } else {
69 request_type_att = GSXML.REQUEST_TYPE_PROCESS;
70 // add in the params - except the ones only used by the action
71 param_list = getServiceParamList(cgi_param_list);
72
73 }
74 Element mr_query_request = GSXML.createBasicRequest(doc_, request_type_att, to, lang);
75 mr_query_request.appendChild(param_list);
76 mr_query_message.appendChild(mr_query_request);
77
78 Element mr_query_response = (Element)mr_.process(mr_query_message);
79 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
80
81 if (response_only) {
82 // just send the reponse as is
83 return result_response;
84 }
85
86 // else append the contents of the response to the page - just the status elem for now
87 Element status = (Element)GSXML.getChildByTagName(result_response, GSXML.STATUS_ELEM);
88 page_response.appendChild(doc_.importNode(status, true));
89 }
90
91
92 // another part of the page is the service description
93
94 // request the service info for the selected service - should be cached
95 Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM);
96 Element mr_info_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_DESCRIBE, to, lang); //.createElement(GSXML.REQUEST_ELEM);
97 mr_info_message.appendChild(mr_info_request);
98 Element mr_info_response = (Element) mr_.process(mr_info_message);
99
100 String path = GSXML.RESPONSE_ELEM;
101 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
102 Element description = (Element)doc_.importNode(GSXML.getNodeByPath(mr_info_response, path), true);
103
104 page_response.appendChild(description);
105
106 return result;
107 }
108
109 protected Element getServiceParamList(Element cgi_param_list) {
110
111 Element new_param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
112 Element param;
113 NodeList cgi_params = cgi_param_list.getChildNodes();
114 for (int i=0; i<cgi_params.getLength(); i++) {
115 Element p = (Element) cgi_params.item(i);
116 String name = p.getAttribute(GSXML.NAME_ATT);
117 if (name.equals(GSCGI.SERVICE_ARG) || name.equals(GSCGI.REQUEST_TYPE_ARG) || name.equals(GSCGI.CLUSTER_ARG)) {
118 continue;
119 }
120 // else add it in to the list
121 new_param_list.appendChild(doc_.importNode(p, true));
122 }
123 return new_param_list;
124 }
125}
Note: See TracBrowser for help on using the repository browser.