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

Last change on this file since 4717 was 4695, checked in by kjdon, 21 years ago

no longer use ConfigVars, use a HashMap instead

  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 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 = doc_.createElement(GSXML.MESSAGE_ELEM);
22 Element page_response = 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(GSCGI.REQUEST_TYPE_ARG);
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(GSCGI.COLLECTION_ARG);
37 boolean coll_specified = true;
38 String service_name=(String)params.get(GSCGI.SERVICE_ARG);
39 String lang = request.getAttribute(GSXML.LANG_ATT);
40 String to=null;
41 if (collection==null||collection.equals("") ) {
42 coll_specified = false;
43 to = service_name;
44 } else {
45 to = GSPath.appendLink(collection, service_name);
46 }
47
48 if (request_type.equals("r")) {
49 // 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
50
51 Element mr_message = doc_.createElement(GSXML.MESSAGE_ELEM);
52 Element mr_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_PROCESS, to, lang);
53 mr_message.appendChild(mr_request);
54 // just append all the params for now - should filter out unneeded ones
55 mr_request.appendChild(doc_.importNode(cgi_param_list, true));
56
57 // process the request
58 Element mr_response = (Element)mr_.process(mr_message);
59 // get the applet data out and pass it back as is.
60 String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.APPLET_DATA_ELEM);
61 Element applet_info = (Element)GSXML.getNodeByPath(mr_response, path).getFirstChild();
62 return applet_info;
63
64 }
65
66
67 // get the applet description, and the collection info if a collection is specified
68
69 Element mr_message = doc_.createElement(GSXML.MESSAGE_ELEM);
70 Element applet_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_DESCRIBE, to, lang);
71 mr_message.appendChild(applet_request);
72
73
74 Element mr_response = (Element)mr_.process(mr_message);
75
76 // add in the applet info
77 String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.SERVICE_ELEM);
78 path = GSPath.appendLink(path, GSXML.APPLET_ELEM);
79 Element app_desc = (Element)doc_.importNode(GSXML.getNodeByPath(mr_response, path), true);
80 // must handle any params that have values that are not
81 // necessarily known by the service
82 // should this be done here or by web receptionist??
83 // cant really have an applet without web?
84 editLocalParams(app_desc, (String)config_params.get(GSConstants.LIBRARY_NAME), collection);
85 page_response.appendChild(app_desc);
86
87 return result;
88
89 }
90
91 /** this method looks through the PARAMs of the applet description for
92 * 'library' or 'collection'. If found, the params are set to
93 * the appropriate values
94 * should this be done here or in the receptionist?
95 */
96 protected void editLocalParams(Element description, String library_name,
97 String full_collection_name) {
98
99 Node child = description.getFirstChild();
100 while (child != null) {
101 if (child.getNodeType() == Node.ELEMENT_NODE) {
102 String param = child.getNodeName();
103 if (param.equals("PARAM")||param.equals("param")) {
104 String name = ((Element)child).getAttribute("NAME");
105 if (name == null || name.equals("")) {
106 // somethings wrong!!
107 } else if (name.equals("library")) {
108 ((Element)child).setAttribute("VALUE", library_name);
109 } else if (name.equals("collection")) {
110 ((Element)child).setAttribute("VALUE", full_collection_name);
111 }
112
113 }
114 }
115 child = child.getNextSibling();
116 }
117 }
118
119}
Note: See TracBrowser for help on using the repository browser.