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

Last change on this file since 22135 was 22135, checked in by xiao, 14 years ago

removed hard-code hack for serving flax page actions

  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 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 /** process a request */
13 public Node process (Node message_node) {
14
15 Element message = this.converter.nodeToElement(message_node);
16
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);
21
22 // assume only one request
23 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
24 logger.debug(" request="+this.converter.getString(request));
25
26 String lang = request.getAttribute(GSXML.LANG_ATT);
27 String uid = request.getAttribute(GSXML.USER_ID_ATT);
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(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.
44
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
48
49
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;
56 }
57
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
112}
Note: See TracBrowser for help on using the repository browser.