source: trunk/gsdl3/src/java/org/greenstone/gsdl3/action/ResourceAction.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: 2.8 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("request").item(0);
30
31 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, "paramList");
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("page");
44 page.setAttribute("lang", message.getAttribute("lang"));
45 // add the lang stuff from message
46 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true));
47 // add the config stuff from message
48 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true));
49
50
51
52 // build up the mr request
53 Element mr_message = doc_.createElement("message");
54 Element mr_request = doc_.createElement("request");
55 mr_message.appendChild(mr_request);
56 mr_request.setAttribute("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("to", to);
61
62 // all query requests must have a paramList and a content
63 Element paramList = doc_.createElement("paramList");
64 mr_request.appendChild(paramList);
65
66 Element content = doc_.createElement("content");
67 mr_request.appendChild(content);
68
69 Element resource_list = doc_.createElement("resourceList");
70 Element resource = doc_.createElement("resource");
71 resource.setAttribute("name", 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, "response"), 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.