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

Last change on this file since 14398 was 14398, checked in by xiao, 17 years ago

modify to accommodate the new subaction - FlaxPageGeneration, deliverying the flax web pages.

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