Ignore:
Timestamp:
2012-03-27T15:18:44+13:00 (12 years ago)
Author:
kjdon
Message:

tidying up handling of external links and hrefs that are relative greenstone links

File:
1 edited

Legend:

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

    r25128 r25305  
    4848    public static final String GOTO_PAGE_ARG = "gp";
    4949    public static final String ENRICH_DOC_ARG = "end";
     50    public static final String EXPAND_DOCUMENT_ARG = "ed";
     51    public static final String EXPAND_CONTENTS_ARG = "ec";
     52    public static final String REALISTIC_BOOK_ARG = "book";
    5053
    5154    /**
     
    9295        HashMap service_params = (HashMap) params.get("s0");
    9396
    94         String has_rl = null;
    95         String has_href = null;
    96         has_href = (String) params.get("href");//for an external link : get the href URL if it is existing in the params list
    97         has_rl = (String) params.get("rl");//for an external link : get the rl value if it is existing in the params list
    9897        String collection = (String) params.get(GSParams.COLLECTION);
    99         UserContext userContext = new UserContext(request);
    100         String document_name = (String) params.get(GSParams.DOCUMENT);
    101         if ((document_name == null || document_name.equals("")) && (has_href == null || has_href.equals("")))
     98        String document_id = (String) params.get(GSParams.DOCUMENT);
     99        if (document_id != null && document_id.equals("")) {
     100          document_id = null;
     101        }
     102        String href = (String) params.get(GSParams.HREF);//for an external link : get the href URL if it is existing in the params list
     103        if (href != null && href.equals("")) {
     104          href = null;
     105        }
     106        String rl = (String) params.get(GSParams.RELATIVE_LINK);//for an external link : get the rl value if it is existing in the params list
     107        if (document_id == null && href == null)
    102108        {
    103109            logger.error("no document specified!");
    104110            return result;
    105111        }
     112        if (rl != null && rl.equals("0")) {
     113          // this is a true external link, we should have been directed to a different page or action
     114          logger.error("rl value was 0, shouldn't get here");
     115          return result;
     116        }
    106117        String document_type = (String) params.get(GSParams.DOCUMENT_TYPE);
    107         if (document_type == null)
     118        if (document_type == null ||  document_type.equals(""))
    108119        {
    109120            document_type = "simple";
     
    117128        }
    118129
     130        String doc_id_modifier = "";
    119131        String sibling_num = (String) params.get(GOTO_PAGE_ARG);
    120132        if (sibling_num != null && !sibling_num.equals(""))
    121133        {
    122134            // we have to modify the doc name
    123             document_name = document_name + "." + sibling_num + ".ss";
     135            doc_id_modifier = "." + sibling_num + ".ss";
    124136        }
    125137
    126138        boolean expand_document = false;
    127         String ed_arg = (String) params.get(GSParams.EXPAND_DOCUMENT);
     139        String ed_arg = (String) params.get(EXPAND_DOCUMENT_ARG);
    128140        if (ed_arg != null && ed_arg.equals("1"))
    129141        {
     
    138150        else
    139151        {
    140             String ec_arg = (String) params.get(GSParams.EXPAND_CONTENTS);
     152            String ec_arg = (String) params.get(EXPAND_CONTENTS_ARG);
    141153            if (ec_arg != null && ec_arg.equals("1"))
    142154            {
     
    144156            }
    145157        }
     158       
     159        UserContext userContext = new UserContext(request);
    146160
    147161        //append site metadata
     
    165179        Element current_doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    166180        basic_doc_list.appendChild(current_doc);
    167         if (document_name.length() != 0)
    168         {
    169             current_doc.setAttribute(GSXML.NODE_ID_ATT, document_name);
    170         }
    171         else if (has_href.length() != 0)
    172         {
    173             current_doc.setAttribute(GSXML.NODE_ID_ATT, has_href);
    174             current_doc.setAttribute("externalURL", has_rl);
     181        if (document_id != null)
     182        {
     183            current_doc.setAttribute(GSXML.NODE_ID_ATT, document_id+doc_id_modifier);
     184        }
     185        else
     186        {
     187            current_doc.setAttribute(GSXML.HREF_ID_ATT, href);
     188            // do we need this??
     189            current_doc.setAttribute(GSXML.ID_MOD_ATT, doc_id_modifier);
    175190        }
    176191
     
    198213            }
    199214
    200             // get teh info needed for paged naviagtion
     215            // get the info needed for paged naviagtion
    201216            ds_param = this.doc.createElement(GSXML.PARAM_ELEM);
    202217            ds_param_list.appendChild(ds_param);
     
    305320                // no structure nodes, so put in a dummy doc node
    306321                Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    307                 if (document_name.length() != 0)
    308                 {
    309                     doc_node.setAttribute(GSXML.NODE_ID_ATT, document_name);
    310                 }
    311                 else if (has_href.length() != 0)
    312                 {
    313                     doc_node.setAttribute(GSXML.NODE_ID_ATT, has_href);
    314                     doc_node.setAttribute("externalURL", has_rl);
     322                if (document_id != null)
     323                {
     324                    doc_node.setAttribute(GSXML.NODE_ID_ATT, document_id);
     325                }
     326                else
     327                {
     328                    doc_node.setAttribute(GSXML.HREF_ID_ATT, href);
     329               
    315330                }
    316331                the_document.appendChild(doc_node);
     
    323338            // no structure request, so just put in a dummy doc node
    324339            Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    325             if (document_name.length() != 0)
    326             {
    327                 doc_node.setAttribute(GSXML.NODE_ID_ATT, document_name);
    328             }
    329             else if (has_href.length() != 0)
    330             {
    331                 doc_node.setAttribute(GSXML.NODE_ID_ATT, has_href);
    332                 doc_node.setAttribute("externalURL", has_rl);
     340            if (document_id != null)
     341            {
     342                doc_node.setAttribute(GSXML.NODE_ID_ATT, document_id);
     343            }
     344            else
     345            {
     346                doc_node.setAttribute(GSXML.HREF_ID_ATT, href);
    333347            }
    334348            the_document.appendChild(doc_node);
     
    398412        Element doc_node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    399413        // the node we want is the root document node
    400         if (document_name.length() != 0)
    401         {
    402             doc_node.setAttribute(GSXML.NODE_ID_ATT, document_name + ".rt");
    403         }
    404         else if (has_href.length() != 0)
    405         {
    406             doc_node.setAttribute(GSXML.NODE_ID_ATT, has_href + ".rt");
    407             doc_node.setAttribute("externalURL", has_rl);
     414        if (document_id != null)
     415        {
     416            doc_node.setAttribute(GSXML.NODE_ID_ATT, document_id + ".rt");
     417        }
     418        else
     419        {
     420          doc_node.setAttribute(GSXML.HREF_ID_ATT, href);// + ".rt");
     421          // can we assume that href is always a top level doc??
     422          //doc_node.setAttribute(GSXML.ID_MOD_ATT, ".rt");
     423            //doc_node.setAttribute("externalURL", has_rl);
    408424        }
    409425        doc_list.appendChild(doc_node);
     
    486502            Element dc_response_doc = (Element) GSXML.getChildByTagName(dc_response_doc_list, GSXML.DOC_NODE_ELEM);
    487503            Element dc_response_doc_content = (Element) GSXML.getChildByTagName(dc_response_doc, GSXML.NODE_CONTENT_ELEM);
    488             Element dc_response_doc_external = (Element) GSXML.getChildByTagName(dc_response_doc, "external");
     504            //Element dc_response_doc_external = (Element) GSXML.getChildByTagName(dc_response_doc, "external");
    489505
    490506            if (dc_response_doc_content == null)
    491507            {
    492508                // no content to add
    493                 if (dc_response_doc_external != null)
    494                 {
    495                     String modified_doc_id = dc_response_doc.getAttribute(GSXML.NODE_ID_ATT);
    496 
    497                     the_document.setAttribute("selectedNode", modified_doc_id);
    498                     the_document.setAttribute("external", dc_response_doc_external.getAttribute("external_link"));
    499                 }
    500                 return result;
     509              if (dc_response_doc.getAttribute("external").equals("true")) {
     510               
     511                //if (dc_response_doc_external != null)
     512                //{
     513                    String href_id = dc_response_doc.getAttribute(GSXML.HREF_ID_ATT);
     514
     515                    the_document.setAttribute("selectedNode", href_id);
     516                    the_document.setAttribute("external", href_id);
     517              }
     518              return result;
    501519            }
    502520            if (highlight_query_terms)
     
    598616     * important for args that should not be saved
    599617     */
    600     public boolean getActionParameters(GSParams params)
     618    public boolean addActionParameters(GSParams params)
    601619    {
    602620        params.addParameter(GOTO_PAGE_ARG, false);
    603621        params.addParameter(ENRICH_DOC_ARG, false);
     622        params.addParameter(EXPAND_DOCUMENT_ARG, false);
     623        params.addParameter(EXPAND_CONTENTS_ARG, false);
     624        params.addParameter(REALISTIC_BOOK_ARG, false);
     625
    604626        return true;
    605627    }
Note: See TracChangeset for help on using the changeset viewer.