source: trunk/gsdl3/src/java/org/greenstone/gsdl3/action/DocumentAction.java@ 3645

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

actions tidied up a bit, ResourceAction changed to DocumentAction, BuildAction removed, more general ProcessAction added

  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 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 via the message router
14 */
15public class DocumentAction extends Action {
16
17 public Element process (Element message) {
18
19 // find the stylesheet
20 String stylesheet = GSFile.stylesheetFile(config_, "document.xsl");
21
22 if (stylesheet==null) {
23 System.err.println("DocumentAction Error: document 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 document_name = (String)params.get(GSCGI.DOCUMENT_ARG);
35 if (document_name == null || document_name.equals("")) {
36 System.err.println("DocumentAction Error: no document 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 String to = (String)params.get(GSCGI.COLLECTION_ARG); // collection name
55 to = GSPath.appendLink(to, "DocumentRetrieve");
56 mr_request.setAttribute(GSXML.TO_ATT, to);
57
58 // all query requests must have a paramList and a content
59 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
60 mr_request.appendChild(paramList);
61
62 Element content = doc_.createElement(GSXML.CONTENT_ELEM);
63 mr_request.appendChild(content);
64
65 Element document_list = doc_.createElement(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
66 Element document = doc_.createElement(GSXML.DOCUMENT_ELEM);
67 document.setAttribute(GSXML.NAME_ATT, document_name);
68 document_list.appendChild(document);
69 content.appendChild(document_list);
70
71 Element mr_result = (Element)mr_.process(mr_message);
72
73 // add the results to the page
74 page.appendChild(doc_.importNode(request, true));
75 page.appendChild(doc_.importNode(GSXML.getChildByTagName(mr_result, GSXML.RESPONSE_ELEM), true));
76
77 // process using the stylesheet
78 Document style_doc = converter_.getDOM(new File(stylesheet));
79 GSXSLT.absoluteIncludePaths(style_doc, config_);
80 return (Element)transformer_.transform(style_doc, page);
81
82 }
83
84
85}
Note: See TracBrowser for help on using the repository browser.