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

Last change on this file since 19851 was 19851, checked in by shaoqun, 15 years ago

tidy debug info

  • 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.*;
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 //A shortcut action serving the flax web page requests
26 if(request.getAttribute(GSXML.SUBACTION_ATT).equals(GSXML.FLAX_PAGE_GENERATION)
27 && request.getAttribute(GSXML.TO_ATT).equals(GSXML.FLAX_PAGE_GENERATION)) {
28 //
29 Element mr_info_response = (Element) this.mr.process(message);
30 Node flaxPageNode = (mr_info_response.getElementsByTagName(GSXML.FLAX_PAGE)).item(0);
31 //logger.info(" raw page="+this.converter.getString(flaxPageNode));
32 if(flaxPageNode != null){
33 page_response.appendChild((Element)this.doc.importNode(flaxPageNode, true));
34 }
35 return result;
36 }
37
38 // get the param list
39 Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
40 HashMap params = GSXML.extractParams(cgi_param_list, false);
41 String service_name = (String) params.get(GSParams.SERVICE);
42 String cluster_name = (String) params.get(GSParams.CLUSTER);
43 String response_only_p = (String)params.get(GSParams.RESPONSE_ONLY);
44 boolean response_only = false;
45 if (response_only_p!=null) {
46 response_only = (response_only_p.equals("1")?true:false);
47 }
48 String request_type = (String) params.get(GSParams.REQUEST_TYPE);
49 String lang = request.getAttribute(GSXML.LANG_ATT);
50 String uid = request.getAttribute(GSXML.USER_ID_ATT);
51 // what is carried out depends on the request_type
52 // if rt=d, then a describe request is done,
53 // is rt=r, a request and then a describe request is done
54 // if rt=s, a status request is done.
55
56 // if ro=1, then this calls for a process only page - we do the request
57 // (rt should be r or s) and just give the response straight back
58 // without any page processing
59
60
61 // where to send requests
62 String to;
63 if (cluster_name != null) {
64 to = GSPath.appendLink(cluster_name, service_name);
65 } else {
66 to = service_name;
67 }
68
69 if (request_type.equals("r")) {
70 //do the request
71
72 Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
73 Element mr_query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
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 param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
82 GSXML.addParametersToList(this.doc, param_list, service_params);
83 mr_query_request.appendChild(param_list);
84 }
85
86 Element mr_query_response = (Element)this.mr.process(mr_query_message);
87 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
88
89 if (response_only) {
90 // just send the reponse as is
91 return result_response;
92 }
93 if (result_response != null){
94 // else append the contents of the response to the page
95 GSXML.copyAllChildren(page_response, result_response);
96 }
97 }
98
99
100 // another part of the page is the service description
101
102 // request the service info for the selected service - should be cached
103 Element mr_info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
104 Element mr_info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, uid);
105 mr_info_message.appendChild(mr_info_request);
106 Element mr_info_response = (Element) this.mr.process(mr_info_message);
107
108
109 String path = GSXML.RESPONSE_ELEM;
110 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
111
112
113 Node desNode = GSXML.getNodeByPath(mr_info_response, path);
114 if(desNode != null){
115 page_response.appendChild((Element)this.doc.importNode(desNode, true));
116 }
117
118 return result;
119 }
120
121}
Note: See TracBrowser for help on using the repository browser.