source: trunk/gsdl3/src/java/org/greenstone/gsdl3/action/ResourceAction.java@ 3512

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

all modules now talk the same messages; all xml elems and atts have been made constants and moved to GSXML.java; SOAPCommunicator can be used outside a MessageRouter

  • Property svn:keywords set to Author Date Id Revision
File size: 3.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.Document;
8import org.w3c.dom.Element;
9
10import java.util.HashMap;
11import java.io.File;
12
13public class ResourceAction extends Action {
14
15
16 // could pass in action name, and have it dynamically decide the name
17
18 public String process (Element message) {
19
20 // find the stylesheet
21 String stylesheet = GSFile.stylesheetFile(config_, "resource.xsl");
22
23 if (stylesheet==null) {
24 return GSHTML.errorPage("resource stylesheet not found!");
25 }
26
27 // for now, no subaction eventually we may want to have subactions such as text assoc or something ?
28
29 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);
30
31 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
32 cgi_.toLong(cgi_paramList);
33 HashMap params = GSXML.extractParams(cgi_paramList);
34
35 String resource_name = (String)params.get("resource");
36 if (resource_name == null || resource_name.equals("")) {
37 // no doc to show
38 return GSHTML.errorPage("no resource specified");
39 }
40
41
42 // create the return page tree
43 Element page = doc_.createElement(GSXML.PAGE_ELEM);
44 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));
45 // add the lang stuff from message
46 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true));
47 // add the config stuff from message
48 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
49
50
51
52 // build up the mr request
53 Element mr_message = doc_.createElement(GSXML.MESSAGE_ELEM);
54 Element mr_request = doc_.createElement(GSXML.REQUEST_ELEM);
55 mr_message.appendChild(mr_request);
56 mr_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
57 mr_request.setAttribute("resourceType", "core");
58 String to = (String)params.get("collection"); // collection name
59 to = GSPath.appendLink(to, "ResourceRetrieve");
60 mr_request.setAttribute(GSXML.TO_ATT, to);
61
62 // all query requests must have a paramList and a content
63 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
64 mr_request.appendChild(paramList);
65
66 Element content = doc_.createElement(GSXML.CONTENT_ELEM);
67 mr_request.appendChild(content);
68
69 Element resource_list = doc_.createElement(GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER);
70 Element resource = doc_.createElement(GSXML.RESOURCE_ELEM);
71 resource.setAttribute(GSXML.NAME_ATT, resource_name);
72 resource_list.appendChild(resource);
73 content.appendChild(resource_list);
74
75 Element mr_result = (Element)mr_.process(mr_message);
76
77 // add the results to the page
78 page.appendChild(doc_.importNode(request, true));
79 page.appendChild(doc_.importNode(GSXML.getChildByTagName(mr_result, GSXML.RESPONSE_ELEM), true));
80
81 // process using the stylesheet
82 Document style_doc = converter_.getDOM(new File(stylesheet));
83 GSXSLT.absoluteIncludePaths(style_doc, config_);
84 return transformer_.transform(style_doc, page);
85
86 }
87
88
89}
Note: See TracBrowser for help on using the repository browser.