Changeset 3603
- Timestamp:
- 2002-12-02T10:02:33+13:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/QueryAction.java
r3568 r3603 18 18 public class QueryAction extends Action { 19 19 20 /** process - processes a request. 21 */ 20 22 public Element process (Element message) { 21 23 … … 31 33 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 32 34 33 // query type is teh subaction 34 String query_type = request.getAttribute(GSXML.SUBACTION_ATT); 35 36 if (query_type.equals("")) { 37 query_type = "text"; 38 } 39 40 if (query_type.equals("text")) { 41 return textQuery(page, request); 42 } 43 if (query_type.equals("field")) { 44 return fieldQuery(page, request); 45 } 46 return unknownQuery(page, request, query_type); 47 35 // query type is the subaction 36 String query_type = request.getAttribute(GSXML.SUBACTION_ATT) + "Query"; 37 38 // for now assume all queries can be handled by basic query 39 return basicQuery(page, request, query_type); 48 40 49 41 } 50 42 51 // we may be able to generalize this for all query types? 52 protected Element textQuery(Element page, Element request) { 53 54 // 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 55 String stylesheet = GSFile.stylesheetFile(config_, "textquery.xsl"); 43 /** a generic query handler 44 * this gets the service description, does the query (just passes all teh 45 * params to the service, then gets the titles for any results 46 */ 47 protected Element basicQuery(Element page, Element request, String service_name) { 48 49 // check that the stylesheet is present - cant output the page without one. 50 String stylesheet = GSFile.stylesheetFile(config_, "basicquery.xsl"); 56 51 if (stylesheet==null) { 57 System.err.println("QueryAction Error: textquery stylesheet not found!");52 System.err.println("QueryAction Error: basicquery stylesheet not found!"); 58 53 return null; 59 54 } … … 61 56 // extract the params from the cgi-request, and check that we have a coll specified 62 57 Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 58 63 59 HashMap params = GSXML.extractParams(cgi_param_list); 64 60 65 61 String collection = (String)params.get("collection"); 66 62 if (collection == null || collection.equals("")) { 67 System.err.println("QueryAction Error: no collec iton was specified!");63 System.err.println("QueryAction Error: no collection was specified!"); 68 64 return null; 69 65 } … … 77 73 78 74 String to = collection; 79 to = GSPath.appendLink(to, "TextQuery");75 to = GSPath.appendLink(to, service_name); 80 76 mr_info_request.setAttribute(GSXML.TO_ATT, to); 81 77 82 78 Element mr_info_response = (Element) mr_.process(mr_info_message); 83 79 System.out.println("describe response from query="); 80 System.out.println(converter_.getString(mr_info_response)); 84 81 String path = GSXML.RESPONSE_ELEM; 85 82 path = GSPath.appendLink(path, GSXML.SERVICE_ELEM); … … 88 85 89 86 if (pl !=null) { 87 System.out.println("adding shortnames"); 90 88 // add short names to the params in the param list 91 89 cgi_.addShortNames(pl); 92 93 90 // for each param in the description, overwrite teh default value with the currently set value if present 94 91 Element param = (Element)pl.getFirstChild(); 95 92 while (param !=null) { 96 93 if (param.getNodeName().equals(GSXML.PARAM_ELEM)) { // just in case 97 String name = param.getAttribute(GSXML.NAME_ATT); 98 String current = (String)params.get(name); 99 if (current !=null && !current.equals("")) { 100 param.setAttribute(GSXML.DEFAULT_ATT, current); 94 if (param.getAttribute(GSXML.TYPE_ATT).equals(GSXML.PARAM_TYPE_MULTI)) { 95 // get the values for each sub param 96 NodeList subparams = param.getElementsByTagName(GSXML.PARAM_ELEM); 97 for (int i=0; i<subparams.getLength(); i++) { 98 String name = ((Element)subparams.item(i)).getAttribute(GSXML.NAME_ATT); 99 String current = (String)params.get(name); 100 if (current !=null && !current.equals("")) { 101 Element e = GSXML.createTextElement(pl.getOwnerDocument(), GSXML.DEFAULT_ELEM, current); 102 e.setAttribute(GSXML.NAME_ATT, name); 103 param.appendChild(e); 104 } 105 } 106 } else { 107 108 String name = param.getAttribute(GSXML.NAME_ATT); 109 String current = (String)params.get(name); 110 if (current !=null && !current.equals("")) { 111 param.setAttribute(GSXML.DEFAULT_ATT, current); 112 } 101 113 } 102 114 } … … 104 116 } 105 117 } 118 System.out.println(converter_.getString(pl)); 106 119 107 120 // part of the data for the description is the cgi-params … … 111 124 112 125 page.appendChild(description); 113 114 // check the query string 115 String query = (String)params.get(GSXML.REQUEST_TYPE_QUERY); 116 117 if (query!=null&& !query.equals("")) { 118 // do the query 119 120 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM); 121 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM); 122 mr_query_message.appendChild(mr_query_request); 123 124 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 125 mr_query_request.setAttribute(GSXML.TO_ATT, to); 126 mr_query_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 127 // paramList 128 // should we remove the query from the param list? 129 Element query_param_list = (Element)doc_.importNode(cgi_param_list, true); 130 mr_query_request.appendChild(query_param_list); 131 132 // content - contains the query string 133 Element query_content = GSXML.createTextElement(doc_, GSXML.CONTENT_ELEM, query); 134 mr_query_request.appendChild(query_content); 135 136 Element mr_query_response = (Element)mr_.process(mr_query_message); 137 138 // this result is the list of docs. 139 // now take that list, and get the Titles 140 // for now, just create a whole new request 141 142 // check that there are some resources - for now check the list, but later should use a numdocs metadata elem 143 path = GSXML.RESPONSE_ELEM; 144 path = GSPath.appendLink(path, GSXML.CONTENT_ELEM); 145 path = GSPath.appendLink(path, GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER); 146 147 Element resource_list = (Element)GSXML.getNodeByPath(mr_query_response, 148 path); // resourceList not present if no docs found 149 if (resource_list == null) { 150 151 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 152 153 page.appendChild(doc_.importNode(result_response, true)); 154 155 Document style_doc = converter_.getDOM(new File(stylesheet)); 156 GSXSLT.absoluteIncludePaths(style_doc, config_); 157 return (Element)transformer_.transform(style_doc, page); 158 159 } 160 161 // we have a doc list, so get the metadata - for now, get title. 162 // can we dynamically decide what metadata to get? 163 Element mr_metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM); 164 Element mr_metadata_request = doc_.createElement(GSXML.REQUEST_ELEM); 165 mr_metadata_message.appendChild(mr_metadata_request); 166 167 mr_metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 168 mr_metadata_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 169 to = GSPath.appendLink(collection, "MetadataRetrieve"); 170 mr_metadata_request.setAttribute(GSXML.TO_ATT, to); 171 172 Element meta_content = doc_.createElement(GSXML.CONTENT_ELEM); 173 mr_metadata_request.appendChild(meta_content); 174 175 // the first part of the content is the doc list 176 meta_content.appendChild(doc_.importNode(resource_list, true)); 177 178 // the second part of the content is the metadata list 179 Element metadata_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 180 Element title = doc_.createElement(GSXML.METADATA_ELEM); 181 title.setAttribute(GSXML.NAME_ATT, "Title"); 182 metadata_list.appendChild(title); 183 meta_content.appendChild(metadata_list); 184 185 Element mr_metadata_response = (Element)mr_.process(mr_metadata_message); 186 187 Element result_response = (Element)GSXML.getChildByTagName(mr_metadata_response, GSXML.RESPONSE_ELEM); 126 127 // now we always do the query - we have no way of knowing whether 128 // a query was specified or not cos we cant assume that q is the 129 // query string - maybe we could check that any required params have 130 // a value?? 131 132 Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM); 133 Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM); 134 mr_query_message.appendChild(mr_query_request); 135 136 mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 137 mr_query_request.setAttribute(GSXML.TO_ATT, to); 138 mr_query_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 139 // paramList 140 Element query_param_list = (Element)doc_.importNode(cgi_param_list, true); 141 mr_query_request.appendChild(query_param_list); 142 143 144 Element mr_query_response = (Element)mr_.process(mr_query_message); 145 146 // this result is the list of docs. 147 // now take that list, and get the Titles 148 // for now, just create a whole new request 149 150 // check that there are some resources - for now check the list, but later should use a numdocs metadata elem 151 path = GSXML.RESPONSE_ELEM; 152 path = GSPath.appendLink(path, GSXML.CONTENT_ELEM); 153 path = GSPath.appendLink(path, GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER); 154 155 Element resource_list = (Element)GSXML.getNodeByPath(mr_query_response, 156 path); // resourceList not present if no docs found 157 if (resource_list == null) { 158 159 Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM); 188 160 189 161 page.appendChild(doc_.importNode(result_response, true)); 190 191 } // do teh query 192 162 163 Document style_doc = converter_.getDOM(new File(stylesheet)); 164 GSXSLT.absoluteIncludePaths(style_doc, config_); 165 return (Element)transformer_.transform(style_doc, page); 166 167 } 168 169 // we have a doc list, so get the metadata - for now, get title. 170 // can we dynamically decide what metadata to get? 171 Element mr_metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM); 172 Element mr_metadata_request = doc_.createElement(GSXML.REQUEST_ELEM); 173 mr_metadata_message.appendChild(mr_metadata_request); 174 175 mr_metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY); 176 mr_metadata_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT)); 177 to = GSPath.appendLink(collection, "MetadataRetrieve"); 178 mr_metadata_request.setAttribute(GSXML.TO_ATT, to); 179 180 Element meta_content = doc_.createElement(GSXML.CONTENT_ELEM); 181 mr_metadata_request.appendChild(meta_content); 182 183 // the first part of the content is the doc list 184 meta_content.appendChild(doc_.importNode(resource_list, true)); 185 186 // the second part of the content is the metadata list 187 Element metadata_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 188 Element title = doc_.createElement(GSXML.METADATA_ELEM); 189 title.setAttribute(GSXML.NAME_ATT, "Title"); 190 metadata_list.appendChild(title); 191 meta_content.appendChild(metadata_list); 192 193 Element mr_metadata_response = (Element)mr_.process(mr_metadata_message); 194 195 Element result_response = (Element)GSXML.getChildByTagName(mr_metadata_response, GSXML.RESPONSE_ELEM); 196 197 page.appendChild(doc_.importNode(result_response, true)); 198 193 199 194 200 // output the page … … 200 206 } 201 207 202 protected Element fieldQuery(Element page, Element request) { 203 String p = GSHTML.errorPage("field query not implemented"); 204 205 return converter_.getDOM(p).getDocumentElement(); 206 } 207 protected Element unknownQuery(Element page, Element request, String query_type) { 208 209 String p = GSHTML.errorPage("unknown query subtype - "+query_type+" query not implemented"); 210 return null;//converter_.getDOM(p).getDocumentElement(); 211 } 208 212 209 }
Note:
See TracChangeset
for help on using the changeset viewer.