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

Last change on this file since 3467 was 3467, checked in by kjdon, 22 years ago

the xml representation of cgi args now has two attributes 'action' and 'subaction', instead of the single 'info' attribute

  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 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;
12public class BrowseAction extends Action {
13
14
15 public String process (Element message) {
16
17 // create the return page tree
18 Element page = doc_.createElement("page");
19 page.setAttribute("lang", message.getAttribute("lang"));
20 // add the lang stuff from message
21 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true));
22 // add the system stuff from message
23 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true));
24
25 Element request = (Element)message.getElementsByTagName("request").item(0);
26
27 // the browse type is the subaction
28 String browse_type = request.getAttribute("subaction");
29
30 if (browse_type.equals("classifier")) {
31 return classifierBrowse(page, request);
32 }
33 return unknownBrowse(page, request, browse_type);
34
35
36 }
37
38
39 protected String classifierBrowse(Element page, Element request) {
40
41 // 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
42 String stylesheet = GSFile.stylesheetFile(config_, "classifier.xsl");
43 if (stylesheet==null) {
44 return GSHTML.errorPage("classifier stylesheet not found!");
45 }
46 Document style_doc = converter_.getDOM(new File(stylesheet));
47
48 // extract the params from the cgi-request, and check that we have a coll specified
49 // first convert short to long names
50 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, "paramList");
51 cgi_.toLong(cgi_paramList);
52 HashMap params = GSXML.extractParams(cgi_paramList);
53
54 String collection = (String)params.get("c");
55 if (collection == null || collection.equals("")) {
56 return GSHTML.errorPage("classifierbrowse, need to specify a collection!");
57 }
58
59 // the first part of the data for the page is the cgi-params
60 Element cgi_request = (Element)doc_.importNode(request, true);
61 page.appendChild(cgi_request);
62
63 // get the service info from the MR - this will probably need to be cached somehow later on. and add as a description node to the cgi-request - this doesn't work. change to add the specified value as a current attribute to the param - need to do somthing different for query
64
65 Element mr_info_message = doc_.createElement("message");
66 Element mr_info_request = doc_.createElement("request");
67 mr_info_message.appendChild(mr_info_request);
68 mr_info_request.setAttribute("type", "describe");
69
70 String to = collection;
71 to = GSPath.appendLink(to, "ClassifierBrowse");
72 mr_info_request.setAttribute("to", to);
73
74 Element mr_info_response = (Element) mr_.process(mr_info_message);
75 Element description = doc_.createElement("description");
76 Node cl = GSXML.getNodeByPath(mr_info_response, "response/service/classifierList");
77
78 Element imported_classList = (Element)doc_.importNode(cl, true);
79
80 description.appendChild(imported_classList);
81 cgi_request.appendChild(description);
82
83
84 // if there is a cl field in the cgi params, get the classifier info
85 String node = (String)params.get("cl");
86
87 if (node==null|| node.equals("")) {
88 System.out.println("no cl node selected");
89 // if there is no cl set, just output the list
90 GSXSLT.absoluteIncludePaths(style_doc, config_);
91 return transformer_.transform(style_doc, page);
92 }
93
94 // get the info for the selected node
95 Element mr_query_message = doc_.createElement("message");
96 Element mr_query_request = doc_.createElement("request");
97 mr_query_message.appendChild(mr_query_request);
98
99 mr_query_request.setAttribute("type", "query");
100 mr_query_request.setAttribute("to", to);
101
102 // paramList - empty for now
103 Element paramList = doc_.createElement("paramList");
104 mr_query_request.appendChild(paramList);
105
106
107 // content - contains the classifier node, may be more than one
108 // call this resource list for now
109 Element query_content = doc_.createElement("content");
110 mr_query_request.appendChild(query_content);
111
112 Element resource_list = doc_.createElement("resourceList");
113 Element resource = doc_.createElement("resource");
114 resource.setAttribute("name", node);
115 resource_list.appendChild(resource);
116 query_content.appendChild(resource_list);
117
118 Element mr_query_response = (Element)mr_.process(mr_query_message);
119
120 Element response = (Element)GSXML.getChildByTagName(mr_query_response, "response");
121 Node new_style = GSXML.getChildByTagName(response, "stylesheet");
122 if (new_style !=null) {
123 GSXSLT.mergeStylesheets(style_doc, (Element)new_style);
124 response.removeChild(new_style);
125 }
126 // add the response to the page data
127 page.appendChild(doc_.importNode(response, true));
128
129 GSXSLT.absoluteIncludePaths(style_doc, config_);
130 return transformer_.transform(style_doc, page);
131 }
132
133 protected String unknownBrowse(Element page, Element request, String browse_type) {
134
135 return GSHTML.errorPage("unknown browse subtype: "+browse_type);
136 }
137}
Note: See TracBrowser for help on using the repository browser.