- Timestamp:
- 2002-11-26T13:55:24+13:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/BuildAction.java
r3513 r3568 17 17 18 18 19 public Stringprocess (Element message) {19 public Element process (Element message) { 20 20 21 //find the stylesheet 21 //find the stylesheet - cant go any further if not found 22 22 String stylesheet = GSFile.stylesheetFile(config_, "build.xsl"); 23 23 24 24 if (stylesheet==null) { 25 return GSHTML.errorPage("build stylesheet not found!"); 25 System.err.println("BuildAction Error: build stylesheet not found!"); 26 return null; 26 27 } 28 29 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0); 30 String service_name = request.getAttribute(GSXML.SUBACTION_ATT); 31 // get the param list 32 Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 33 HashMap params = GSXML.extractParams(cgi_param_list); 27 34 28 35 // create the return page tree 29 36 Element page = doc_.createElement(GSXML.PAGE_ELEM); 30 page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));37 page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT)); 31 38 // add the lang stuff from message 32 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML. TRANSLATION_ELEM), true));39 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true)); 33 40 // add the system stuff from message 34 41 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 42 35 43 36 Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0); 37 String service_name = request.getAttribute(GSXML.SUBACTION_ATT); 44 // we need to do the request before getting the description- 45 // it may have changedthe action may change the descripiton, eg 46 // deleting a collection changes the collection list 47 String collection = (String)params.get("collection"); 48 String to = "build"; // knwo this cos its build action - loaded by a cluster called build 49 to = GSPath.appendLink(to, service_name); 38 50 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); 51 if (collection != null && !collection.equals("")) { 52 53 // a collection has been specified - do the request 54 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM); 55 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM); 56 mr_query_message.appendChild(mr_query_request); 57 58 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_BUILD); 59 mr_query_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 60 61 mr_query_request.setAttribute(GSXML.TO_ATT, to); 62 63 // paramList 64 Element query_param_list = (Element) doc_.importNode(cgi_param_list, true); 65 mr_query_request.appendChild(query_param_list); 66 67 Element mr_query_response = (Element)mr_.process(mr_query_message); 68 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 69 // append the response to the page 70 page.appendChild(doc_.importNode(result_response, true)); 71 } 43 72 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); 73 // another part of the page is the service description 47 74 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 75 // request the service info for the selected service - should be cached 51 76 Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM); 52 77 Element mr_info_request = doc_.createElement(GSXML.REQUEST_ELEM); 53 78 mr_info_message.appendChild(mr_info_request); 54 79 mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE); 80 mr_info_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 55 81 56 String to = "build"; // knwo this cos its build action - loaded by a cluster called build57 to = GSPath.appendLink(to, service_name);58 82 mr_info_request.setAttribute(GSXML.TO_ATT, to); 59 83 60 84 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 too65 85 66 86 String path = GSXML.RESPONSE_ELEM; 67 87 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM); 68 path = GSPath.appendLink(path, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);88 Element description = (Element)doc_.importNode(GSXML.getNodeByPath(mr_info_response, path), true); 69 89 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); 90 Element pl = (Element)GSXML.getChildByTagName(description, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 91 92 if (pl !=null) { 93 // add short names to the params in the param list 94 cgi_.addShortNames(pl); 80 95 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); 96 // for each param in the description, overwrite teh default value with the currently set value if present 97 Element param = (Element)pl.getFirstChild(); 98 while (param !=null) { 99 if (param.getNodeName().equals(GSXML.PARAM_ELEM)) { // just in case 100 String name = param.getAttribute(GSXML.NAME_ATT); 101 String current = (String)params.get(name); 102 if (current !=null && !current.equals("")) { 103 param.setAttribute(GSXML.DEFAULT_ATT, current); 104 } 93 105 } 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 // } 106 param = (Element)param.getNextSibling(); 134 107 } 135 108 } 109 page.appendChild(description); 110 111 // part of the data for the page is the cgi-params 112 // if we have this here, do we need to do the previous step? 113 Element cgi_request = (Element)doc_.importNode(request, true); 114 page.appendChild(cgi_request); 136 115 137 Element mr_query_response = (Element)mr_.process(mr_query_message);138 116 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 117 // now process the page and return the result 143 118 Document style_doc = converter_.getDOM(new File(stylesheet)); 144 119 145 120 GSXSLT.absoluteIncludePaths(style_doc, config_); 146 return transformer_.transform(style_doc, page);121 return (Element)transformer_.transform(style_doc, page); 147 122 } 148 123 }
Note:
See TracChangeset
for help on using the changeset viewer.