Changeset 39010 for main/trunk/greenstone3/src/java/org/greenstone/gsdl3
- Timestamp:
- 2024-05-09T14:28:40+12:00 (6 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/URLFilter.java
r38371 r39010 66 66 protected static final String BROWSE_PATH = "browse"; 67 67 protected static final String SEARCH_PATH = "search"; 68 protected static final String ASSOC_PATH = "assoc"; 68 69 protected static final ArrayList<String> _keywords; 69 70 … … 147 148 // so they are not a true link to a file. We remove the 148 149 // 'library' then forward the request to the new url. 149 securityCheckAssocFiles(url, hRequest, response );150 securityCheckAssocFiles(url, hRequest, response, null); 150 151 return; 151 152 } … … 200 201 url = url.substring(0, index); 201 202 } 203 204 // OK, here we split into segments and process bit by bit. 202 205 String[] segments = url.split("/"); 203 206 for (int i = 0; i < segments.length; i++) … … 248 251 gRequest.setParameter("ed", "1"); 249 252 250 } 253 } else if ((i+3) < segments.length && segments[i+2].equals("assoc")) { 254 url = generateFileURL(context, url, gRequest.getParameter(GSParams.COLLECTION), gRequest.getParameter(GSParams.DOCUMENT), segments[i+3]); 255 256 securityCheckAssocFiles(url, hRequest, response, gRequest.getParameter(GSParams.DOCUMENT)); 257 return; 258 } 259 251 260 252 261 } … … 429 438 } 430 439 431 432 private void securityCheckAssocFiles(String url, HttpServletRequest request, ServletResponse response) throws IOException, ServletException { 440 private String generateFileURL(ServletContext context, String url, String collection, String document, String filename) { 441 442 String library_name = url.replaceFirst(context.getContextPath()+"/", ""); 443 library_name = library_name.substring(0, library_name.indexOf("/")); 444 445 MessageRouter gsRouter = (MessageRouter) context.getAttribute(library_name+"Router"); 446 String site_name = gsRouter.getSiteName(); 447 String context_path = context.getContextPath(); 448 String assocfilepath = queryMRforMetadata(gsRouter, collection, document, "assocfilepath"); 449 450 if (assocfilepath == null) { 451 return null; 452 } 453 return context_path +"/"+ library_name+"/"+ 454 "sites/"+ site_name+"/"+ 455 "collect/"+collection+"/"+ 456 "index/assoc/"+assocfilepath+"/"+filename; 457 458 } 459 460 private void securityCheckAssocFiles(String url, HttpServletRequest request, ServletResponse response, String document) throws IOException, ServletException { 461 433 462 HttpSession session = request.getSession(); 434 463 String session_id = session.getId(); … … 494 523 } 495 524 525 if (document == null) { 496 526 // Query the MR with a request for the contains metadata for node "dir" - where dir is the assocfilepath 497 527 // In the jdbm db, have entries like … … 499 529 // <contains>HASH1552e3sdlkjf7sdfsdfk 500 530 // mapping assocfilepath to doc id 501 String document = queryMRforDOCID(gsRouter, collection, dir); 502 if (document == null) { 503 response.getWriter().println("ERROR: Couldn't find the document associated with assocfilepath: "+dir); 504 return; 505 } 531 document = queryMRforDOCID(gsRouter, collection, dir); 532 if (document == null) { 533 response.getWriter().println("ERROR: Couldn't find the document associated with assocfilepath: "+dir); 534 return; 535 } 536 } 506 537 507 538 //Query the MR for the security info for this document … … 668 699 669 700 private String queryMRforDOCID(MessageRouter gsRouter, String collection, String assocfiledir) { 701 return queryMRforMetadata(gsRouter, collection, assocfiledir, "contains"); 702 } 703 704 // set node_id to be a document_id, and metadata_name to be 'assocfilepath' to 705 // get the assocfilepath for a particular doc 706 // set node_id to be the assocfilepath, and metadata_name to be 'contains' to 707 // get the doc_id for a particular assocfilepath 708 private String queryMRforMetadata(MessageRouter gsRouter, String collection, String node_id, String metadata_name) { 670 709 Document gsDoc = XMLConverter.newDOM(); 671 710 … … 679 718 Element param = gsDoc.createElement(GSXML.PARAM_ELEM); 680 719 param.setAttribute(GSXML.NAME_ATT, "metadata"); 681 param.setAttribute(GSXML.VALUE_ATT, "contains");720 param.setAttribute(GSXML.VALUE_ATT, metadata_name); 682 721 paramList.appendChild(param); 683 722 … … 686 725 687 726 Element doc = gsDoc.createElement(GSXML.DOC_NODE_ELEM); 688 doc.setAttribute(GSXML.NODE_ID_ATT, assocfiledir);727 doc.setAttribute(GSXML.NODE_ID_ATT, node_id); 689 728 docList.appendChild(doc); 690 729 … … 694 733 if (metadataList.getLength() == 0) { 695 734 696 logger.error("Could not find the document ID related to this url");735 logger.error("Could not find the metadata '"+metadata_name+"' for node '"+node_id+"'"); 697 736 return null; 698 737 } 699 738 700 739 Element metadata = (Element) metadataList.item(0); 701 String document= metadata.getTextContent();702 if ( document != null && document.equals("")) {703 document= null;704 } 705 return document;740 String meta_value = metadata.getTextContent(); 741 if (meta_value != null && meta_value.equals("")) { 742 meta_value = null; 743 } 744 return meta_value; 706 745 707 746
Note:
See TracChangeset
for help on using the changeset viewer.