Changeset 36978 for main


Ignore:
Timestamp:
2022-12-07T12:14:03+13:00 (17 months ago)
Author:
kjdon
Message:

now this does a check to see if the doc id is valid before proceding to get teh structure, metadata etc. if the id is invalid, the page will contain an error element and not a document element. Also replaced hard coded service names with their variable names

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/DocumentAction.java

    r35363 r36978  
    2121// Greenstone classes
    2222import org.greenstone.gsdl3.core.ModuleInterface;
     23import org.greenstone.gsdl3.service.AbstractDocumentRetrieve;
     24import org.greenstone.gsdl3.service.DocXMLUtil;
    2325import org.greenstone.gsdl3.util.*;
    2426import org.greenstone.util.GlobalProperties;
     
    125127            return result;
    126128        }
     129               
     130        String doc_id_modifier = "";
     131        String sibling_num = (String) params.get(GOTO_PAGE_ARG);
     132        if (sibling_num != null && !sibling_num.equals(""))
     133        {
     134            // we have to modify the doc name
     135            doc_id_modifier = "." + sibling_num + ".ss";
     136        }
     137
    127138
    128139        UserContext userContext = new UserContext(request);
     
    134145        // get the additional data needed for the page
    135146        getBackgroundData(page_response, collection, userContext);
     147
     148                // create a basic doc list containing the current node
     149                // we will use this to query whether the id is valid, and to get document type
     150        Element basic_doc_list = doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
     151        Element current_doc = doc.createElement(GSXML.DOC_NODE_ELEM);
     152        basic_doc_list.appendChild(current_doc);
     153        if (document_id != null)
     154        {
     155            current_doc.setAttribute(GSXML.NODE_ID_ATT, document_id + doc_id_modifier);
     156        }
     157        else
     158        {
     159            current_doc.setAttribute(GSXML.HREF_ID_ATT, href);
     160            // do we need this??
     161            current_doc.setAttribute(GSXML.ID_MOD_ATT, doc_id_modifier);
     162        }
     163
     164                // lets do a quick check here for valid doc id.
     165                if (document_id != null) {
     166                  boolean is_valid = checkValidOID(basic_doc_list, collection, userContext, page_response );
     167                  if (!is_valid) {
     168                    GSXML.addError(page_response, "Invalid doc id ("+document_id+")", GSXML.ERROR_TYPE_INVALID_ID);
     169                    return result;
     170                  }
     171                }
    136172        Element format_elem = (Element) GSXML.getChildByTagName(page_response, GSXML.FORMAT_ELEM);
    137173
     
    180216        }
    181217
    182         String doc_id_modifier = "";
    183         String sibling_num = (String) params.get(GOTO_PAGE_ARG);
    184         if (sibling_num != null && !sibling_num.equals(""))
    185         {
    186             // we have to modify the doc name
    187             doc_id_modifier = "." + sibling_num + ".ss";
    188         }
    189 
    190218        boolean expand_document = false;
    191219        String ed_arg = (String) params.get(EXPAND_DOCUMENT_ARG);
     
    226254        page_response.appendChild(the_document);
    227255
    228         // create a basic doc list containing the current node
    229         Element basic_doc_list = doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
    230         Element current_doc = doc.createElement(GSXML.DOC_NODE_ELEM);
    231         basic_doc_list.appendChild(current_doc);
    232         if (document_id != null)
    233         {
    234             current_doc.setAttribute(GSXML.NODE_ID_ATT, document_id + doc_id_modifier);
    235         }
    236         else
    237         {
    238             current_doc.setAttribute(GSXML.HREF_ID_ATT, href);
    239             // do we need this??
    240             current_doc.setAttribute(GSXML.ID_MOD_ATT, doc_id_modifier);
    241         }
    242        
     256// used to create basic_doc_list here       
    243257        if (document_type == null)
    244258        {
     
    342356            // Build a request to obtain the document structure
    343357            Element ds_message = doc.createElement(GSXML.MESSAGE_ELEM);
    344             String to = GSPath.appendLink(collection, "DocumentStructureRetrieve");// Hard-wired?
     358            String to = GSPath.appendLink(collection, AbstractDocumentRetrieve.DOCUMENT_STRUCTURE_RETRIEVE_SERVICE);
    345359            Element ds_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
    346360            ds_message.appendChild(ds_request);
     
    421435        // Build a request to obtain some document metadata
    422436        Element dm_message = doc.createElement(GSXML.MESSAGE_ELEM);
    423         String to = GSPath.appendLink(collection, "DocumentMetadataRetrieve"); // Hard-wired?
     437        String to = GSPath.appendLink(collection, AbstractDocumentRetrieve.DOCUMENT_METADATA_RETRIEVE_SERVICE);
    424438        Element dm_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
    425439        dm_message.appendChild(dm_request);
     
    575589        // Build a request to obtain some document content
    576590        Element dc_message = doc.createElement(GSXML.MESSAGE_ELEM);
    577         to = GSPath.appendLink(collection, "DocumentContentRetrieve"); // Hard-wired?
     591        to = GSPath.appendLink(collection, AbstractDocumentRetrieve.DOCUMENT_CONTENT_RETRIEVE_SERVICE);
    578592        Element dc_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
    579593        dc_message.appendChild(dc_request);
     
    783797    }
    784798
     799  protected boolean checkValidOID(Element basic_doc_list, String collection, UserContext userContext, Element page_response) {
     800    Document doc = basic_doc_list.getOwnerDocument();
     801   
     802    Element v_message = doc.createElement(GSXML.MESSAGE_ELEM);
     803    String to = GSPath.appendLink(collection, AbstractDocumentRetrieve.VALIDATE_DOCUMENT_ID_SERVICE);
     804    Element v_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
     805    v_message.appendChild(v_request);
     806
     807    // add the node list
     808    v_request.appendChild(basic_doc_list);
     809    Element v_response_message = (Element) this.mr.process(v_message);
     810    if (processErrorElements(v_response_message, page_response))
     811    {
     812      return false;
     813    }
     814    String[] links = { GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM };
     815    String path = GSPath.createPath(links);
     816    Element info_elem = (Element) GSXML.getNodeByPath(v_response_message, path);
     817    if (info_elem == null) {
     818      return false;
     819    }
     820    if (info_elem.getAttribute("valid").equals("true")) {
     821      return true;
     822    }
     823    return false;
     824
     825  }
     826
    785827  protected Element getFormattedArchiveDoc(Document doc, String collection, String document_id, String document_type, Element result, Element page_response, UserContext userContext ) {
    786828    // call get archive doc
    787829    Element dx_message = doc.createElement(GSXML.MESSAGE_ELEM);
    788     String to = "DocXMLGetSection";
     830    String to = DocXMLUtil.DOC_XML_GET_SECTION_SERVICE;
    789831    Element dx_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
    790832    dx_message.appendChild(dx_request);
     
    881923        // these could all be cached
    882924        Element info_message = doc.createElement(GSXML.MESSAGE_ELEM);
    883         String path = GSPath.appendLink(collection, "DocumentContentRetrieve");
     925        String path = GSPath.appendLink(collection, AbstractDocumentRetrieve.DOCUMENT_CONTENT_RETRIEVE_SERVICE);
    884926        // the format request - ignore for now, where does this request go to??
    885927        Element format_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_FORMAT, path, userContext);
     
    957999       
    9581000        Element ds_message = doc.createElement(GSXML.MESSAGE_ELEM);
    959         String to = GSPath.appendLink(collection, "DocumentStructureRetrieve");// Hard-wired?
     1001        String to = GSPath.appendLink(collection, AbstractDocumentRetrieve.DOCUMENT_STRUCTURE_RETRIEVE_SERVICE);
    9601002        Element ds_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
    9611003        ds_message.appendChild(ds_request);
     
    13321374     
    13331375     Element hl_message = doc.createElement(GSXML.MESSAGE_ELEM);
    1334      to = GSPath.appendLink(collection, "DocumentContentRetrieve");
     1376     to = GSPath.appendLink(collection, AbstractDocumentRetrieve.DOCUMENT_CONTENT_RETRIEVE_SERVICE);
    13351377     Element dc_request = GSXML.createBasicRequest(doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
    13361378     hl_message.appendChild(dc_request);
Note: See TracChangeset for help on using the changeset viewer.