source: trunk/gsdl3/src/java/org/greenstone/gsdl3/action/BrowseAction.java@ 3604

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

* empty log message *

  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 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 // first convert short to long names
54 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
55 cgi_.toLong(cgi_paramList);
56 HashMap params = GSXML.extractParams(cgi_paramList);
57
58 String collection = (String)params.get("collection");
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
66 // get the service info from the MR - this will probably need to be cached somehow later on.
67
68 Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM);
69 Element mr_info_request = doc_.createElement(GSXML.REQUEST_ELEM);
70 mr_info_message.appendChild(mr_info_request);
71 mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
72 mr_info_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
73
74 String to = collection;
75 to = GSPath.appendLink(to, "ClassifierBrowse");
76 mr_info_request.setAttribute(GSXML.TO_ATT, to);
77
78 Element mr_info_response = (Element) mr_.process(mr_info_message);
79
80 String path = GSXML.RESPONSE_ELEM;
81 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
82
83 Element description = (Element)doc_.importNode(GSXML.getNodeByPath(mr_info_response, path), true);
84
85 // the first part of the data for the page is the cgi-params
86 Element cgi_request = (Element)doc_.importNode(request, true);
87 page.appendChild(cgi_request);
88
89 page.appendChild(description);
90
91 // if there is a cl field in the cgi params, get the classifier info
92 String node = (String)params.get("classifier");
93
94 if (node!=null && !node.equals("")) {
95
96 // get the info for the selected node
97 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);
98 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM);
99 mr_query_message.appendChild(mr_query_request);
100
101 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
102 mr_query_request.setAttribute(GSXML.TO_ATT, to);
103 mr_query_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
104
105
106 // paramList - empty for now
107 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
108 mr_query_request.appendChild(paramList);
109
110
111 // content - contains the classifier node, may be more than one
112 // call this resource list for now
113 Element query_content = doc_.createElement(GSXML.CONTENT_ELEM);
114 mr_query_request.appendChild(query_content);
115
116 Element resource_list = doc_.createElement(GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER);
117 Element resource = doc_.createElement(GSXML.RESOURCE_ELEM);
118 resource.setAttribute(GSXML.NAME_ATT, node);
119 resource_list.appendChild(resource);
120 query_content.appendChild(resource_list);
121
122 Element mr_query_response = (Element)mr_.process(mr_query_message);
123
124 Element response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
125 Node new_style = GSXML.getChildByTagName(response, "stylesheet");
126 if (new_style !=null) {
127 GSXSLT.mergeStylesheets(style_doc, (Element)new_style);
128 response.removeChild(new_style);
129 }
130 // add the response to the page data
131 page.appendChild(doc_.importNode(response, true));
132
133 }
134
135 GSXSLT.absoluteIncludePaths(style_doc, config_);
136 return (Element)transformer_.transform(style_doc, page);
137 }
138
139 protected Element unknownBrowse(Element page, Element request, String browse_type) {
140 System.err.println("BrowseAction Error: unknown browse subtype: "+browse_type);
141 return null;
142 }
143}
Note: See TracBrowser for help on using the repository browser.