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

Last change on this file since 19984 was 19984, checked in by oranfry, 15 years ago

initial implementation of support for site-level metadata

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