Changeset 4023
- Timestamp:
- 2003-03-28T09:55:57+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/action/DocumentAction.java
r3997 r4023 41 41 public static final String SIBLING_ARG = "sib"; 42 42 43 /** if this is set to true, when a document is displayed, any annotation 44 * type services (enrich) will be offered to the user as well */ 45 protected static final boolean provide_annotations = true; 46 43 47 /* add the action specific args to the cgi param list 44 48 */ … … 52 56 // for now, no subaction eventually we may want to have subactions such as text assoc or something ? 53 57 58 // check that the stylesheet is present 59 String stylesheet = GSFile.stylesheetFile(config_, "document.xsl"); 60 if (stylesheet == null) { 61 System.err.println("DocumentAction Error: document stylesheet not found!"); 62 return null; 63 } 64 54 65 // get the request - assume only one 55 66 Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM); … … 58 69 59 70 String collection = (String) params.get(GSCGI.COLLECTION_ARG); 60 String to;71 String lang = request.getAttribute(GSXML.LANG_ATT); 61 72 String document_name = (String) params.get(GSCGI.DOCUMENT_ARG); 62 73 if (document_name == null || document_name.equals("")) { … … 64 75 return null; 65 76 } 77 66 78 //whether to retrieve siblings or not 67 79 boolean get_siblings = false; … … 71 83 } 72 84 85 // Create the return page tree 86 Element page = doc_.createElement(GSXML.PAGE_ELEM); 87 page.setAttribute(GSXML.LANG_ATT, lang); 88 89 // Add the display element, config stuff, and original request from the message 90 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true)); 91 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true)); 92 Element page_request = GSXML.duplicateWithNewName(doc_, request, GSXML.PAGE_REQUEST_ELEM, true); 93 page.appendChild(page_request); 94 // the element for all the response data 95 Element page_response = doc_.createElement(GSXML.PAGE_RESPONSE_ELEM); 96 page.appendChild(page_response); 97 98 // get the additional data needed for the page 99 getBackgroundData(page_response, collection, lang); 100 101 // the_document is where all the doc info - structure and metadata etc 102 //- is added into, to be returned in the page 103 Element the_document = doc_.createElement(GSXML.DOCUMENT_ELEM); 104 page_response.appendChild(the_document); 105 106 73 107 // Build a request to obtain the document structure 74 108 Element ds_message = doc_.createElement(GSXML.MESSAGE_ELEM); 75 Element ds_request = doc_.createElement(GSXML.REQUEST_ELEM); 109 String to = GSPath.appendLink(collection, "DocumentStructureRetrieve"); // Hard-wired? 110 Element ds_request = GSXML.createBasicRequest(doc_,GSXML.REQUEST_TYPE_PROCESS, to, lang); 76 111 ds_message.appendChild(ds_request); 77 to = GSPath.appendLink(collection, "DocumentStructureRetrieve"); // Hard-wired?78 ds_request.setAttribute(GSXML.TO_ATT, to);79 ds_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);80 ds_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));81 112 82 113 // Create a parameter list to specify the required structure information … … 115 146 Element ds_response_structure = (Element) GSXML.getNodeByPath(ds_response_message, path); 116 147 117 // the_document is where all the extra info is added into, to be returned in the page118 Element the_document = doc_.createElement(GSXML.DOCUMENT_ELEM);119 148 // add the contents of the structure bit into the_document 120 149 NodeList structs = ds_response_structure.getChildNodes(); … … 125 154 // Build a request to obtain some document metadata 126 155 Element dm_message = doc_.createElement(GSXML.MESSAGE_ELEM); 127 Element dm_request = doc_.createElement(GSXML.REQUEST_ELEM); 156 to = GSPath.appendLink(collection, "DocumentMetadataRetrieve"); // Hard-wired? 157 Element dm_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_PROCESS, to, lang); 128 158 dm_message.appendChild(dm_request); 129 to = GSPath.appendLink(collection, "DocumentMetadataRetrieve"); // Hard-wired?130 dm_request.setAttribute(GSXML.TO_ATT, to);131 dm_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);132 dm_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));133 134 159 // Create a parameter list to specify the required metadata information 135 160 // for now get Title … … 175 200 // Build a request to obtain some document content 176 201 Element dc_message = doc_.createElement(GSXML.MESSAGE_ELEM); 177 Element dc_request = doc_.createElement(GSXML.REQUEST_ELEM); 202 to = GSPath.appendLink(collection, "DocumentContentRetrieve"); // Hard-wired? 203 Element dc_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_PROCESS, to, lang); 178 204 dc_message.appendChild(dc_request); 179 to = GSPath.appendLink(collection, "DocumentContentRetrieve"); // Hard-wired? 180 dc_request.setAttribute(GSXML.TO_ATT, to); 181 dc_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS); 182 dc_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT)); 205 183 206 184 207 // Create a parameter list to specify the request parameters - empty for now … … 193 216 path = GSPath.appendLink(path, GSXML.DOC_NODE_ELEM); 194 217 Element dc_response_doc = (Element) GSXML.getNodeByPath(dc_response_message, path); 195 //path = GSPath.appendLink(path, GSXML.DOC_NODE_CONTENT_ELEM);196 218 Element dc_response_doc_content = (Element) GSXML.getChildByTagName(dc_response_doc, GSXML.NODE_CONTENT_ELEM); 219 if (provide_annotations) { 220 // now we can modifiy the response doc if needed 221 String enrich_service = (String)params.get(GSCGI.SERVICE_ARG); 222 if (enrich_service != null && !enrich_service.equals("")) { 223 // send a message to the service 224 Element enrich_message = doc_.createElement(GSXML.MESSAGE_ELEM); 225 Element enrich_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_PROCESS, enrich_service, lang); 226 enrich_message.appendChild(enrich_request); 227 Element enrich_pl = getServiceParamList(cgi_paramList); 228 enrich_request.appendChild(enrich_pl); 229 Element doc_list = doc_.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); 230 enrich_request.appendChild(doc_list); 231 doc_list.appendChild(doc_.importNode(dc_response_doc, true)); 232 233 Element enrich_response = mr_.process(enrich_message); 234 235 String [] links = {GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM, GSXML.NODE_CONTENT_ELEM}; 236 path = GSPath.createPath(links); 237 System.out.println("enrich path = "+path); 238 239 //appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER); 240 //path = GSPath.appendLink(GSXML.DOC_NODE_ELEM 241 dc_response_doc_content = (Element)GSXML.getNodeByPath(enrich_response, path); 242 } 243 } 197 244 // use the returned id rather than the sent one cos there may have 198 245 // been modifiers such as .pr that are removed. 199 246 String modified_doc_id = dc_response_doc.getAttribute(GSXML.NODE_ID_ATT); 247 the_document.setAttribute("selectedNode", modified_doc_id); 200 248 // Merge the document content with the metadata and structure information 201 249 for (int i = 0; i < doc_nodes.getLength(); i++) { … … 209 257 } 210 258 211 // Create the return page tree212 Element page = doc_.createElement(GSXML.PAGE_ELEM);213 page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));214 215 // Add the display element, config stuff, and original request from the message216 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true));217 page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));218 Element page_request = GSXML.duplicateWithNewName(doc_, request, "pageRequest", true);219 page.appendChild(page_request);220 221 // get the collection or cluster description - for the httpAddress type metadata222 Element coll_about_message = doc_.createElement(GSXML.MESSAGE_ELEM);223 Element coll_about_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_DESCRIBE, collection, page.getAttribute(GSXML.LANG_ATT));224 coll_about_message.appendChild(coll_about_request);225 Element coll_about_response = (Element)mr_.process(coll_about_message);226 227 // add the response to the page228 Element response = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM);229 Element page_response = GSXML.duplicateWithNewName(doc_, response, "pageResponse", false);230 page_response.appendChild(the_document);231 232 // Add the results of the action to the page233 page.appendChild(page_response);234 System.out.println("Page:\n" + converter_.getPrettyString(page));235 236 // Finally, process using the stylesheet, and return237 String stylesheet = GSFile.stylesheetFile(config_, "document.xsl");238 if (stylesheet == null) {239 System.err.println("DocumentAction Error: document stylesheet not found!");240 return null;241 }242 259 243 260 Document style_doc = converter_.getDOM(new File(stylesheet)); … … 245 262 return (Element) transformer_.transform(style_doc, page); 246 263 } 264 265 protected Element getServiceParamList(Element cgi_param_list) { 266 267 Element new_param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 268 Element param; 269 NodeList cgi_params = cgi_param_list.getChildNodes(); 270 for (int i=0; i<cgi_params.getLength(); i++) { 271 Element p = (Element) cgi_params.item(i); 272 String name = p.getAttribute(GSXML.NAME_ATT); 273 if (name.equals(GSCGI.SERVICE_ARG) || name.equals(GSCGI.REQUEST_TYPE_ARG) || name.equals(GSCGI.CLUSTER_ARG) || name.equals(GSCGI.DOCUMENT_ARG) || name.equals(SIBLING_ARG) ) { 274 continue; 275 } 276 // esle add it in to the list 277 new_param_list.appendChild(doc_.importNode(p, true)); 278 } 279 return new_param_list; 280 } 281 282 /** this method gets the collection description, the format info, the 283 * list of enrich services, etc - stuff that is needed for the page, 284 * but is the same whatever the query is - should be cached */ 285 protected boolean getBackgroundData(Element page_response, 286 String collection, String lang) { 287 288 // create a message to process - contains requests for the collection 289 // description, the format element, the enrich services on offer 290 // these could all be cached 291 Element info_message = doc_.createElement(GSXML.MESSAGE_ELEM); 292 293 // the collection request 294 Element coll_about_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_DESCRIBE, collection, lang); 295 info_message.appendChild(coll_about_request); 296 297 // the format request - ignore for now, where does this request go to?? 298 //Element format_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_FORMAT, ???, lang); 299 //info_message.appendChild(format_request); 300 301 // the enrich_services request - only do this if provide_annotations is true 302 303 if (provide_annotations) { 304 Element enrich_services_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_DESCRIBE, "", lang); 305 enrich_services_request.setAttribute(GSXML.INFO_ATT, "serviceList"); 306 info_message.appendChild(enrich_services_request); 307 } 308 309 Element info_response = (Element)mr_.process(info_message); 310 311 // the collection is the first response 312 NodeList responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM); 313 Element coll_resp = (Element)responses.item(0); 314 page_response.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_resp, GSXML.COLLECTION_ELEM), true)); 315 316 //Element format_resp = (Element) responses.item(1); 317 //page_reponse.appendChild(doc_.importNode(GSXML.getChildByTagName(format_resp, GSXML.FORMAT_ELEM), true)); 318 319 320 if (provide_annotations) { 321 Element services_resp = (Element)responses.item(1); // change when format request added in 322 323 // a new message for the mr 324 Element enrich_message = doc_.createElement(GSXML.MESSAGE_ELEM); 325 326 NodeList e_services = services_resp.getElementsByTagName(GSXML.SERVICE_ELEM); 327 boolean service_found = false; 328 for (int j=0; j<e_services.getLength(); j++) { 329 if (((Element)e_services.item(j)).getAttribute(GSXML.TYPE_ATT).equals("enrich")) { 330 Element s = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_DESCRIBE, ((Element)e_services.item(j)).getAttribute(GSXML.NAME_ATT), lang); 331 enrich_message.appendChild(s); 332 service_found = true; 333 } 334 } 335 if (service_found) { 336 Element enrich_response = mr_.process(enrich_message); 337 338 e_services = enrich_response.getElementsByTagName(GSXML.SERVICE_ELEM); 339 Element service_list = doc_.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 340 for (int i=0; i<e_services.getLength(); i++) { 341 Element pl = (Element)GSXML.getChildByTagName(e_services.item(i), GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER); 342 if (pl != null) { 343 // add short names to the params in the param list 344 cgi_.paramListAddShortNames(pl); 345 } 346 service_list.appendChild(doc_.importNode(e_services.item(i), true)); 347 } 348 page_response.appendChild(service_list); 349 } 350 } // if provide_annotations 351 return true; 352 353 } 247 354 }
Note:
See TracChangeset
for help on using the changeset viewer.