- Timestamp:
- 2013-10-10T17:21:30+13:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java
r28258 r28382 82 82 83 83 Element message = this.converter.nodeToElement(message_node); 84 84 Document doc = message.getOwnerDocument(); 85 85 86 // the response 86 Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);87 Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);87 Element result = doc.createElement(GSXML.MESSAGE_ELEM); 88 Element page_response = doc.createElement(GSXML.RESPONSE_ELEM); 88 89 result.appendChild(page_response); 89 90 … … 174 175 // the_document is where all the doc info - structure and metadata etc 175 176 // is added into, to be returned in the page 176 Element the_document = this.doc.createElement(GSXML.DOCUMENT_ELEM);177 Element the_document = doc.createElement(GSXML.DOCUMENT_ELEM); 177 178 page_response.appendChild(the_document); 178 179 179 180 // create a basic doc list containing the current node 180 Element basic_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);181 Element current_doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);181 Element basic_doc_list = doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER); 182 Element current_doc = doc.createElement(GSXML.DOC_NODE_ELEM); 182 183 basic_doc_list.appendChild(current_doc); 183 184 if (document_id != null) … … 207 208 208 209 // Create a parameter list to specify the required structure information 209 Element ds_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);210 Element ds_param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 210 211 211 212 if (service_params != null) 212 213 { 213 GSXML.addParametersToList( this.doc, ds_param_list, service_params);214 GSXML.addParametersToList(doc, ds_param_list, service_params); 214 215 } 215 216 … … 223 224 if (expand_contents) 224 225 { 225 ds_param = this.doc.createElement(GSXML.PARAM_ELEM);226 ds_param = doc.createElement(GSXML.PARAM_ELEM); 226 227 ds_param_list.appendChild(ds_param); 227 228 ds_param.setAttribute(GSXML.NAME_ATT, "structure"); … … 230 231 231 232 // get the info needed for paged naviagtion 232 ds_param = this.doc.createElement(GSXML.PARAM_ELEM);233 ds_param = doc.createElement(GSXML.PARAM_ELEM); 233 234 ds_param_list.appendChild(ds_param); 234 235 ds_param.setAttribute(GSXML.NAME_ATT, "info"); 235 236 ds_param.setAttribute(GSXML.VALUE_ATT, "numSiblings"); 236 ds_param = this.doc.createElement(GSXML.PARAM_ELEM);237 ds_param = doc.createElement(GSXML.PARAM_ELEM); 237 238 ds_param_list.appendChild(ds_param); 238 239 ds_param.setAttribute(GSXML.NAME_ATT, "info"); 239 240 ds_param.setAttribute(GSXML.VALUE_ATT, "numChildren"); 240 ds_param = this.doc.createElement(GSXML.PARAM_ELEM);241 ds_param = doc.createElement(GSXML.PARAM_ELEM); 241 242 ds_param_list.appendChild(ds_param); 242 243 ds_param.setAttribute(GSXML.NAME_ATT, "info"); … … 245 246 if (get_siblings) 246 247 { 247 ds_param = this.doc.createElement(GSXML.PARAM_ELEM);248 ds_param = doc.createElement(GSXML.PARAM_ELEM); 248 249 ds_param_list.appendChild(ds_param); 249 250 ds_param.setAttribute(GSXML.NAME_ATT, "structure"); … … 257 258 if (expand_contents) 258 259 { 259 ds_param = this.doc.createElement(GSXML.PARAM_ELEM);260 ds_param = doc.createElement(GSXML.PARAM_ELEM); 260 261 ds_param_list.appendChild(ds_param); 261 262 ds_param.setAttribute(GSXML.NAME_ATT, "structure"); … … 265 266 { 266 267 // get the info needed for table of contents 267 ds_param = this.doc.createElement(GSXML.PARAM_ELEM);268 ds_param = doc.createElement(GSXML.PARAM_ELEM); 268 269 ds_param_list.appendChild(ds_param); 269 270 ds_param.setAttribute(GSXML.NAME_ATT, "structure"); 270 271 ds_param.setAttribute(GSXML.VALUE_ATT, "ancestors"); 271 ds_param = this.doc.createElement(GSXML.PARAM_ELEM);272 ds_param = doc.createElement(GSXML.PARAM_ELEM); 272 273 ds_param_list.appendChild(ds_param); 273 274 ds_param.setAttribute(GSXML.NAME_ATT, "structure"); … … 275 276 if (get_siblings) 276 277 { 277 ds_param = this.doc.createElement(GSXML.PARAM_ELEM);278 ds_param = doc.createElement(GSXML.PARAM_ELEM); 278 279 ds_param_list.appendChild(ds_param); 279 280 ds_param.setAttribute(GSXML.NAME_ATT, "structure"); … … 292 293 293 294 // Build a request to obtain the document structure 294 Element ds_message = this.doc.createElement(GSXML.MESSAGE_ELEM);295 Element ds_message = doc.createElement(GSXML.MESSAGE_ELEM); 295 296 String to = GSPath.appendLink(collection, "DocumentStructureRetrieve");// Hard-wired? 296 Element ds_request = GSXML.createBasicRequest( this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);297 Element ds_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext); 297 298 ds_message.appendChild(ds_request); 298 299 ds_request.appendChild(ds_param_list); … … 316 317 if (ds_response_struct_info != null) 317 318 { 318 the_document.appendChild( this.doc.importNode(ds_response_struct_info, true));319 the_document.appendChild(doc.importNode(ds_response_struct_info, true)); 319 320 } 320 321 path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER); … … 329 330 for (int i = 0; i < structs.getLength(); i++) 330 331 { 331 the_document.appendChild( this.doc.importNode(structs.item(i), true));332 the_document.appendChild(doc.importNode(structs.item(i), true)); 332 333 } 333 334 } … … 335 336 { 336 337 // no structure nodes, so put in a dummy doc node 337 Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);338 Element doc_node = doc.createElement(GSXML.DOC_NODE_ELEM); 338 339 if (document_id != null) 339 340 { … … 353 354 // should think about this more 354 355 // no structure request, so just put in a dummy doc node 355 Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);356 Element doc_node = doc.createElement(GSXML.DOC_NODE_ELEM); 356 357 if (document_id != null) 357 358 { … … 367 368 368 369 // Build a request to obtain some document metadata 369 Element dm_message = this.doc.createElement(GSXML.MESSAGE_ELEM);370 Element dm_message = doc.createElement(GSXML.MESSAGE_ELEM); 370 371 String to = GSPath.appendLink(collection, "DocumentMetadataRetrieve"); // Hard-wired? 371 Element dm_request = GSXML.createBasicRequest( this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);372 Element dm_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext); 372 373 dm_message.appendChild(dm_request); 373 374 // Create a parameter list to specify the required metadata information … … 390 391 } 391 392 392 Element dm_param_list = createMetadataParamList( meta_names);393 Element dm_param_list = createMetadataParamList(doc,meta_names); 393 394 if (service_params != null) 394 395 { 395 GSXML.addParametersToList( this.doc, dm_param_list, service_params);396 GSXML.addParametersToList(doc, dm_param_list, service_params); 396 397 } 397 398 … … 399 400 400 401 // create the doc node list for the metadata request 401 Element dm_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);402 Element dm_doc_list = doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER); 402 403 dm_request.appendChild(dm_doc_list); 403 404 … … 410 411 411 412 // Add the documentNode to the list 412 Element dm_doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);413 Element dm_doc_node = doc.createElement(GSXML.DOC_NODE_ELEM); 413 414 dm_doc_list.appendChild(dm_doc_node); 414 415 dm_doc_node.setAttribute(GSXML.NODE_ID_ATT, doc_node_id); … … 418 419 // we also want a metadata request to the top level document to get 419 420 // assocfilepath - this could be cached too 420 Element doc_meta_request = GSXML.createBasicRequest( this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);421 Element doc_meta_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext); 421 422 dm_message.appendChild(doc_meta_request); 422 Element doc_meta_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);423 Element doc_meta_param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 423 424 if (service_params != null) 424 425 { 425 GSXML.addParametersToList( this.doc, doc_meta_param_list, service_params);426 GSXML.addParametersToList(doc, doc_meta_param_list, service_params); 426 427 } 427 428 428 429 doc_meta_request.appendChild(doc_meta_param_list); 429 Element doc_param = this.doc.createElement(GSXML.PARAM_ELEM);430 Element doc_param = doc.createElement(GSXML.PARAM_ELEM); 430 431 doc_meta_param_list.appendChild(doc_param); 431 432 doc_param.setAttribute(GSXML.NAME_ATT, "metadata"); … … 433 434 434 435 // create the doc node list for the metadata request 435 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);436 Element doc_list = doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER); 436 437 doc_meta_request.appendChild(doc_list); 437 438 438 Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);439 Element doc_node = doc.createElement(GSXML.DOC_NODE_ELEM); 439 440 // the node we want is the root document node 440 441 if (document_id != null) … … 472 473 473 474 // Build a request to obtain some document content 474 Element dc_message = this.doc.createElement(GSXML.MESSAGE_ELEM);475 Element dc_message = doc.createElement(GSXML.MESSAGE_ELEM); 475 476 to = GSPath.appendLink(collection, "DocumentContentRetrieve"); // Hard-wired? 476 Element dc_request = GSXML.createBasicRequest( this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);477 Element dc_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext); 477 478 dc_message.appendChild(dc_request); 478 479 479 480 // Create a parameter list to specify the request parameters - empty for now 480 Element dc_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);481 Element dc_param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 481 482 if (service_params != null) 482 483 { 483 GSXML.addParametersToList( this.doc, dc_param_list, service_params);484 GSXML.addParametersToList(doc, dc_param_list, service_params); 484 485 } 485 486 … … 518 519 content = highlightQueryTerms(request, (Element) content); 519 520 } 520 doc_nodes.item(i).appendChild( this.doc.importNode(content, true));521 doc_nodes.item(i).appendChild(doc.importNode(content, true)); 521 522 } 522 523 //GSXML.mergeMetadataLists(doc_nodes.item(i), dm_response_docs.item(i)); … … 561 562 String enrich_service = (String) params.get(GSParams.SERVICE); 562 563 // send a message to the service 563 Element enrich_message = this.doc.createElement(GSXML.MESSAGE_ELEM);564 Element enrich_request = GSXML.createBasicRequest( this.doc, GSXML.REQUEST_TYPE_PROCESS, enrich_service, userContext);564 Element enrich_message = doc.createElement(GSXML.MESSAGE_ELEM); 565 Element enrich_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, enrich_service, userContext); 565 566 enrich_message.appendChild(enrich_request); 566 567 // check for parameters … … 568 569 if (e_service_params != null) 569 570 { 570 Element enrich_pl = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);571 GSXML.addParametersToList( this.doc, enrich_pl, e_service_params);571 Element enrich_pl = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 572 GSXML.addParametersToList(doc, enrich_pl, e_service_params); 572 573 enrich_request.appendChild(enrich_pl); 573 574 } 574 Element e_doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);575 Element e_doc_list = doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER); 575 576 enrich_request.appendChild(e_doc_list); 576 e_doc_list.appendChild( this.doc.importNode(dc_response_doc, true));577 e_doc_list.appendChild(doc.importNode(dc_response_doc, true)); 577 578 578 579 Node enrich_response = this.mr.process(enrich_message); … … 595 596 596 597 dummy_node.setAttribute(GSXML.NODE_ID_ATT, modified_doc_id); 597 dummy_node.appendChild( this.doc.importNode(dc_response_doc_content, true));598 dummy_node.appendChild(doc.importNode(dc_response_doc_content, true)); 598 599 // hack for simple type 599 600 if (document_type.equals(GSXML.DOC_TYPE_SIMPLE)) … … 630 631 if (dn_id.equals(modified_doc_id)) 631 632 { 632 dn.appendChild( this.doc.importNode(dc_response_doc_content, true));633 dn.appendChild(doc.importNode(dc_response_doc_content, true)); 633 634 break; 634 635 } … … 663 664 protected boolean getBackgroundData(Element page_response, String collection, UserContext userContext) 664 665 { 665 666 Document doc = page_response.getOwnerDocument(); 667 666 668 // create a message to process - contains requests for the collection 667 669 // description, the format element, the enrich services on offer 668 670 // these could all be cached 669 Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);671 Element info_message = doc.createElement(GSXML.MESSAGE_ELEM); 670 672 String path = GSPath.appendLink(collection, "DocumentContentRetrieve"); 671 673 // the format request - ignore for now, where does this request go to?? 672 Element format_request = GSXML.createBasicRequest( this.doc, GSXML.REQUEST_TYPE_FORMAT, path, userContext);674 Element format_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_FORMAT, path, userContext); 673 675 info_message.appendChild(format_request); 674 676 … … 677 679 if (provide_annotations) 678 680 { 679 Element enrich_services_request = GSXML.createBasicRequest( this.doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext);681 Element enrich_services_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, "", userContext); 680 682 enrich_services_request.setAttribute(GSXML.INFO_ATT, "serviceList"); 681 683 info_message.appendChild(enrich_services_request); … … 699 701 // set the format type 700 702 format_elem.setAttribute(GSXML.TYPE_ATT, "display"); 701 page_response.appendChild( this.doc.importNode(format_elem, true));703 page_response.appendChild(doc.importNode(format_elem, true)); 702 704 } 703 705 … … 707 709 708 710 // a new message for the mr 709 Element enrich_message = this.doc.createElement(GSXML.MESSAGE_ELEM);711 Element enrich_message = doc.createElement(GSXML.MESSAGE_ELEM); 710 712 NodeList e_services = services_resp.getElementsByTagName(GSXML.SERVICE_ELEM); 711 713 boolean service_found = false; … … 714 716 if (((Element) e_services.item(j)).getAttribute(GSXML.TYPE_ATT).equals("enrich")) 715 717 { 716 Element s = GSXML.createBasicRequest( this.doc, GSXML.REQUEST_TYPE_DESCRIBE, ((Element) e_services.item(j)).getAttribute(GSXML.NAME_ATT), userContext);718 Element s = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_DESCRIBE, ((Element) e_services.item(j)).getAttribute(GSXML.NAME_ATT), userContext); 717 719 enrich_message.appendChild(s); 718 720 service_found = true; … … 724 726 725 727 NodeList e_responses = enrich_response.getElementsByTagName(GSXML.RESPONSE_ELEM); 726 Element service_list = this.doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);728 Element service_list = doc.createElement(GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER); 727 729 for (int i = 0; i < e_responses.getLength(); i++) 728 730 { 729 731 Element e_resp = (Element) e_responses.item(i); 730 Element e_service = (Element) this.doc.importNode(GSXML.getChildByTagName(e_resp, GSXML.SERVICE_ELEM), true);732 Element e_service = (Element) doc.importNode(GSXML.getChildByTagName(e_resp, GSXML.SERVICE_ELEM), true); 731 733 e_service.setAttribute(GSXML.NAME_ATT, e_resp.getAttribute(GSXML.FROM_ATT)); 732 734 service_list.appendChild(e_service); … … 741 743 protected String getDocumentType(Element basic_doc_list, String collection, UserContext userContext, Element page_response) 742 744 { 743 Element ds_message = this.doc.createElement(GSXML.MESSAGE_ELEM); 745 Document doc = basic_doc_list.getOwnerDocument(); 746 747 Element ds_message = doc.createElement(GSXML.MESSAGE_ELEM); 744 748 String to = GSPath.appendLink(collection, "DocumentStructureRetrieve");// Hard-wired? 745 Element ds_request = GSXML.createBasicRequest( this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);749 Element ds_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext); 746 750 ds_message.appendChild(ds_request); 747 751 748 752 // Create a parameter list to specify the required structure information 749 Element ds_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);750 Element ds_param = this.doc.createElement(GSXML.PARAM_ELEM);753 Element ds_param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 754 Element ds_param = doc.createElement(GSXML.PARAM_ELEM); 751 755 ds_param_list.appendChild(ds_param); 752 756 ds_param.setAttribute(GSXML.NAME_ATT, "info"); … … 787 791 protected Element highlightQueryTerms(Element request, Element dc_response_doc_content) 788 792 { 793 Document doc = request.getOwnerDocument(); 794 789 795 // do the query again to get term info 790 796 Element cgi_param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); … … 806 812 String to = GSPath.appendLink(collection, service_name); 807 813 808 Element mr_query_message = this.doc.createElement(GSXML.MESSAGE_ELEM);809 Element mr_query_request = GSXML.createBasicRequest( this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);814 Element mr_query_message = doc.createElement(GSXML.MESSAGE_ELEM); 815 Element mr_query_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext); 810 816 mr_query_message.appendChild(mr_query_request); 811 817 … … 813 819 HashMap service_params = (HashMap) params.get("s1"); 814 820 815 Element query_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);816 GSXML.addParametersToList( this.doc, query_param_list, service_params);821 Element query_param_list = doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 822 GSXML.addParametersToList(doc, query_param_list, service_params); 817 823 mr_query_request.appendChild(query_param_list); 818 824 … … 969 975 } 970 976 971 return highlightQueryTermsInternal( content, query_term_variants, phrase_query_term_variants_hierarchy);977 return highlightQueryTermsInternal(doc, content, query_term_variants, phrase_query_term_variants_hierarchy); 972 978 } 973 979 … … 975 981 * Highlights query terms in a piece of text. 976 982 */ 977 private Element highlightQueryTermsInternal( String content, HashSet<String> query_term_variants, ArrayList<ArrayList<HashSet<String>>> phrase_query_term_variants_hierarchy)983 private Element highlightQueryTermsInternal(Document doc, String content, HashSet<String> query_term_variants, ArrayList<ArrayList<HashSet<String>>> phrase_query_term_variants_hierarchy) 978 984 { 979 985 // Convert the content string to an array of characters for speed … … 1122 1128 1123 1129 // Now add the annotation tags into the document at the correct points 1124 Element content_element = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);1130 Element content_element = doc.createElement(GSXML.NODE_CONTENT_ELEM); 1125 1131 1126 1132 int last_wrote = 0; … … 1134 1140 { 1135 1141 String preceding_text = new String(content_characters, last_wrote, (highlight_start - last_wrote)); 1136 content_element.appendChild( this.doc.createTextNode(preceding_text));1142 content_element.appendChild(doc.createTextNode(preceding_text)); 1137 1143 } 1138 1144 … … 1141 1147 { 1142 1148 String highlight_text = new String(content_characters, highlight_start, (highlight_end - highlight_start)); 1143 Element annotation_element = GSXML.createTextElement( this.doc, "annotation", highlight_text);1149 Element annotation_element = GSXML.createTextElement(doc, "annotation", highlight_text); 1144 1150 annotation_element.setAttribute("type", "query_term"); 1145 1151 content_element.appendChild(annotation_element); … … 1152 1158 { 1153 1159 String remaining_text = new String(content_characters, last_wrote, (content_characters.length - last_wrote)); 1154 content_element.appendChild( this.doc.createTextNode(remaining_text));1160 content_element.appendChild(doc.createTextNode(remaining_text)); 1155 1161 } 1156 1162
Note:
See TracChangeset
for help on using the changeset viewer.