source: trunk/gsdl3/src/java/org/greenstone/gsdl3/action/BuildAction.java@ 3513

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

new service and action for coll building gsdl2 style

  • 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.NodeList;
8import org.w3c.dom.Document;
9import org.w3c.dom.Element;
10
11import java.util.HashMap;
12import java.util.Map;
13import java.util.Iterator;
14import java.io.File;
15
16public class BuildAction extends Action {
17
18
19 public String process (Element message) {
20
21 //find the stylesheet
22 String stylesheet = GSFile.stylesheetFile(config_, "build.xsl");
23
24 if (stylesheet==null) {
25 return GSHTML.errorPage("build stylesheet not found!");
26 }
27
28 // create the return page tree
29 Element page = doc_.createElement(GSXML.PAGE_ELEM);
30 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));
31 // add the lang stuff from message
32 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true));
33 // add the system stuff from message
34 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
35
36 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);
37 String service_name = request.getAttribute(GSXML.SUBACTION_ATT);
38
39 // get the param list
40 Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
41 cgi_.toLong(cgi_paramList);
42 HashMap params = GSXML.extractParams(cgi_paramList);
43
44 // the first part of the data for the page is the cgi-params
45 Element cgi_request = (Element)doc_.importNode(request, true);
46 page.appendChild(cgi_request);
47
48 // the second part of the page is the param list for the service
49 // request the service info for the selected service - should be cached?
50
51 Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM);
52 Element mr_info_request = doc_.createElement(GSXML.REQUEST_ELEM);
53 mr_info_message.appendChild(mr_info_request);
54 mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
55
56 String to = "build"; // knwo this cos its build action - loaded by a cluster called build
57 to = GSPath.appendLink(to, service_name);
58 mr_info_request.setAttribute(GSXML.TO_ATT, to);
59
60 Element mr_info_response = (Element) mr_.process(mr_info_message);
61 System.err.println("describe response for service");
62 System.err.println(converter_.getString(mr_info_response));
63 Element description = doc_.createElement(GSXML.DESCRIPTION_ELEM);
64 // just param list for now - may need content info too
65
66 String path = GSXML.RESPONSE_ELEM;
67 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
68 path = GSPath.appendLink(path, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
69
70 Node pl = GSXML.getNodeByPath(mr_info_response, path);
71 if (pl ==null) {
72 System.out.println("pl is null");
73 }
74 else {
75 System.out.println("pl name is "+pl.getNodeName());
76 }
77 Element imported_paramList = (Element)doc_.importNode(pl, true);
78 // convert the name to short
79 cgi_.addShortNames(imported_paramList);
80
81 description.appendChild(imported_paramList);
82
83 // for each param in page_request, set the current value if present
84 //actually, prob dont need to know the default value, just which one to display - overwrite the default att?
85
86 Element param = (Element)imported_paramList.getFirstChild();
87 while (param !=null) {
88 if (param.getNodeName().equals(GSXML.PARAM_ELEM)) { // just in case
89 String name = param.getAttribute(GSXML.NAME_ATT);
90 String current = (String)params.get(name);
91 if (current !=null && !current.equals("")) {
92 param.setAttribute(GSXML.DEFAULT_ATT, current);
93 }
94 }
95 param = (Element)param.getNextSibling();
96 }
97
98 cgi_request.appendChild(description);
99
100 // now see if we need to actually do anything - only if a colleciton has been set
101 String collection = (String)params.get("collection");
102 if (collection == null || collection.equals("")) {
103 // no coll set - just output the form
104
105 Document style_doc = converter_.getDOM(new File(stylesheet));
106 GSXSLT.absoluteIncludePaths(style_doc, config_);
107 return transformer_.transform(style_doc, page);
108 }
109
110 // else do the request, output search box and results
111 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);
112 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM);
113 mr_query_message.appendChild(mr_query_request);
114
115 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_BUILD);
116 mr_query_request.setAttribute(GSXML.TO_ATT, to);
117
118 // paramList
119 Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
120 mr_query_request.appendChild(paramList);
121
122 Iterator i = params.entrySet().iterator();
123 while (i.hasNext()) {
124 Map.Entry e = (Map.Entry)i.next();
125 String name = cgi_.toLong((String)e.getKey());
126 if (!name.equals("")) {
127 String value = (String)e.getValue();
128 // if (!name.equals("c")) {
129 Element p = doc_.createElement(GSXML.PARAM_ELEM);
130 p.setAttribute(GSXML.NAME_ATT, name);
131 p.setAttribute(GSXML.VALUE_ATT, value);
132 paramList.appendChild(p);
133 // }
134 }
135 }
136
137 Element mr_query_response = (Element)mr_.process(mr_query_message);
138
139 // this result is a message
140 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
141 page.appendChild(doc_.importNode(result_response, true));
142
143 Document style_doc = converter_.getDOM(new File(stylesheet));
144
145 GSXSLT.absoluteIncludePaths(style_doc, config_);
146 return transformer_.transform(style_doc, page);
147 }
148}
Note: See TracBrowser for help on using the repository browser.