Changeset 39010


Ignore:
Timestamp:
2024-05-09T14:28:40+12:00 (11 days ago)
Author:
kjdon
Message:

added metadata_name param to queryMRforDOCID and renamed it to queryMRforMetadata, so it can be used for both doc_id->assocfilepath and assocfilepath->doc_id lookup. added support for restful assoc file urls - these will be stable unlike filepaths with assocfilepath inthem, which can change between builds. gs doc url is greenstone3/library/collection/demo/document/HASHxxx - add on to this /assoc/yyy.pdf and you can view that document without needing assocfilepath.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/URLFilter.java

    r38371 r39010  
    6666  protected static final String BROWSE_PATH = "browse";
    6767  protected static final String SEARCH_PATH = "search";
     68  protected static final String ASSOC_PATH = "assoc";
    6869  protected static final ArrayList<String> _keywords;
    6970
     
    147148      // so they are not a true link to a file. We remove the
    148149      // 'library' then forward the request to the new url.
    149       securityCheckAssocFiles(url, hRequest, response);
     150      securityCheckAssocFiles(url, hRequest, response, null);
    150151      return;
    151152    }
     
    200201        url = url.substring(0, index);
    201202      }
     203
     204        // OK, here we split into segments and process bit by bit.
    202205    String[] segments = url.split("/");
    203206    for (int i = 0; i < segments.length; i++)
     
    248251          gRequest.setParameter("ed", "1");
    249252                         
    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               
    251260                   
    252261          }
     
    429438  }
    430439
    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
    433462    HttpSession session = request.getSession();
    434463    String session_id = session.getId();
     
    494523    }
    495524
     525        if (document == null) {
    496526    // Query the MR with a request for the contains metadata for node "dir" - where dir is the assocfilepath
    497527    // In the jdbm db, have entries like
     
    499529    // <contains>HASH1552e3sdlkjf7sdfsdfk
    500530    // 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        }
    506537   
    507538    //Query the MR for the security info for this document
     
    668699
    669700  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) {
    670709    Document gsDoc = XMLConverter.newDOM();
    671710
     
    679718    Element param = gsDoc.createElement(GSXML.PARAM_ELEM);   
    680719    param.setAttribute(GSXML.NAME_ATT, "metadata");
    681     param.setAttribute(GSXML.VALUE_ATT, "contains");
     720    param.setAttribute(GSXML.VALUE_ATT, metadata_name);
    682721    paramList.appendChild(param);
    683722
     
    686725
    687726    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);
    689728    docList.appendChild(doc);
    690729   
     
    694733    if (metadataList.getLength() == 0) {
    695734     
    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+"'");
    697736      return null;
    698737    }
    699738     
    700739    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;
    706745     
    707746 
Note: See TracChangeset for help on using the changeset viewer.