Changeset 4717


Ignore:
Timestamp:
2003-06-18T12:28:37+12:00 (21 years ago)
Author:
kjdon
Message:

in the middle of doing document display stuff - so this is unfinished, but should work mostly I hope

File:
1 edited

Legend:

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

    r4287 r4717  
    4242    // this is used to specify that the sibling nodes of a selected one should be obtained
    4343    public static final String SIBLING_ARG = "sib";
    44 
     44    public static final String DOC_TYPE_ARG = "dt";
     45   
    4546    /** if this is set to true, when a document is displayed, any annotation
    4647     * type services (enrich) will be offered to the user as well */
     
    6869        return result;
    6970    }
    70 
     71    String document_type = (String) params.get(DOC_TYPE_ARG);
    7172    //whether to retrieve siblings or not
    7273    boolean get_siblings = false;
     
    8485    page_response.appendChild(the_document);
    8586
    86    
    87     // Build a request to obtain the document structure
    88     Element ds_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    89     String to = GSPath.appendLink(collection, "DocumentStructureRetrieve");  // Hard-wired?
    90     Element ds_request = GSXML.createBasicRequest(doc_,GSXML.REQUEST_TYPE_PROCESS, to, lang);
    91     ds_message.appendChild(ds_request);
    92 
     87    // set the doctype from the cgi arg as an attribute
     88    the_document.setAttribute(GSXML.DOC_TYPE_ATT, document_type);
     89
     90    // create a basic doc list containing the current node
     91    Element basic_doc_list = doc_.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     92    Element current_doc = doc_.createElement(GSXML.DOC_NODE_ELEM);
     93    basic_doc_list.appendChild(current_doc);
     94    current_doc.setAttribute(GSXML.NODE_ID_ATT, document_name);
     95   
    9396    // Create a parameter list to specify the required structure information
    9497    Element ds_param_list = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    95     ds_request.appendChild(ds_param_list);
    96     Element ds_param = doc_.createElement(GSXML.PARAM_ELEM);
    97     ds_param_list.appendChild(ds_param);
    98     ds_param.setAttribute(GSXML.NAME_ATT, "structure");
    99     ds_param.setAttribute(GSXML.VALUE_ATT, "ancestors");
    100     ds_param = doc_.createElement(GSXML.PARAM_ELEM);
    101     ds_param_list.appendChild(ds_param);
    102     ds_param.setAttribute(GSXML.NAME_ATT, "structure");
    103     ds_param.setAttribute(GSXML.VALUE_ATT, "children");
    104     if (get_siblings) {
     98
     99    Element ds_param = null;
     100    boolean get_structure = false;
     101    boolean get_structure_info = false;
     102    if (document_type.equals("paged")) {
     103        get_structure_info = true;
     104        // get teh info needed for paged naviagtion
     105        ds_param = doc_.createElement(GSXML.PARAM_ELEM);
     106        ds_param_list.appendChild(ds_param);
     107        ds_param.setAttribute(GSXML.NAME_ATT, "info");
     108        ds_param.setAttribute(GSXML.VALUE_ATT, "numSiblings");
     109        ds_param = doc_.createElement(GSXML.PARAM_ELEM);
     110        ds_param_list.appendChild(ds_param);
     111        ds_param.setAttribute(GSXML.NAME_ATT, "info");
     112        ds_param.setAttribute(GSXML.VALUE_ATT, "numChildren");
     113        ds_param = doc_.createElement(GSXML.PARAM_ELEM);
     114        ds_param_list.appendChild(ds_param);
     115        ds_param.setAttribute(GSXML.NAME_ATT, "info");
     116        ds_param.setAttribute(GSXML.VALUE_ATT, "siblingPosition");
     117       
     118    } else if (document_type.equals("hierarchy")){
     119        get_structure = true;
     120        // get the info needed for table of contents
    105121        ds_param = doc_.createElement(GSXML.PARAM_ELEM);
    106122        ds_param_list.appendChild(ds_param);
    107123        ds_param.setAttribute(GSXML.NAME_ATT, "structure");
    108         ds_param.setAttribute(GSXML.VALUE_ATT, "siblings");
    109     }
    110 
    111     // put these in for now, but we should really decide what to do on basis of type, eg get structure for toc, get info for paged navigation etc
    112    
    113     // add in the info params to test them
    114     ds_param = doc_.createElement(GSXML.PARAM_ELEM);
    115     ds_param_list.appendChild(ds_param);
    116     ds_param.setAttribute(GSXML.NAME_ATT, "info");
    117     ds_param.setAttribute(GSXML.VALUE_ATT, "numSiblings");
    118     ds_param = doc_.createElement(GSXML.PARAM_ELEM);
    119     ds_param_list.appendChild(ds_param);
    120     ds_param.setAttribute(GSXML.NAME_ATT, "info");
    121     ds_param.setAttribute(GSXML.VALUE_ATT, "numChildren");
    122     ds_param = doc_.createElement(GSXML.PARAM_ELEM);
    123     ds_param_list.appendChild(ds_param);
    124     ds_param.setAttribute(GSXML.NAME_ATT, "info");
    125     ds_param.setAttribute(GSXML.VALUE_ATT, "siblingPosition");
    126    
    127     // create a doc_node_list and put in the doc_node that we are interested in
    128     Element ds_doc_list = doc_.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    129     ds_request.appendChild(ds_doc_list);
    130     Element ds_doc = doc_.createElement(GSXML.DOC_NODE_ELEM);
    131     ds_doc_list.appendChild(ds_doc);
    132     ds_doc.setAttribute(GSXML.NODE_ID_ATT, document_name);
    133    
    134     // Process the document structure retrieve message
    135     Element ds_response_message = (Element) mr_.process(ds_message);
    136 
    137     // get the info and print out
    138     String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    139     path = GSPath.appendLink(path, GSXML.DOC_NODE_ELEM);
    140     path = GSPath.appendLink(path, "nodeStructureInfo");
    141     Element ds_response_struct_info = (Element) GSXML.getNodeByPath(ds_response_message, path);
    142     // get the doc_node bit
    143     the_document.appendChild(doc_.importNode(ds_response_struct_info, true));
    144     path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    145     path = GSPath.appendLink(path, GSXML.DOC_NODE_ELEM);
    146     path = GSPath.appendLink(path, GSXML.NODE_STRUCTURE_ELEM);
    147     Element ds_response_structure = (Element) GSXML.getNodeByPath(ds_response_message, path);
    148 
    149     // add the contents of the structure bit into the_document
    150     NodeList structs = ds_response_structure.getChildNodes();
    151     for (int i=0; i<structs.getLength();i++) {
    152         the_document.appendChild(doc_.importNode(structs.item(i), true));
    153     }
    154 
     124        ds_param.setAttribute(GSXML.VALUE_ATT, "ancestors");
     125        ds_param = doc_.createElement(GSXML.PARAM_ELEM);
     126        ds_param_list.appendChild(ds_param);
     127        ds_param.setAttribute(GSXML.NAME_ATT, "structure");
     128        ds_param.setAttribute(GSXML.VALUE_ATT, "children");
     129        if (get_siblings) {
     130        ds_param = doc_.createElement(GSXML.PARAM_ELEM);
     131        ds_param_list.appendChild(ds_param);
     132        ds_param.setAttribute(GSXML.NAME_ATT, "structure");
     133        ds_param.setAttribute(GSXML.VALUE_ATT, "siblings");
     134        }
     135    } else {
     136        // we dont need any structure
     137    }
     138
     139    if (get_structure || get_structure_info) {
     140
     141        // Build a request to obtain the document structure
     142        Element ds_message = doc_.createElement(GSXML.MESSAGE_ELEM);
     143        String to = GSPath.appendLink(collection, "DocumentStructureRetrieve");// Hard-wired?
     144        Element ds_request = GSXML.createBasicRequest(doc_,GSXML.REQUEST_TYPE_PROCESS, to, lang);
     145        ds_message.appendChild(ds_request);
     146        ds_request.appendChild(ds_param_list);
     147       
     148        // create a doc_node_list and put in the doc_node that we are interested in
     149        ds_request.appendChild(basic_doc_list);
     150       
     151        // Process the document structure retrieve message
     152        Element ds_response_message = (Element) mr_.process(ds_message);
     153       
     154        // get the info and print out
     155        String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     156        path = GSPath.appendLink(path, GSXML.DOC_NODE_ELEM);
     157        path = GSPath.appendLink(path, "nodeStructureInfo");
     158        Element ds_response_struct_info = (Element) GSXML.getNodeByPath(ds_response_message, path);
     159        // get the doc_node bit
     160        if (ds_response_struct_info != null) {
     161        the_document.appendChild(doc_.importNode(ds_response_struct_info, true));
     162        }
     163        path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     164        path = GSPath.appendLink(path, GSXML.DOC_NODE_ELEM);
     165        path = GSPath.appendLink(path, GSXML.NODE_STRUCTURE_ELEM);
     166        Element ds_response_structure = (Element) GSXML.getNodeByPath(ds_response_message, path);
     167       
     168        if (ds_response_structure != null) {
     169        // add the contents of the structure bit into the_document
     170        NodeList structs = ds_response_structure.getChildNodes();
     171        for (int i=0; i<structs.getLength();i++) {
     172            the_document.appendChild(doc_.importNode(structs.item(i), true));
     173        }
     174        }
     175    } else {
     176        // no structure request, so just put in a dummy doc node
     177        Element doc_node = doc_.createElement(GSXML.DOC_NODE_ELEM);
     178        doc_node.setAttribute(GSXML.NODE_ID_ATT, document_name);
     179        the_document.appendChild(doc_node);
     180    }
     181   
    155182    // Build a request to obtain some document metadata
    156183    Element dm_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    157     to = GSPath.appendLink(collection, "DocumentMetadataRetrieve");  // Hard-wired?
     184    String to = GSPath.appendLink(collection, "DocumentMetadataRetrieve");  // Hard-wired?
    158185    Element dm_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_PROCESS, to, lang);
    159186    dm_message.appendChild(dm_request);
     
    165192    dm_param_list.appendChild(dm_param);
    166193    dm_param.setAttribute(GSXML.NAME_ATT, "metadata");
    167     dm_param.setAttribute(GSXML.VALUE_ATT, "Title");
     194    dm_param.setAttribute(GSXML.VALUE_ATT, "all");
    168195
    169196    // create the doc node list for the metadata request
     
    206233    Element dm_response_message = (Element) mr_.process(dm_message);
    207234
    208     path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
     235    String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    209236    Element dm_response_doc_list = (Element) GSXML.getNodeByPath(dm_response_message, path);
    210237
     
    214241        GSXML.mergeMetadataLists(doc_nodes.item(i), dm_response_docs.item(i));
    215242    }
    216     // get teh top level do metadata out
     243    // get teh top level doc metadata out
    217244    Element doc_meta_response = (Element)dm_response_message.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1);
    218245    Element doc_meta_list = (Element)GSXML.getNodeByPath(doc_meta_response, "documentNodeList/documentNode/metadataList");
     
    231258
    232259    // the doc list for the content request is the same as the one for the structure request
    233     dc_request.appendChild(ds_doc_list);
     260    dc_request.appendChild(basic_doc_list);
    234261
    235262    Element dc_response_message = (Element) mr_.process(dc_message);
     
    313340    // these could all be cached
    314341    Element info_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    315 
     342    String path = GSPath.appendLink(collection, "DocumentMetadataRetrieve");
    316343    // the format request - ignore for now, where does this request go to??
    317     //Element format_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_FORMAT, ???, lang);
    318     //info_message.appendChild(format_request);
     344    Element format_request = GSXML.createBasicRequest(doc_, GSXML.REQUEST_TYPE_FORMAT, path, lang);
     345    info_message.appendChild(format_request);
    319346
    320347    // the enrich_services request - only do this if provide_annotations is true
     
    330357    // the collection is the first response
    331358    NodeList responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
    332     //Element format_resp = (Element) responses.item(1);
    333     //page_reponse.appendChild(doc_.importNode(GSXML.getChildByTagName(format_resp, GSXML.FORMAT_ELEM), true));
    334    
     359    Element format_resp = (Element) responses.item(0);
     360    if (format_resp != null) {
     361        System.out.println("doc action found a format statement");
     362        Element format_elem = (Element)doc_.importNode(GSXML.getChildByTagName(format_resp, GSXML.FORMAT_ELEM), true);
     363        // set teh format type
     364        format_elem.setAttribute(GSXML.TYPE_ATT, "display");
     365       
     366        page_response.appendChild(format_elem);
     367    }
    335368
    336369    if (provide_annotations) {
    337         Element services_resp = (Element)responses.item(0); // change when format request added in
     370        Element services_resp = (Element)responses.item(1);
    338371
    339372        // a new message for the mr
     
    367400    }
    368401
    369     /** this involves a bit of a hack to get the equivalent query terms - has to requery the query service - uses the last selected service name. (if it ends in query). should this action do the query or shoul dit send a message to the query action? but that will involve lots of extra stuff. also doesn't handle phrases properly - just highlights all teh terms found in the text.
     402    /** this involves a bit of a hack to get the equivalent query terms - has to requery the query service - uses the last selected service name. (if it ends in query). should this action do the query or should it send a message to the query action? but that will involve lots of extra stuff. also doesn't handle phrases properly - just highlights all the terms found in the text.
    370403     */
    371404    protected Element highlightQueryTerms(Element request, Element dc_response_doc_content) {
     
    414447    }
    415448
     449    Element new_content_elem = doc_.createElement(GSXML.NODE_CONTENT_ELEM);
     450
    416451    String content = GSXML.getNodeText(dc_response_doc_content);
    417452
    418453    StringBuffer temp = new StringBuffer();
    419     StringBuffer new_content = new StringBuffer();
     454    StringBuffer temp_content = new StringBuffer();
    420455
    421456    for (int i=0; i<content.length(); i++) {
     
    429464        if (temp.length()>0) {
    430465            if (all_terms.contains(temp.toString())) {
    431             new_content.append("<annotation type='query_term'>"+temp+"</annotation>");
     466            //if there is anything already present in temp_content, add it as a text node
     467            Text t = doc_.createTextNode(temp_content.toString());
     468            new_content_elem.appendChild(t);
     469            temp_content.delete(0, temp_content.length());
     470            Element annot = GSXML.createTextElement(doc_, "annotation", temp.toString());
     471            annot.setAttribute("type", "query_term");
     472            new_content_elem.appendChild(annot);
     473            //new_content.append("<annotation type='query_term'>"+temp+"</annotation>");
    432474            } else {
    433             new_content.append(temp);
     475            temp_content.append(temp);
    434476            }
    435477            temp.delete(0, temp.length());
    436478        }
    437479        if (c=='<') {
    438             temp.append(c);
     480            temp_content.append(c);
    439481            i++;
    440482            // skip over html
    441483            while (i<content.length() && content.charAt(i)!='>') {
    442             temp.append(content.charAt(i));
     484            temp_content.append(content.charAt(i));
    443485            i++;
    444486            }
    445             temp.append(content.charAt(i));
    446             new_content.append(GSXML.xmlSafe(temp.toString()));
    447             temp.delete(0, temp.length());
     487            temp_content.append(content.charAt(i));
     488            //temp_content.append(GSXML.xmlSafe(temp.toString()));
     489            //temp.delete(0, temp.length());
    448490           
    449491        } else {
    450             new_content.append(c);
     492            temp_content.append(c);
    451493        }
    452494        }
    453495    }
    454    
    455     String content_string = "<nodeContent>"+new_content.toString()+"</nodeContent>";
    456     Element content_elem = converter_.getDOM(content_string).getDocumentElement();
    457     return content_elem;
     496    // append anything left of temp_content and temp
     497    Text t = doc_.createTextNode(temp_content.toString());
     498    new_content_elem.appendChild(t);
     499
     500    if (temp.length() > 0) {
     501        Element annot = GSXML.createTextElement(doc_, "annotation", temp.toString());
     502        annot.setAttribute("type", "query_term");
     503        new_content_elem.appendChild(annot);
     504    }
     505    //String content_string = "<nodeContent>"+new_content.toString()+"</nodeContent>";
     506    //Element content_elem = converter_.getDOM(content_string).getDocumentElement();
     507    return new_content_elem;
    458508    }
    459509}
Note: See TracChangeset for help on using the changeset viewer.