Changeset 24991 for main/trunk/greenstone3/src/java/org/greenstone
- Timestamp:
- 2012-01-26T11:40:18+13:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/ProcessAction.java
r16688 r24991 4 4 import org.greenstone.gsdl3.util.*; 5 5 // XML classes 6 import org.w3c.dom.Node; 7 import org.w3c.dom.NodeList; 8 import org.w3c.dom.Document; 9 import org.w3c.dom.Element; 6 import org.w3c.dom.Node; 7 import org.w3c.dom.NodeList; 8 import org.w3c.dom.Document; 9 import org.w3c.dom.Element; 10 10 11 11 import java.util.HashMap; … … 14 14 import java.io.File; 15 15 16 public class ProcessAction extends Action { 17 18 /** process a request */ 19 public Node process (Node message_node) { 16 public class ProcessAction extends Action 17 { 20 18 21 Element message = this.converter.nodeToElement(message_node); 19 /** process a request */ 20 public Node process(Node message_node) 21 { 22 22 23 // the result 24 Element result = this.doc.createElement(GSXML.MESSAGE_ELEM); 25 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM); 26 result.appendChild(page_response); 23 Element message = this.converter.nodeToElement(message_node); 27 24 28 // assume only one request 29 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 25 // the result 26 Element result = this.doc.createElement(GSXML.MESSAGE_ELEM); 27 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM); 28 result.appendChild(page_response); 30 29 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 response_only = (response_only_p.equals("1")?true:false); 40 } 41 String request_type = (String) params.get(GSParams.REQUEST_TYPE); 42 String lang = request.getAttribute(GSXML.LANG_ATT); 43 String uid = request.getAttribute(GSXML.USER_ID_ATT); 44 // what is carried out depends on the request_type 45 // if rt=d, then a describe request is done, 46 // is rt=r, a request and then a describe request is done 47 // if rt=s, a status request is done. 30 // assume only one request 31 Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); 48 32 49 // if ro=1, then this calls for a process only page - we do the request 50 // (rt should be r or s) and just give the response straight back 51 // without any page processing 33 // get the param list 34 Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 35 HashMap params = GSXML.extractParams(cgi_param_list, false); 36 String service_name = (String) params.get(GSParams.SERVICE); 37 String cluster_name = (String) params.get(GSParams.CLUSTER); 38 String response_only_p = (String) params.get(GSParams.RESPONSE_ONLY); 39 boolean response_only = false; 40 if (response_only_p != null) 41 { 42 response_only = (response_only_p.equals("1") ? true : false); 43 } 44 String request_type = (String) params.get(GSParams.REQUEST_TYPE); 45 String lang = request.getAttribute(GSXML.LANG_ATT); 46 String uid = request.getAttribute(GSXML.USER_ID_ATT); 47 // what is carried out depends on the request_type 48 // if rt=d, then a describe request is done, 49 // is rt=r, a request and then a describe request is done 50 // if rt=s, a status request is done. 52 51 52 // if ro=1, then this calls for a process only page - we do the request 53 // (rt should be r or s) and just give the response straight back 54 // without any page processing 53 55 54 // where to send requests 55 String to; 56 if (cluster_name != null) { 57 58 to = GSPath.appendLink(cluster_name, service_name); 59 } else { 60 to = service_name; 56 // where to send requests 57 String to; 58 if (cluster_name != null) 59 { 60 61 to = GSPath.appendLink(cluster_name, service_name); 62 } 63 else 64 { 65 to = service_name; 66 } 67 68 if (!request_type.equals("d")) 69 { 70 // if rt=s or rt=r, do the request 71 72 Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 73 String request_type_att; 74 Element param_list = null; 75 if (request_type.equals("s")) 76 { // status 77 request_type_att = GSXML.REQUEST_TYPE_STATUS; 78 param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 79 Element param = this.doc.createElement(GSXML.PARAM_ELEM); 80 param.setAttribute(GSXML.NAME_ATT, GSParams.PROCESS_ID); 81 param.setAttribute(GSXML.VALUE_ATT, (String) params.get(GSParams.PROCESS_ID)); 82 param_list.appendChild(param); 83 } 84 else 85 { 86 request_type_att = GSXML.REQUEST_TYPE_PROCESS; 87 // add in the service params - except the ones only used by the action 88 HashMap service_params = (HashMap) params.get("s1"); 89 if (service_params != null) 90 { 91 param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 92 GSXML.addParametersToList(this.doc, param_list, service_params); 93 } 94 95 } 96 Element mr_query_request = GSXML.createBasicRequest(this.doc, request_type_att, to, lang, uid); 97 if (param_list != null) 98 { 99 mr_query_request.appendChild(param_list); 100 } 101 mr_query_message.appendChild(mr_query_request); 102 103 Element mr_query_response = (Element) this.mr.process(mr_query_message); 104 Element result_response = (Element) GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 105 106 if (response_only) 107 { 108 // just send the reponse as is 109 return result_response; 110 } 111 112 // else append the contents of the response to the page - just the status elem for now 113 Element status = (Element) GSXML.getChildByTagName(result_response, GSXML.STATUS_ELEM); 114 page_response.appendChild(this.doc.importNode(status, true)); 115 } 116 117 // another part of the page is the service description 118 119 // request the service info for the selected service - should be cached 120 Element mr_info_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 121 Element mr_info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, uid); 122 mr_info_message.appendChild(mr_info_request); 123 Element mr_info_response = (Element) this.mr.process(mr_info_message); 124 125 String path = GSXML.RESPONSE_ELEM; 126 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM); 127 Element description = (Element) this.doc.importNode(GSXML.getNodeByPath(mr_info_response, path), true); 128 129 page_response.appendChild(description); 130 131 return result; 61 132 } 62 133 63 if (!request_type.equals("d")) { 64 // if rt=s or rt=r, do the request 65 66 Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 67 String request_type_att; 68 Element param_list = null; 69 if (request_type.equals("s")) { // status 70 request_type_att = GSXML.REQUEST_TYPE_STATUS; 71 param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 72 Element param = this.doc.createElement(GSXML.PARAM_ELEM); 73 param.setAttribute(GSXML.NAME_ATT, GSParams.PROCESS_ID); 74 param.setAttribute(GSXML.VALUE_ATT, (String)params.get(GSParams.PROCESS_ID)); 75 param_list.appendChild(param); 76 } else { 77 request_type_att = GSXML.REQUEST_TYPE_PROCESS; 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); 134 protected Element getServiceParamList(Element cgi_param_list) 135 { 136 137 Element new_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 138 Element param; 139 NodeList cgi_params = cgi_param_list.getChildNodes(); 140 for (int i = 0; i < cgi_params.getLength(); i++) 141 { 142 Element p = (Element) cgi_params.item(i); 143 String name = p.getAttribute(GSXML.NAME_ATT); 144 if (name.equals(GSParams.SERVICE) || name.equals(GSParams.REQUEST_TYPE) || name.equals(GSParams.CLUSTER)) 145 { 146 continue; 147 } 148 // else add it in to the list 149 new_param_list.appendChild(this.doc.importNode(p, true)); 83 150 } 84 85 } 86 Element mr_query_request = GSXML.createBasicRequest(this.doc, request_type_att, to, lang, uid); 87 if (param_list != null) { 88 mr_query_request.appendChild(param_list); 89 } 90 mr_query_message.appendChild(mr_query_request); 91 92 Element mr_query_response = (Element)this.mr.process(mr_query_message); 93 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 94 95 if (response_only) { 96 // just send the reponse as is 97 return result_response; 98 } 99 100 // else append the contents of the response to the page - just the status elem for now 101 Element status = (Element)GSXML.getChildByTagName(result_response, GSXML.STATUS_ELEM); 102 page_response.appendChild(this.doc.importNode(status, true)); 151 return new_param_list; 103 152 } 104 105 106 // another part of the page is the service description107 108 // request the service info for the selected service - should be cached109 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 String path = GSXML.RESPONSE_ELEM;115 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);116 Element description = (Element)this.doc.importNode(GSXML.getNodeByPath(mr_info_response, path), true);117 118 page_response.appendChild(description);119 120 return result;121 }122 123 protected Element getServiceParamList(Element cgi_param_list) {124 125 Element new_param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);126 Element param;127 NodeList cgi_params = cgi_param_list.getChildNodes();128 for (int i=0; i<cgi_params.getLength(); i++) {129 Element p = (Element) cgi_params.item(i);130 String name = p.getAttribute(GSXML.NAME_ATT);131 if (name.equals(GSParams.SERVICE) || name.equals(GSParams.REQUEST_TYPE) || name.equals(GSParams.CLUSTER)) {132 continue;133 }134 // else add it in to the list135 new_param_list.appendChild(this.doc.importNode(p, true));136 }137 return new_param_list;138 }139 153 }
Note:
See TracChangeset
for help on using the changeset viewer.