Changeset 3896


Ignore:
Timestamp:
2003-03-18T15:02:23+12:00 (21 years ago)
Author:
kjdon
Message:

added sib arg - if set to 1, get the siblings of a selected node. also tidied up the code a bit

File:
1 edited

Legend:

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

    r3868 r3896  
    3838public class DocumentAction extends Action {
    3939 
     40    // this is used to specify that the sibling nodes of a selected one should be obtained
     41    public static final String SIBLING_ARG = "sib";
     42
     43    /* add the action specific args to the cgi param list
     44     */
     45    public void addCGIParams() {
     46    cgi_.addStaticParam(SIBLING_ARG);
     47    }
     48
     49
    4050    public Element process (Element message)
    4151    {
     
    5464        return null;
    5565    }
    56 
    57 
     66    //whether to retrieve siblings or not
     67    boolean get_siblings = false;
     68    String sibs = (String) params.get(SIBLING_ARG);
     69    if (sibs != null && sibs.equals("1")) {
     70        get_siblings = true;
     71    }
     72   
    5873    // Build a request to obtain the document structure
    5974    Element ds_message = doc_.createElement(GSXML.MESSAGE_ELEM);
     
    7691    ds_param.setAttribute(GSXML.NAME_ATT, "structure");
    7792    ds_param.setAttribute(GSXML.VALUE_ATT, "children");
    78 
     93    if (get_siblings) {
     94        ds_param = doc_.createElement(GSXML.PARAM_ELEM);
     95        ds_param_list.appendChild(ds_param);
     96        ds_param.setAttribute(GSXML.NAME_ATT, "structure");
     97        ds_param.setAttribute(GSXML.VALUE_ATT, "siblings");
     98    }
    7999    // create a doc_node_list and put in the doc_node that we are interested in
    80100    Element ds_doc_list = doc_.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     
    102122        the_document.appendChild(doc_.importNode(structs.item(i), true));
    103123    }
    104     //Element ds_response = (Element) GSXML.getChildByTagName(ds_response_message, GSXML.RESPONSE_ELEM);
    105     //Element ds_response_doc_list = (Element) GSXML.getChildByTagName(ds_response, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    106     //Element ds_response_document = (Element) GSXML.getChildByTagName(ds_response_doc_list, GSXML.DOC_NODE_ELEM);
    107 
    108     // Detach the document from the list, remove the list, and add the document back
    109     // ds_response is the re
    110     //ds_response.removeChild(ds_response_doc_list);
    111     //ds_response.appendChild(ds_response_document);
    112 
    113124
    114125    // Build a request to obtain some document metadata
     
    155166    Element dm_response_doc_list = (Element) GSXML.getNodeByPath(dm_response_message, path);
    156167
    157     //Element dm_response_content = (Element) GSXML.getNodeByPath(dm_response, "response/content");
    158     //Element dm_response_doc_list = (Element) GSXML.getNodeByPath(dm_response_content, "documentList");
    159 
    160168    // Merge the metadata with the structure information
    161169    NodeList dm_response_docs = dm_response_doc_list.getChildNodes();
     
    180188    // the doc list for the content request is the same as the one for the structure request
    181189    dc_request.appendChild(ds_doc_list);
    182 //      Element dc_doc_list = doc_.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    183 //      dc_request.appendChild(dc_doc_list);
    184 //      Element dc_doc = doc_.createElement(GSXML.DOC_NODE_ELEM);
    185 //      dc_doc_list.appendChild(dc_doc);
    186 //      dc_doc.setAttribute(GSXML.DOC_NODE_ID, document_name);
    187190
    188191    // System.out.println("(DocumentAction) Content request:\n" + converter_.getString(dc_request));
     
    191194   
    192195    path = GSPath.appendLink(path, GSXML.DOC_NODE_ELEM);
    193     path = GSPath.appendLink(path, GSXML.DOC_NODE_CONTENT_ELEM);
    194     Element dc_response_doc_content = (Element) GSXML.getNodeByPath(dc_response_message, path);
    195 
     196    Element dc_response_doc = (Element) GSXML.getNodeByPath(dc_response_message, path);
     197    //path = GSPath.appendLink(path, GSXML.DOC_NODE_CONTENT_ELEM);
     198    Element dc_response_doc_content = (Element) GSXML.getChildByTagName(dc_response_doc, GSXML.DOC_NODE_CONTENT_ELEM);
     199    // use the returned id rather than the sent one cos there may have
     200    // been modifiers such as .pr that are removed.
     201    String modified_doc_id = dc_response_doc.getAttribute(GSXML.NODE_ID_ATT);
    196202    // Merge the document content with the metadata and structure information
    197203    for (int i = 0; i < doc_nodes.getLength(); i++) {
     
    199205        Node doc_node_id = doc_node.getAttributes().getNamedItem(GSXML.DOC_NODE_ID_ATT);
    200206        String dc_doc_id = doc_node_id.getNodeValue();
    201         if (dc_doc_id == document_name) {
     207        if (dc_doc_id.equals(modified_doc_id)) {
    202208        doc_node.appendChild(doc_.importNode(dc_response_doc_content, true));
    203209        break;
     
    219225    response.appendChild(the_document);
    220226   
    221     // System.out.println("Finished page: " + converter_.getString(page));
     227     System.out.println("doc action: Finished page: " + converter_.getString(page));
    222228   
    223229   
Note: See TracChangeset for help on using the changeset viewer.