1 | package org.greenstone.gsdl3.action;
|
---|
2 |
|
---|
3 | import org.greenstone.gsdl3.core.ModuleInterface;
|
---|
4 | import org.greenstone.gsdl3.util.*;
|
---|
5 | // XML classes
|
---|
6 | import org.w3c.dom.Node;
|
---|
7 | import org.w3c.dom.Document;
|
---|
8 | import org.w3c.dom.Element;
|
---|
9 |
|
---|
10 | import java.util.HashMap;
|
---|
11 | import java.io.File;
|
---|
12 |
|
---|
13 | /** action for classifier browsing */
|
---|
14 | public class BrowseAction extends Action {
|
---|
15 |
|
---|
16 | public static final String CLASSIFIER_ARG = "cl";
|
---|
17 |
|
---|
18 | /* add the action specific args to the cgi param list
|
---|
19 | */
|
---|
20 | public void addCGIParams() {
|
---|
21 | cgi_.addStaticParam(CLASSIFIER_ARG);
|
---|
22 | }
|
---|
23 |
|
---|
24 | /** process the request */
|
---|
25 | public Element process (Element message) {
|
---|
26 |
|
---|
27 | // get the request - assume only one
|
---|
28 | Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
|
---|
29 |
|
---|
30 | // create the return page tree
|
---|
31 | Element page = doc_.createElement(GSXML.PAGE_ELEM);
|
---|
32 | page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
|
---|
33 | // add the lang stuff from message
|
---|
34 | page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true));
|
---|
35 | // add the system stuff from message
|
---|
36 | page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
|
---|
37 |
|
---|
38 | return classifierBrowse(page, request);
|
---|
39 |
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
43 | protected Element classifierBrowse(Element page, Element request) {
|
---|
44 |
|
---|
45 | // check that the stylesheet is present - cant output a page without one. we may adapt this to use unknownquery stylesheet? - or ask for one from the MR
|
---|
46 | String stylesheet = GSFile.stylesheetFile(config_, "classifier.xsl");
|
---|
47 | if (stylesheet==null) {
|
---|
48 | System.err.println("BrowseAction Error: classifier stylesheet not found!");
|
---|
49 | return null;
|
---|
50 | }
|
---|
51 | Document style_doc = converter_.getDOM(new File(stylesheet));
|
---|
52 |
|
---|
53 | // extract the params from the cgi-request, and check that we have a coll specified
|
---|
54 | Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
|
---|
55 | HashMap params = GSXML.extractParams(cgi_paramList, false);
|
---|
56 |
|
---|
57 | String service_name = (String)params.get(GSCGI.SERVICE_ARG);
|
---|
58 | String collection = (String)params.get(GSCGI.COLLECTION_ARG);
|
---|
59 | if (collection == null || collection.equals("")) {
|
---|
60 | System.err.println("BrowseAction Error:classifierbrowse, need to specify a collection!");
|
---|
61 | return null;
|
---|
62 |
|
---|
63 | }
|
---|
64 |
|
---|
65 | // get the service info from the MR - this will probably need to be cached somehow later on.
|
---|
66 |
|
---|
67 | Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM);
|
---|
68 | Element mr_info_request = doc_.createElement(GSXML.REQUEST_ELEM);
|
---|
69 | mr_info_message.appendChild(mr_info_request);
|
---|
70 | mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
|
---|
71 | mr_info_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
|
---|
72 |
|
---|
73 | String to = collection;
|
---|
74 | to = GSPath.appendLink(to, service_name);
|
---|
75 | mr_info_request.setAttribute(GSXML.TO_ATT, to);
|
---|
76 |
|
---|
77 | Element mr_info_response = (Element) mr_.process(mr_info_message);
|
---|
78 |
|
---|
79 | String path = GSXML.RESPONSE_ELEM;
|
---|
80 | path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
|
---|
81 |
|
---|
82 | Element description = (Element)doc_.importNode(GSXML.getNodeByPath(mr_info_response, path), true);
|
---|
83 |
|
---|
84 | // the first part of the data for the page is the cgi-params
|
---|
85 | Element cgi_request = (Element)doc_.importNode(request, true);
|
---|
86 | page.appendChild(cgi_request);
|
---|
87 |
|
---|
88 | page.appendChild(description);
|
---|
89 |
|
---|
90 | // if there is a cl field in the cgi params, get the classifier info
|
---|
91 | String node = (String)params.get(CLASSIFIER_ARG);
|
---|
92 |
|
---|
93 | if (node!=null && !node.equals("")) {
|
---|
94 |
|
---|
95 | // get the info for the selected node
|
---|
96 | Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);
|
---|
97 | Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM);
|
---|
98 | mr_query_message.appendChild(mr_query_request);
|
---|
99 |
|
---|
100 | mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
|
---|
101 | mr_query_request.setAttribute(GSXML.TO_ATT, to);
|
---|
102 | mr_query_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
|
---|
103 |
|
---|
104 |
|
---|
105 | // paramList - empty for now
|
---|
106 | Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
|
---|
107 | mr_query_request.appendChild(paramList);
|
---|
108 |
|
---|
109 | Element document_list = doc_.createElement(GSXML.CLASS_NODE_ELEM+GSXML.LIST_MODIFIER);
|
---|
110 | Element document = doc_.createElement(GSXML.CLASS_NODE_ELEM);
|
---|
111 | document.setAttribute(GSXML.CLASS_NODE_ID_ATT, node);
|
---|
112 | document_list.appendChild(document);
|
---|
113 | mr_query_request.appendChild(document_list);
|
---|
114 |
|
---|
115 | Element mr_query_response = (Element)mr_.process(mr_query_message);
|
---|
116 |
|
---|
117 | Element response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
|
---|
118 | Node new_style = GSXML.getChildByTagName(response, GSXML.STYLESHEET_ELEM);
|
---|
119 | if (new_style !=null) {
|
---|
120 | GSXSLT.mergeStylesheets(style_doc, (Element)new_style);
|
---|
121 | response.removeChild(new_style);
|
---|
122 | }
|
---|
123 | // add the response to the page data
|
---|
124 | page.appendChild(doc_.importNode(response, true));
|
---|
125 |
|
---|
126 | }
|
---|
127 |
|
---|
128 | GSXSLT.absoluteIncludePaths(style_doc, config_);
|
---|
129 |
|
---|
130 | //System.out.println("page=");
|
---|
131 | //System.out.println(converter_.getString(page));
|
---|
132 | return (Element)transformer_.transform(style_doc, page);
|
---|
133 | }
|
---|
134 |
|
---|
135 | protected Element unknownBrowse(Element page, Element request, String browse_type) {
|
---|
136 | System.err.println("BrowseAction Error: unknown browse subtype: "+browse_type);
|
---|
137 | return null;
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|