source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/GeneralAction.java@ 24866

Last change on this file since 24866 was 24866, checked in by sjm84, 12 years ago

Some fixes to the GeneralAction

  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 KB
Line 
1package org.greenstone.gsdl3.action;
2
3import org.greenstone.gsdl3.util.*;
4// XML classes
5import org.w3c.dom.Node;
6import org.w3c.dom.Element;
7
8import java.util.HashMap;
9
10public class GeneralAction extends Action
11{
12
13 /** process a request */
14 public Node process(Node message_node)
15 {
16
17 Element message = this.converter.nodeToElement(message_node);
18
19 // the result
20 Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
21 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
22 result.appendChild(page_response);
23
24 // assume only one request
25 Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
26 logger.debug(" request=" + this.converter.getString(request));
27
28 String lang = request.getAttribute(GSXML.LANG_ATT);
29 String uid = request.getAttribute(GSXML.USER_ID_ATT);
30
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 {
40 response_only = (response_only_p.equals("1") ? true : false);
41 }
42 String request_type = (String) params.get(GSParams.REQUEST_TYPE);
43 // what is carried out depends on the request_type
44 // if rt=d, then a describe request is done,
45 // is rt=r, a request and then a describe request is done
46 // if rt=s, a status request is done.
47
48 // if ro=1, then this calls for a process only page - we do the request
49 // (rt should be r or s) and just give the response straight back
50 // without any page processing
51
52 // where to send requests
53 String to;
54 if (cluster_name != null)
55 {
56 to = GSPath.appendLink(cluster_name, service_name);
57 }
58 else
59 {
60 to = service_name;
61 }
62
63 if (request_type.equals("r") || request_type.equals("s"))
64 {
65 //do the request
66
67 Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
68 Element mr_query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
69
70 if(request_type.equals("s"))
71 {
72 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_STATUS);
73 }
74
75 mr_query_message.appendChild(mr_query_request);
76
77 Element param_list = null;
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 {
82 param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
83 GSXML.addParametersToList(this.doc, param_list, service_params);
84 mr_query_request.appendChild(param_list);
85 }
86
87 Element mr_query_response = (Element) this.mr.process(mr_query_message);
88 Element result_response = (Element) GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
89
90 if (response_only)
91 {
92 // just send the reponse as is
93 addSiteMetadata(result_response, lang, uid);
94 return result_response;
95 }
96 if (result_response != null)
97 {
98 // else append the contents of the response to the page
99 GSXML.copyAllChildren(page_response, result_response);
100 }
101 }
102
103 // another part of the page is the service description
104
105 // request the service info for the selected service - should be cached
106 Element mr_info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
107 Element mr_info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, uid);
108 mr_info_message.appendChild(mr_info_request);
109 Element mr_info_response = (Element) this.mr.process(mr_info_message);
110
111 String path = GSXML.RESPONSE_ELEM;
112 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
113
114 Node desNode = GSXML.getNodeByPath(mr_info_response, path);
115 if (desNode != null)
116 {
117 page_response.appendChild((Element) this.doc.importNode(desNode, true));
118 }
119
120 addSiteMetadata(page_response, lang, uid);
121
122 return result;
123 }
124
125}
Note: See TracBrowser for help on using the repository browser.