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