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