Changeset 25816


Ignore:
Timestamp:
2012-06-26T15:29:29+12:00 (12 years ago)
Author:
kjdon
Message:

if no document type is specified in cgi params, then get it from the collection, don't just assume hierarchy

File:
1 edited

Legend:

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

    r25642 r25816  
    7474            provide_annotations = true;
    7575        }
    76         return true;
    77     }
     76        return true;    }
    7877
    7978    public Node process(Node message_node)
     
    120119        }
    121120        String document_type = (String) params.get(GSParams.DOCUMENT_TYPE);
    122         if (document_type == null || document_type.equals(""))
    123         {
    124             document_type = "hierarchy";
     121        if (document_type != null && document_type.equals(""))
     122        {
     123          //document_type = "hierarchy";
     124          document_type = null; // we'll get it later if not already specified
    125125        }
    126126        //whether to retrieve siblings or not
     
    175175        Element the_document = this.doc.createElement(GSXML.DOCUMENT_ELEM);
    176176        page_response.appendChild(the_document);
    177 
    178         // set the doctype from the cgi arg as an attribute
    179         the_document.setAttribute(GSXML.DOC_TYPE_ATT, document_type);
    180177
    181178        // create a basic doc list containing the current node
     
    193190            current_doc.setAttribute(GSXML.ID_MOD_ATT, doc_id_modifier);
    194191        }
     192
     193        if (document_type == null) {
     194          logger.error("getting document type");
     195          document_type = getDocumentType(basic_doc_list, collection, userContext, page_response);
     196          logger.error("new doc type = "+document_type);
     197        }
     198        if (document_type != null) {
     199          // set the doctype from the cgi arg or from the server as an attribute
     200          the_document.setAttribute(GSXML.DOC_TYPE_ATT, document_type);
     201        }
     202        else {
     203          logger.error("doctype is null!!!***********");
     204    }
    195205
    196206        // Create a parameter list to specify the required structure information
     
    286296            ds_request.appendChild(ds_param_list);
    287297
    288             // create a doc_node_list and put in the doc_node that we are interested in
     298            // add the node list we created earlier
    289299            ds_request.appendChild(basic_doc_list);
    290300
     
    679689            // a new message for the mr
    680690            Element enrich_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
    681 
    682691            NodeList e_services = services_resp.getElementsByTagName(GSXML.SERVICE_ELEM);
    683692            boolean service_found = false;
     
    710719
    711720    }
     721
     722  protected String getDocumentType(Element basic_doc_list, String collection, UserContext userContext, Element page_response)
     723  {
     724   
     725    Element ds_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
     726    String to = GSPath.appendLink(collection, "DocumentStructureRetrieve");// Hard-wired?
     727    Element ds_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
     728    ds_message.appendChild(ds_request);
     729
     730    // Create a parameter list to specify the required structure information
     731    Element ds_param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
     732    Element ds_param = this.doc.createElement(GSXML.PARAM_ELEM);
     733    ds_param_list.appendChild(ds_param);
     734    ds_param.setAttribute(GSXML.NAME_ATT, "info");
     735    ds_param.setAttribute(GSXML.VALUE_ATT, "documentType");
     736   
     737    ds_request.appendChild(ds_param_list);
     738   
     739    // add the node list we created earlier
     740    ds_request.appendChild(basic_doc_list);
     741   
     742    logger.error("doctype request = "+this.converter.getPrettyString(ds_request));
     743    // Process the document structure retrieve message
     744    Element ds_response_message = (Element) this.mr.process(ds_message);
     745    logger.error("doctype response = "+this.converter.getPrettyString(ds_response_message));
     746    if (processErrorElements(ds_response_message, page_response))
     747      {
     748    return null;
     749      }
     750
     751    String[] links = { GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER, GSXML.DOC_NODE_ELEM, "nodeStructureInfo"};
     752    String path = GSPath.createPath(links);
     753    Element info_elem = (Element) GSXML.getNodeByPath(ds_response_message, path);
     754      Element doctype_elem = GSXML.getNamedElement(info_elem, "info", "name", "documentType");
     755    if (doctype_elem != null) {
     756      String doc_type = doctype_elem.getAttribute("value");
     757      return doc_type;
     758    }
     759    return null;
     760  }
    712761
    713762    /**
Note: See TracChangeset for help on using the changeset viewer.