Changeset 25305 for main/trunk/greenstone3/src/java/org/greenstone
- Timestamp:
- 2012-03-27T15:18:44+13:00 (12 years ago)
- Location:
- main/trunk/greenstone3/src/java/org/greenstone/gsdl3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java
r25128 r25305 48 48 public static final String GOTO_PAGE_ARG = "gp"; 49 49 public static final String ENRICH_DOC_ARG = "end"; 50 public static final String EXPAND_DOCUMENT_ARG = "ed"; 51 public static final String EXPAND_CONTENTS_ARG = "ec"; 52 public static final String REALISTIC_BOOK_ARG = "book"; 50 53 51 54 /** … … 92 95 HashMap service_params = (HashMap) params.get("s0"); 93 96 94 String has_rl = null;95 String has_href = null;96 has_href = (String) params.get("href");//for an external link : get the href URL if it is existing in the params list97 has_rl = (String) params.get("rl");//for an external link : get the rl value if it is existing in the params list98 97 String collection = (String) params.get(GSParams.COLLECTION); 99 UserContext userContext = new UserContext(request); 100 String document_name = (String) params.get(GSParams.DOCUMENT); 101 if ((document_name == null || document_name.equals("")) && (has_href == null || has_href.equals(""))) 98 String document_id = (String) params.get(GSParams.DOCUMENT); 99 if (document_id != null && document_id.equals("")) { 100 document_id = null; 101 } 102 String href = (String) params.get(GSParams.HREF);//for an external link : get the href URL if it is existing in the params list 103 if (href != null && href.equals("")) { 104 href = null; 105 } 106 String rl = (String) params.get(GSParams.RELATIVE_LINK);//for an external link : get the rl value if it is existing in the params list 107 if (document_id == null && href == null) 102 108 { 103 109 logger.error("no document specified!"); 104 110 return result; 105 111 } 112 if (rl != null && rl.equals("0")) { 113 // this is a true external link, we should have been directed to a different page or action 114 logger.error("rl value was 0, shouldn't get here"); 115 return result; 116 } 106 117 String document_type = (String) params.get(GSParams.DOCUMENT_TYPE); 107 if (document_type == null )118 if (document_type == null || document_type.equals("")) 108 119 { 109 120 document_type = "simple"; … … 117 128 } 118 129 130 String doc_id_modifier = ""; 119 131 String sibling_num = (String) params.get(GOTO_PAGE_ARG); 120 132 if (sibling_num != null && !sibling_num.equals("")) 121 133 { 122 134 // we have to modify the doc name 123 doc ument_name = document_name +"." + sibling_num + ".ss";135 doc_id_modifier = "." + sibling_num + ".ss"; 124 136 } 125 137 126 138 boolean expand_document = false; 127 String ed_arg = (String) params.get( GSParams.EXPAND_DOCUMENT);139 String ed_arg = (String) params.get(EXPAND_DOCUMENT_ARG); 128 140 if (ed_arg != null && ed_arg.equals("1")) 129 141 { … … 138 150 else 139 151 { 140 String ec_arg = (String) params.get( GSParams.EXPAND_CONTENTS);152 String ec_arg = (String) params.get(EXPAND_CONTENTS_ARG); 141 153 if (ec_arg != null && ec_arg.equals("1")) 142 154 { … … 144 156 } 145 157 } 158 159 UserContext userContext = new UserContext(request); 146 160 147 161 //append site metadata … … 165 179 Element current_doc = this.doc.createElement(GSXML.DOC_NODE_ELEM); 166 180 basic_doc_list.appendChild(current_doc); 167 if (document_name.length() != 0) 168 { 169 current_doc.setAttribute(GSXML.NODE_ID_ATT, document_name); 170 } 171 else if (has_href.length() != 0) 172 { 173 current_doc.setAttribute(GSXML.NODE_ID_ATT, has_href); 174 current_doc.setAttribute("externalURL", has_rl); 181 if (document_id != null) 182 { 183 current_doc.setAttribute(GSXML.NODE_ID_ATT, document_id+doc_id_modifier); 184 } 185 else 186 { 187 current_doc.setAttribute(GSXML.HREF_ID_ATT, href); 188 // do we need this?? 189 current_doc.setAttribute(GSXML.ID_MOD_ATT, doc_id_modifier); 175 190 } 176 191 … … 198 213 } 199 214 200 // get t ehinfo needed for paged naviagtion215 // get the info needed for paged naviagtion 201 216 ds_param = this.doc.createElement(GSXML.PARAM_ELEM); 202 217 ds_param_list.appendChild(ds_param); … … 305 320 // no structure nodes, so put in a dummy doc node 306 321 Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM); 307 if (document_ name.length() != 0)308 { 309 doc_node.setAttribute(GSXML.NODE_ID_ATT, document_ name);310 } 311 else if (has_href.length() != 0)312 { 313 doc_node.setAttribute(GSXML. NODE_ID_ATT, has_href);314 doc_node.setAttribute("externalURL", has_rl);322 if (document_id != null) 323 { 324 doc_node.setAttribute(GSXML.NODE_ID_ATT, document_id); 325 } 326 else 327 { 328 doc_node.setAttribute(GSXML.HREF_ID_ATT, href); 329 315 330 } 316 331 the_document.appendChild(doc_node); … … 323 338 // no structure request, so just put in a dummy doc node 324 339 Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM); 325 if (document_name.length() != 0) 326 { 327 doc_node.setAttribute(GSXML.NODE_ID_ATT, document_name); 328 } 329 else if (has_href.length() != 0) 330 { 331 doc_node.setAttribute(GSXML.NODE_ID_ATT, has_href); 332 doc_node.setAttribute("externalURL", has_rl); 340 if (document_id != null) 341 { 342 doc_node.setAttribute(GSXML.NODE_ID_ATT, document_id); 343 } 344 else 345 { 346 doc_node.setAttribute(GSXML.HREF_ID_ATT, href); 333 347 } 334 348 the_document.appendChild(doc_node); … … 398 412 Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM); 399 413 // the node we want is the root document node 400 if (document_name.length() != 0) 401 { 402 doc_node.setAttribute(GSXML.NODE_ID_ATT, document_name + ".rt"); 403 } 404 else if (has_href.length() != 0) 405 { 406 doc_node.setAttribute(GSXML.NODE_ID_ATT, has_href + ".rt"); 407 doc_node.setAttribute("externalURL", has_rl); 414 if (document_id != null) 415 { 416 doc_node.setAttribute(GSXML.NODE_ID_ATT, document_id + ".rt"); 417 } 418 else 419 { 420 doc_node.setAttribute(GSXML.HREF_ID_ATT, href);// + ".rt"); 421 // can we assume that href is always a top level doc?? 422 //doc_node.setAttribute(GSXML.ID_MOD_ATT, ".rt"); 423 //doc_node.setAttribute("externalURL", has_rl); 408 424 } 409 425 doc_list.appendChild(doc_node); … … 486 502 Element dc_response_doc = (Element) GSXML.getChildByTagName(dc_response_doc_list, GSXML.DOC_NODE_ELEM); 487 503 Element dc_response_doc_content = (Element) GSXML.getChildByTagName(dc_response_doc, GSXML.NODE_CONTENT_ELEM); 488 Element dc_response_doc_external = (Element) GSXML.getChildByTagName(dc_response_doc, "external");504 //Element dc_response_doc_external = (Element) GSXML.getChildByTagName(dc_response_doc, "external"); 489 505 490 506 if (dc_response_doc_content == null) 491 507 { 492 508 // no content to add 493 if (dc_response_doc_external != null) 494 { 495 String modified_doc_id = dc_response_doc.getAttribute(GSXML.NODE_ID_ATT); 496 497 the_document.setAttribute("selectedNode", modified_doc_id); 498 the_document.setAttribute("external", dc_response_doc_external.getAttribute("external_link")); 499 } 500 return result; 509 if (dc_response_doc.getAttribute("external").equals("true")) { 510 511 //if (dc_response_doc_external != null) 512 //{ 513 String href_id = dc_response_doc.getAttribute(GSXML.HREF_ID_ATT); 514 515 the_document.setAttribute("selectedNode", href_id); 516 the_document.setAttribute("external", href_id); 517 } 518 return result; 501 519 } 502 520 if (highlight_query_terms) … … 598 616 * important for args that should not be saved 599 617 */ 600 public boolean getActionParameters(GSParams params)618 public boolean addActionParameters(GSParams params) 601 619 { 602 620 params.addParameter(GOTO_PAGE_ARG, false); 603 621 params.addParameter(ENRICH_DOC_ARG, false); 622 params.addParameter(EXPAND_DOCUMENT_ARG, false); 623 params.addParameter(EXPAND_CONTENTS_ARG, false); 624 params.addParameter(REALISTIC_BOOK_ARG, false); 625 604 626 return true; 605 627 } -
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java
r25259 r25305 46 46 /** 47 47 * Abstract class for Document Retrieval Services 48 *49 * @author <a href="mailto:[email protected]">Katherine Don</a>50 48 */ 51 49 … … 74 72 75 73 // means the id is not a greenstone id and needs translating 76 protected static final String EXTID_PARAM = "ext";74 // protected static final String EXTID_PARAM = "ext"; 77 75 78 76 protected Element config_info = null; // the xml from the config file … … 150 148 macro_resolver.setSiteDetails(this.site_http_address, this.cluster_name, this.getLibraryName()); 151 149 // set up the macro resolver 152 Element replacement_elem = (Element) GSXML.getChildByTagName(extra_info, "replaceList");150 Element replacement_elem = (Element) GSXML.getChildByTagName(extra_info, GSXML.REPLACE_ELEM+GSXML.LIST_MODIFIER); 153 151 if (replacement_elem != null) 154 152 { … … 156 154 } 157 155 // look for any refs to global replace lists 158 NodeList replace_refs_elems = extra_info.getElementsByTagName( "replaceListRef");156 NodeList replace_refs_elems = extra_info.getElementsByTagName(GSXML.REPLACE_ELEM+GSXML.LIST_MODIFIER+GSXML.REF_MODIFIER); 159 157 for (int i = 0; i < replace_refs_elems.getLength(); i++) 160 158 { … … 162 160 if (!id.equals("")) 163 161 { 164 Element replace_list = GSXML.getNamedElement(this.router.config_info, "replaceList", "id", id);162 Element replace_list = GSXML.getNamedElement(this.router.config_info, GSXML.REPLACE_ELEM+GSXML.LIST_MODIFIER, "id", id); 165 163 if (replace_list != null) 166 164 { … … 206 204 } 207 205 208 boolean external_id = false;209 206 // The metadata information required 210 207 ArrayList metadata_names_list = new ArrayList(); … … 225 222 metadata_names_list.add(metadata); 226 223 } 227 else if (param.getAttribute(GSXML.NAME_ATT).equals(EXTID_PARAM) && GSXML.getValue(param).equals("1")) 228 { 229 external_id = true; 230 } 224 231 225 param = (Element) param.getNextSibling(); 232 226 } … … 265 259 Element request_node = (Element) request_nodes.item(i); 266 260 String node_id = request_node.getAttribute(GSXML.NODE_ID_ATT); 267 268 boolean is_external_link = false; 269 if (!node_id.startsWith("HASH") && !node_id.startsWith("D")) 270 { 271 if (node_id.endsWith(".rt")) 272 { 273 node_id = getHrefOID(node_id.substring(0, node_id.length() - 3)); 274 if (node_id != null) 275 { 276 node_id += ".rt"; 277 } 278 else 279 { 280 is_external_link = true; 281 } 282 } 283 else 284 { 285 node_id = getHrefOID(node_id); 286 if (node_id == null) 287 { 288 is_external_link = true; 289 } 290 } 291 } 292 if (!is_external_link) 293 { 294 if (external_id) 295 { 296 // can we have .pr etc extensions with external ids? 297 node_id = translateExternalId(node_id); 298 } 299 else if (idNeedsTranslating(node_id)) 300 { 301 node_id = translateId(node_id); 302 } 303 } 304 261 boolean is_href_id = false; 262 if (node_id.equals("")) { 263 node_id = getGreenstoneIdFromHref(request_node); 264 if(node_id == null) { 265 // **** TODO, is this good enough??? 266 request_node.setAttribute("external_link", "true"); 267 continue; 268 } 269 270 } 271 272 System.err.println("getting meta for node"+node_id); 273 274 // may have modifiers .rt, .1.ss etc 275 if (idNeedsTranslating(node_id)) 276 { 277 node_id = translateId(node_id); 278 } 279 305 280 if (node_id == null) 306 281 { 307 282 continue; 308 283 } 309 if (!is_external_link) 310 { 311 try 312 { 313 Element metadata_list = getMetadataList(node_id, all_metadata, metadata_names_list); 314 if(metadata_list != null) 315 { 316 request_node.appendChild(metadata_list); 317 } 318 } 319 catch (GSException e) 320 { 321 GSXML.addError(this.doc, result, e.getMessage(), e.getType()); 322 if (e.getType().equals(GSXML.ERROR_TYPE_SYSTEM)) 323 { 324 // there is no point trying any others 325 return result; 326 } 327 } 328 } 329 else 330 { 331 request_node.setAttribute("external_link", request_node.getAttribute(GSXML.NODE_ID_ATT)); 332 } 333 } 284 try 285 { 286 Element metadata_list = getMetadataList(node_id, all_metadata, metadata_names_list); 287 if(metadata_list != null) 288 { 289 request_node.appendChild(metadata_list); 290 } 291 } 292 catch (GSException e) 293 { 294 GSXML.addError(this.doc, result, e.getMessage(), e.getType()); 295 if (e.getType().equals(GSXML.ERROR_TYPE_SYSTEM)) 296 { 297 // there is no point trying any others 298 return result; 299 } 300 } 301 302 303 } // for each doc node 304 334 305 return result; 335 306 } … … 377 348 GSXML.addError(this.doc, result, "DocumentStructureRetrieve: no " + GSXML.DOC_NODE_ELEM + " found in the " + GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.ERROR_TYPE_SYNTAX); 378 349 return result; 379 }380 381 Element extid_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, EXTID_PARAM);382 boolean external_id = false;383 if (extid_param != null && GSXML.getValue(extid_param).equals("1"))384 {385 external_id = true;386 350 } 387 351 … … 446 410 447 411 String doc_id = doc.getAttribute(GSXML.NODE_ID_ATT); 448 String is_external = doc.getAttribute("externalURL"); 449 450 boolean is_external_link = false; 451 if (is_external.equals("0")) 452 { 453 is_external_link = true; 454 } 455 if (is_external.equals("1") && !doc_id.startsWith("HASH") && !is_external_link) 456 { 457 if (doc_id.endsWith(".rt")) 458 { 459 doc_id = getHrefOID(doc_id.substring(0, doc_id.length() - 3)); 460 if (doc_id != null) 461 { 462 doc_id += ".rt"; 463 } 464 else 465 { 466 is_external_link = true; 467 } 468 } 469 else 470 { 471 doc_id = getHrefOID(doc_id); 472 if (doc_id == null) 473 { 474 is_external_link = true; 475 } 476 } 477 } 478 if (!is_external_link) 479 { 480 if (external_id) 481 { 482 doc_id = translateExternalId(doc_id); 483 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); 484 } 485 else if (idNeedsTranslating(doc_id)) 486 { 487 doc_id = translateId(doc_id); 488 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); 489 } 490 491 if (doc_id == null) 492 { 493 continue; 494 } 412 boolean is_href_id = false; 413 if (doc_id.equals("")) { 414 doc_id = getGreenstoneIdFromHref(doc); 415 if(doc_id == null) { 416 // **** TODO, is this good enough??? 417 doc.setAttribute("external_link", "true"); 418 continue; 419 } 420 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); 421 } 422 423 if (idNeedsTranslating(doc_id)) 424 { 425 doc_id = translateId(doc_id); 426 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); 427 } 428 429 if (doc_id == null) 430 { 431 continue; 432 } 495 433 496 434 if (want_info) … … 591 529 } // if want structure 592 530 593 } 594 else 595 { 596 Element external_link_elem = this.doc.createElement("external"); 597 external_link_elem.setAttribute("external_link", doc.getAttribute(GSXML.NODE_ID_ATT)); 598 doc.appendChild(external_link_elem); 599 }// if is_external_link 531 600 532 } // for each doc 601 533 return result; … … 618 550 // Get the parameters of the request 619 551 Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 620 Element extid_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, EXTID_PARAM);621 boolean external_id = false;622 if (extid_param != null && GSXML.getValue(extid_param).equals("1"))623 {624 external_id = true;625 }626 552 // Get the request content 627 553 Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER); … … 633 559 634 560 String lang = request.getAttribute(GSXML.LANG_ATT); 635 Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER); 636 result.appendChild(doc_list); 561 562 // copy the request doc node list to the response 563 Element response_node_list = (Element) this.doc.importNode(query_doc_list, true); 564 result.appendChild(response_node_list); 565 566 NodeList request_nodes = GSXML.getChildrenByTagName(response_node_list, GSXML.DOC_NODE_ELEM); 567 if (request_nodes.getLength() == 0) 568 { 569 GSXML.addError(this.doc, result, "DocumentContentRetrieve: no " + GSXML.DOC_NODE_ELEM + " found in the " + GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.ERROR_TYPE_SYNTAX); 570 return result; 571 } 572 573 //Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER); 574 //result.appendChild(doc_list); 637 575 638 576 // set up the retrieval?? 639 577 640 578 // Get the documents 641 String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list, GSXML.NODE_ID_ATT); 642 String[] is_externals = GSXML.getAttributeValuesFromList(query_doc_list, "externalURL"); 643 644 for (int i = 0; i < doc_ids.length; i++) 645 { 646 String doc_id = doc_ids[i]; 647 String is_external = is_externals[i]; 648 649 boolean is_external_link = false; 650 if (is_external.equals("0")) 651 { 652 is_external_link = true; 653 } 654 if (is_external.equals("1") && !doc_id.startsWith("HASH") && !is_external_link) 655 { 656 //if (!doc_id.startsWith("HASH")){ 657 if (doc_id.endsWith(".rt")) 658 { 659 String find_doc_id = getHrefOID(doc_id.substring(0, doc_id.length() - 3)); 660 if (find_doc_id != null) 661 { 662 doc_id = doc_id + ".rt"; 663 } 664 else 665 { 666 is_external_link = true; 667 } 668 669 } 670 else 671 { 672 String find_doc_id = getHrefOID(doc_id); 673 if (find_doc_id == null) 674 { 675 is_external_link = true; 676 } 677 else 678 { 679 doc_id = find_doc_id; 680 } 681 } 682 } 683 684 if (!is_external_link) 685 { 686 // Create the document node 687 Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM); 688 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); 689 doc_list.appendChild(doc); 690 691 if (external_id) 692 { 693 doc_id = translateExternalId(doc_id); 694 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); 695 } 696 else if (idNeedsTranslating(doc_id)) 697 { 698 doc_id = translateId(doc_id); 699 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); 700 } 701 if (doc_id == null) 702 { 703 continue; 704 } 705 try 706 { 707 Element node_content = getNodeContent(doc_id, lang); 708 doc.appendChild(node_content); 709 } 710 catch (GSException e) 711 { 712 GSXML.addError(this.doc, result, e.getMessage()); 713 return result; 714 715 } 716 } 717 else 718 { 719 Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM); 720 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); 721 //doc.setAttribute("external_link", doc_id); 722 Element external_link_elem = this.doc.createElement("external"); 723 external_link_elem.setAttribute("external_link", doc_id); 724 doc.appendChild(external_link_elem); 725 726 doc_list.appendChild(doc); 727 } 728 } 579 //String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list, GSXML.NODE_ID_ATT); 580 //String[] is_externals = GSXML.getAttributeValuesFromList(query_doc_list, "externalURL"); 581 582 for (int i = 0; i < request_nodes.getLength(); i++) 583 { 584 Element request_node = (Element) request_nodes.item(i); 585 String node_id = request_node.getAttribute(GSXML.NODE_ID_ATT); 586 boolean is_href_id = false; 587 if (node_id.equals("")) { 588 node_id = getGreenstoneIdFromHref(request_node); 589 if(node_id == null) { 590 // **** TODO, is this good enough??? 591 request_node.setAttribute("external_link", "true"); 592 continue; 593 } 594 595 } 596 597 // may have modifiers .rt, .1.ss etc 598 if (idNeedsTranslating(node_id)) 599 { 600 node_id = translateId(node_id); 601 } 602 603 if (node_id == null) 604 { 605 continue; 606 } 607 try 608 { 609 Element node_content = getNodeContent(node_id, lang); 610 request_node.appendChild(node_content); 611 } 612 catch (GSException e) 613 { 614 GSXML.addError(this.doc, result, e.getMessage()); 615 return result; 616 617 } 618 } // for each node 729 619 return result; 730 } 620 } // processDocumentContentRetrieve 731 621 732 622 /** … … 869 759 } 870 760 761 protected String getGreenstoneIdFromHref(Element doc_node) 762 { 763 String node_id = doc_node.getAttribute(GSXML.HREF_ID_ATT); 764 node_id = translateExternalId(node_id); 765 if (node_id == null) { 766 return node_id; 767 } 768 // check for id modifiers 769 String id_mods = doc_node.getAttribute(GSXML.ID_MOD_ATT); 770 if (!id_mods.equals("")) { 771 node_id = node_id+id_mods; 772 } 773 return node_id; 774 } 871 775 /** 872 776 * returns the document type of the doc that the specified node belongs to.
Note:
See TracChangeset
for help on using the changeset viewer.