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

Last change on this file since 3491 was 3491, checked in by kjdon, 22 years ago

actions all use cgi arg long names now, not short names

  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 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
14public class AppletAction extends Action {
15
16
17 public String process (Element message) {
18
19
20 // find the stylesheet
21 String stylesheet = GSFile.stylesheetFile(config_, "applet.xsl");
22
23 if (stylesheet==null) {
24 return GSHTML.errorPage("applet stylesheet not found!");
25 }
26
27 Element request = (Element)message.getElementsByTagName("request").item(0);
28
29 // subaction is display/request
30 String request_type = request.getAttribute("subaction"); // should be 'd' or 'r'
31 if (!request_type.equals("d")&&!request_type.equals("r")) {
32 return GSHTML.errorPage("the sa arg to a=a should be d or r!!");
33 }
34
35 // get the collection and service param
36 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, "paramList");
37 cgi_.toLong(cgi_paramList);
38 HashMap params = GSXML.extractParams(cgi_paramList);
39
40 String collection = (String)params.get("collection");
41 String service_name=(String)params.get("serviceName");
42 service_name+= "Applet";
43
44 String to=null;
45 if (collection==null||collection.equals("") ) {
46 to = service_name;
47 } else {
48 to = GSPath.appendLink(collection, service_name);
49 }
50
51 System.out.println("to="+to);
52
53
54 if (request_type.equals("d")) {
55 // we are just displaying the applet - get the description from
56 // the service, and process using xslt
57
58 //build up the mr request
59
60 Element mr_message = doc_.createElement("message");
61 Element mr_request = doc_.createElement("request");
62 mr_message.appendChild(mr_request);
63 mr_request.setAttribute("type", "describe");
64 mr_request.setAttribute("to", to);
65 //mr_request.setAttribute("info", "appletInfo");
66
67 Element mr_response = (Element)mr_.process(mr_message);
68
69 System.out.println("applet mr response =");
70 System.out.println(converter_.getString(mr_response));
71 // create the return page tree
72 Element page = doc_.createElement("page");
73 page.setAttribute("lang", message.getAttribute("lang"));
74 // add the lang stuff from message
75 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true));
76 // add the config stuff from message
77 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true));
78
79 page.appendChild(doc_.importNode(request, true));
80
81 // add in the applet info
82 Element app_desc = (Element)doc_.importNode(GSXML.getNodeByPath(mr_response, "response/service/applet"), true);
83 // must handle any params that have values that are not
84 // necessarily known by the service
85 editLocalParams(app_desc, config_.library_name_, collection);
86 page.appendChild(app_desc);
87
88 // process using the stylesheet
89 Document style_doc = converter_.getDOM(new File(stylesheet));
90 GSXSLT.absoluteIncludePaths(style_doc, config_);
91 return transformer_.transform(style_doc, page);
92
93 }
94 else if (request_type.equals("r")) {
95 // 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
96
97 Element mr_message = doc_.createElement("message");
98 Element mr_request = doc_.createElement("request");
99 mr_message.appendChild(mr_request);
100 mr_request.setAttribute("type", "query");
101 mr_request.setAttribute("to", to);
102
103 // just append the params for now
104 mr_request.appendChild(doc_.importNode(cgi_paramList, true));
105
106 Element mr_response = (Element)mr_.process(mr_message);
107 System.out.println("applet query response:");
108 // dont need to create a page, just extract the info out.
109 System.out.println(converter_.getString(mr_response));
110 Element applet_info = (Element)GSXML.getNodeByPath(mr_response, "response/appletData").getFirstChild();
111 System.out.println("applet action: applet data =");
112 System.out.println(converter_.getString(applet_info));
113 return converter_.getString(applet_info);
114
115 }
116 else {
117 // should never get here
118 return GSHTML.errorPage("applet action, wrong subaction type");
119 }
120 }
121
122 /** this method looks through the PARAMs of the applet description for
123 * one with the name 'library'. If its found, it sets the value to be
124 * library_name
125 */
126 protected void editLocalParams(Element description, String library_name,
127 String full_collection_name) {
128
129 Node child = description.getFirstChild();
130 while (child != null) {
131 if (child.getNodeType() == Node.ELEMENT_NODE) {
132 String param = child.getNodeName();
133 if (param.equals("PARAM")||param.equals("param")) {
134 String name = ((Element)child).getAttribute("NAME");
135 if (name == null || name.equals("")) {
136 // somethings wrong!!
137 } else if (name.equals("library")) {
138 ((Element)child).setAttribute("VALUE", library_name);
139 } else if (name.equals("collection")) {
140 ((Element)child).setAttribute("VALUE", full_collection_name);
141 }
142
143 }
144 }
145 child = child.getNextSibling();
146 }
147 }
148
149}
Note: See TracBrowser for help on using the repository browser.