source: trunk/gsdl3/src/java/org/greenstone/gsdl3/action/AppletAction.java@ 8800

Last change on this file since 8800 was 6300, checked in by kjdon, 20 years ago

GSXML.createBasicRequest now expects a user id

  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1package org.greenstone.gsdl3.action;
2
3import org.greenstone.gsdl3.core.ModuleInterface;
4import org.greenstone.gsdl3.util.*;
5// XML classes
6import org.w3c.dom.Node;
7import org.w3c.dom.NodeList;
8import org.w3c.dom.Document;
9import org.w3c.dom.Element;
10
11import java.util.HashMap;
12import java.io.File;
13
14/** action class for handling applets */
15public class AppletAction extends Action {
16
17
18 public Element process (Element message) {
19
20 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
21 Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
22 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
23 result.appendChild(page_response);
24
25 // get the collection and service params
26 Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
27 HashMap params = GSXML.extractParams(cgi_param_list, false);
28
29 // request_type is display (d) or request (r)
30 String request_type = (String)params.get(GSParams.REQUEST_TYPE);
31 if (!request_type.equals("d")&&!request_type.equals("r")) {
32 System.err.println("AppletAction Error: the rt arg should be either d or r, instead it was "+request_type+"!");
33 return result;
34 }
35
36 String collection = (String)params.get(GSParams.COLLECTION);
37 boolean coll_specified = true;
38 String service_name=(String)params.get(GSParams.SERVICE);
39 String lang = request.getAttribute(GSXML.LANG_ATT);
40 String uid = request.getAttribute(GSXML.USER_ID_ATT);
41 String to=null;
42 if (collection==null||collection.equals("") ) {
43 coll_specified = false;
44 to = service_name;
45 } else {
46 to = GSPath.appendLink(collection, service_name);
47 }
48
49 if (request_type.equals("r")) {
50 // we are processing stuff for the applet send a message to the service, type="query", and take out the something element, and return that as our result - the applet must take xml
51
52 Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
53 Element mr_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, lang, uid);
54 mr_message.appendChild(mr_request);
55 // just append all the params for now - should filter out unneeded ones
56 mr_request.appendChild(this.doc.importNode(cgi_param_list, true));
57
58 // process the request
59 Element mr_response = (Element)this.mr.process(mr_message);
60 // get the applet data out and pass it back as is.
61 String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.APPLET_DATA_ELEM);
62 Element applet_info = (Element)GSXML.getNodeByPath(mr_response, path).getFirstChild();
63 return applet_info;
64
65 }
66
67
68 // get the applet description, and the collection info if a collection is specified
69
70 Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
71 Element applet_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, uid);
72 mr_message.appendChild(applet_request);
73
74
75 Element mr_response = (Element)this.mr.process(mr_message);
76
77 // add in the applet info
78 String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.SERVICE_ELEM);
79 //path = GSPath.appendLink(path, GSXML.APPLET_ELEM);
80 Element service_elem = (Element)this.doc.importNode(GSXML.getNodeByPath(mr_response, path), true);
81 Element applet_elem = (Element)GSXML.getChildByTagName(service_elem, GSXML.APPLET_ELEM);
82 // must handle any params that have values that are not
83 // necessarily known by the service
84 // should this be done here or by web receptionist??
85 // cant really have an applet without web?
86 editLocalParams(applet_elem, (String)config_params.get(GSConstants.LIBRARY_NAME), collection);
87 page_response.appendChild(service_elem);
88
89 return result;
90
91 }
92
93 /** this method looks through the PARAMs of the applet description for
94 * 'library' or 'collection'. If found, the params are set to
95 * the appropriate values
96 * should this be done here or in the receptionist?
97 */
98 protected void editLocalParams(Element description, String library_name,
99 String full_collection_name) {
100
101 Node child = description.getFirstChild();
102 while (child != null) {
103 if (child.getNodeType() == Node.ELEMENT_NODE) {
104 String param = child.getNodeName();
105 if (param.equals("PARAM")||param.equals("param")) {
106 String name = ((Element)child).getAttribute("NAME");
107 if (name == null || name.equals("")) {
108 // somethings wrong!!
109 } else if (name.equals("library")) {
110 ((Element)child).setAttribute("VALUE", library_name);
111 } else if (name.equals("collection")) {
112 ((Element)child).setAttribute("VALUE", full_collection_name);
113 }
114
115 }
116 }
117 child = child.getNextSibling();
118 }
119 }
120
121}
Note: See TracBrowser for help on using the repository browser.