source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/AppletAction.java@ 26133

Last change on this file since 26133 was 26133, checked in by ak19, 12 years ago

Added applet.xsl for the default interface to get the PhindApplet to work for GS3 for the Tudor and Multimedia tutorials.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 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;
13import java.io.Serializable;
14
15import org.apache.log4j.*;
16
17/** action class for handling applets */
18public class AppletAction extends Action
19{
20
21 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.AppletAction.class.getName());
22
23 public Node process(Node message_node)
24 {
25
26 Element message = this.converter.nodeToElement(message_node);
27
28 Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
29 Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
30 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
31 result.appendChild(page_response);
32
33 // get the collection and service params
34 Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
35 HashMap<String, Serializable> params = GSXML.extractParams(cgi_param_list, false);
36
37 // request_type is display (d) or request (r)
38 String request_type = (String) params.get(GSParams.REQUEST_TYPE);
39 if (!request_type.equals("d") && !request_type.equals("r"))
40 {
41 logger.error("AppletAction Error: the rt arg should be either d or r, instead it was " + request_type + "!");
42 return result;
43 }
44
45 String collection = (String) params.get(GSParams.COLLECTION);
46 boolean coll_specified = true;
47 String service_name = (String) params.get(GSParams.SERVICE);
48 UserContext userContext = new UserContext(request);
49 String to = null;
50 if (collection == null || collection.equals(""))
51 {
52 coll_specified = false;
53 to = service_name;
54 }
55 else
56 {
57 to = GSPath.appendLink(collection, service_name);
58 }
59
60 if (request_type.equals("r"))
61 {
62 // 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
63
64 Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
65 Element mr_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
66 mr_message.appendChild(mr_request);
67 // just append all the params for now - should filter out unneeded ones
68 mr_request.appendChild(this.doc.importNode(cgi_param_list, true));
69
70 // process the request
71 Element mr_response = (Element) this.mr.process(mr_message);
72 // get the applet data out and pass it back as is.
73 String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.APPLET_DATA_ELEM);
74 Element applet_info = GSXML.getFirstElementChild(GSXML.getNodeByPath(mr_response, path));
75 //Element applet_info = (Element)GSXML.getNodeByPath(mr_response, path).getFirstChild();
76 return applet_info;
77
78 }
79
80 // get the applet description, and the collection info if a collection is specified
81
82 Element mr_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
83 Element applet_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, userContext);
84 mr_message.appendChild(applet_request);
85
86 Element mr_response = (Element) this.mr.process(mr_message);
87
88 // add in the applet info
89 String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.SERVICE_ELEM);
90 //path = GSPath.appendLink(path, GSXML.APPLET_ELEM);
91 Element service_elem = (Element) this.doc.importNode(GSXML.getNodeByPath(mr_response, path), true);
92 Element applet_elem = (Element) GSXML.getChildByTagName(service_elem, GSXML.APPLET_ELEM);
93 // must handle any params that have values that are not
94 // necessarily known by the service
95 // should this be done here or by web receptionist??
96 // cant really have an applet without web?
97 editLocalParams(applet_elem, (String) config_params.get(GSConstants.LIBRARY_NAME), collection);
98 page_response.appendChild(service_elem);
99
100 //append site metadata
101 addSiteMetadata(page_response, userContext);
102 //addInterfaceOptions(page_response);
103 return result;
104
105 }
106
107 /**
108 * this method looks through the PARAMs of the applet description for
109 * 'library' or 'collection'. If found, the params are set to the
110 * appropriate values should this be done here or in the receptionist?
111 */
112 protected void editLocalParams(Element description, String library_name, String full_collection_name)
113 {
114
115 Node child = description.getFirstChild();
116 while (child != null)
117 {
118 if (child.getNodeType() == Node.ELEMENT_NODE)
119 {
120 String param = child.getNodeName();
121 if (param.equals("PARAM") || param.equals("param"))
122 {
123 String name = ((Element) child).getAttribute("NAME");
124 if (name == null || name.equals(""))
125 {
126 // somethings wrong!!
127 }
128 else if (name.equals("library"))
129 {
130 ((Element) child).setAttribute("VALUE", library_name);
131 }
132 else if (name.equals("collection"))
133 {
134 ((Element) child).setAttribute("VALUE", full_collection_name);
135 }
136
137 }
138 }
139 child = child.getNextSibling();
140 }
141 }
142
143}
Note: See TracBrowser for help on using the repository browser.