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

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

tidied up a bit, uses new page structure and new display elements

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