source: trunk/gsdl3/src/java/org/greenstone/gsdl3/action/BrowseAction.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: 5.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 for classifier browsing */
14public class BrowseAction extends Action {
15
16 public Element process (Element message) {
17
18 // get the request - assume only one
19 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
20
21 // create the return page tree
22 Element page = doc_.createElement(GSXML.PAGE_ELEM);
23 page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
24 // add the lang stuff from message
25 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true));
26 // add the system stuff from message
27 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
28
29
30 // the browse type is the subaction
31 String browse_type = request.getAttribute(GSXML.SUBACTION_ATT);
32
33 if (browse_type.equals("Classifier")) {
34 return classifierBrowse(page, request);
35 }
36 return unknownBrowse(page, request, browse_type);
37
38
39 }
40
41
42 protected Element classifierBrowse(Element page, Element request) {
43
44 // 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
45 String stylesheet = GSFile.stylesheetFile(config_, "classifier.xsl");
46 if (stylesheet==null) {
47 System.err.println("BrowseAction Error: classifier stylesheet not found!");
48 return null;
49 }
50 Document style_doc = converter_.getDOM(new File(stylesheet));
51
52 // extract the params from the cgi-request, and check that we have a coll specified
53 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
54 HashMap params = GSXML.extractParams(cgi_paramList);
55
56 String collection = (String)params.get(GSCGI.COLLECTION_ARG);
57 if (collection == null || collection.equals("")) {
58 System.err.println("BrowseAction Error:classifierbrowse, need to specify a collection!");
59 return null;
60
61 }
62
63
64 // get the service info from the MR - this will probably need to be cached somehow later on.
65
66 Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM);
67 Element mr_info_request = doc_.createElement(GSXML.REQUEST_ELEM);
68 mr_info_message.appendChild(mr_info_request);
69 mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
70 mr_info_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
71
72 String to = collection;
73 to = GSPath.appendLink(to, "ClassifierBrowse");
74 mr_info_request.setAttribute(GSXML.TO_ATT, to);
75
76 Element mr_info_response = (Element) mr_.process(mr_info_message);
77
78 String path = GSXML.RESPONSE_ELEM;
79 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
80
81 Element description = (Element)doc_.importNode(GSXML.getNodeByPath(mr_info_response, path), true);
82
83 // the first part of the data for the page is the cgi-params
84 Element cgi_request = (Element)doc_.importNode(request, true);
85 page.appendChild(cgi_request);
86
87 page.appendChild(description);
88
89 // if there is a cl field in the cgi params, get the classifier info
90 String node = (String)params.get("cl");
91
92 if (node!=null && !node.equals("")) {
93
94 // get the info for the selected node
95 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);
96 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM);
97 mr_query_message.appendChild(mr_query_request);
98
99 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
100 mr_query_request.setAttribute(GSXML.TO_ATT, to);
101 mr_query_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
102
103
104 // paramList - empty for now
105 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
106 mr_query_request.appendChild(paramList);
107
108
109 // content - contains the classifier node, may be more than one
110 // call this document list for now
111 Element query_content = doc_.createElement(GSXML.CONTENT_ELEM);
112 mr_query_request.appendChild(query_content);
113
114 Element document_list = doc_.createElement(GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
115 Element document = doc_.createElement(GSXML.DOCUMENT_ELEM);
116 document.setAttribute(GSXML.NAME_ATT, node);
117 document_list.appendChild(document);
118 query_content.appendChild(document_list);
119
120 Element mr_query_response = (Element)mr_.process(mr_query_message);
121
122 Element response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
123 Node new_style = GSXML.getChildByTagName(response, "stylesheet");
124 if (new_style !=null) {
125 GSXSLT.mergeStylesheets(style_doc, (Element)new_style);
126 response.removeChild(new_style);
127 }
128 // add the response to the page data
129 page.appendChild(doc_.importNode(response, true));
130
131 }
132
133 GSXSLT.absoluteIncludePaths(style_doc, config_);
134 return (Element)transformer_.transform(style_doc, page);
135 }
136
137 protected Element unknownBrowse(Element page, Element request, String browse_type) {
138 System.err.println("BrowseAction Error: unknown browse subtype: "+browse_type);
139 return null;
140 }
141}
Note: See TracBrowser for help on using the repository browser.