Ignore:
Timestamp:
2002-11-26T13:55:24+13:00 (21 years ago)
Author:
kjdon
Message:

tidied up a bit, uses new page structure and new display elements

File:
1 edited

Legend:

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

    r3512 r3568  
    1010import java.util.HashMap;
    1111import java.io.File;
     12
     13/** action for classifier browsing */
    1214public class BrowseAction extends Action {
    1315   
     16    public Element process (Element message) {
    1417
    15     public String process (Element message) {
    16 
     18    // get the request - assume only one
     19    Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
     20   
    1721    // create the return page tree
    1822    Element page = doc_.createElement(GSXML.PAGE_ELEM);
    19     page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));
     23    page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
    2024    // add the lang stuff from message
    21     page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true));
     25    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true));
    2226    // add the system stuff from message
    2327    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
    2428
    25     Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);
    2629   
    2730    // the browse type is the subaction
     
    3740   
    3841
    39     protected String classifierBrowse(Element page, Element request) {
     42    protected Element classifierBrowse(Element page, Element request) {
    4043
    4144    // check that the stylesheet is present - cant output a page without one. we may adapt this to use unknownquery stylesheet? - or ask for one from the MR
    4245    String stylesheet = GSFile.stylesheetFile(config_, "classifier.xsl");
    4346    if (stylesheet==null) {
    44         return GSHTML.errorPage("classifier stylesheet not found!");
     47        System.err.println("BrowseAction Error: classifier stylesheet not found!");
     48        return null;
    4549    }
    4650    Document style_doc = converter_.getDOM(new File(stylesheet));
     
    5458    String collection = (String)params.get("collection");
    5559    if (collection == null || collection.equals("")) {
    56         return GSHTML.errorPage("classifierbrowse, need to specify a collection!");
     60        System.err.println("BrowseAction Error:classifierbrowse, need to specify a collection!");
     61        return null;
     62       
    5763    }
    5864
    59     // the first part of the data for the page is the cgi-params
    60     Element cgi_request = (Element)doc_.importNode(request, true);
    61     page.appendChild(cgi_request);
    6265
    63     // get the service info from the MR - this will probably need to be cached somehow later on. and add as a description node to the cgi-request - this doesn't work. change to add the specified value as a current attribute to the param - need to do somthing different for query
     66    // get the service info from the MR - this will probably need to be cached somehow later on.
    6467
    6568    Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM);
     
    6770    mr_info_message.appendChild(mr_info_request);
    6871    mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
     72    mr_info_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
    6973
    7074    String to = collection;
     
    7377
    7478    Element mr_info_response = (Element) mr_.process(mr_info_message);
    75     Element description = doc_.createElement(GSXML.DESCRIPTION_ELEM);
    7679
    7780    String path = GSXML.RESPONSE_ELEM;
    7881    path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
    79     path = GSPath.appendLink(path, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
    80     Node cl = GSXML.getNodeByPath(mr_info_response, path);
    8182
    82     Element imported_classList = (Element)doc_.importNode(cl, true);
     83    Element description = (Element)doc_.importNode(GSXML.getNodeByPath(mr_info_response, path), true);
     84   
     85    // the first part of the data for the page is the cgi-params
     86    Element cgi_request = (Element)doc_.importNode(request, true);
     87    page.appendChild(cgi_request);
    8388
    84     description.appendChild(imported_classList);
    85     cgi_request.appendChild(description);
    86 
    87 
     89    page.appendChild(description);
     90   
    8891    // if there is a cl field in the cgi params, get the classifier info
    8992    String node = (String)params.get("classifier");
     93   
     94    if (node!=null && !node.equals("")) {
    9095
    91     if (node==null|| node.equals("")) {
    92         System.out.println("no cl node selected");
    93         // if there is no cl set, just output the list
    94         GSXSLT.absoluteIncludePaths(style_doc, config_);
    95         return transformer_.transform(style_doc, page);       
     96        // get the info for the selected node
     97        Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);
     98        Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM);
     99        mr_query_message.appendChild(mr_query_request);
     100       
     101        mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
     102        mr_query_request.setAttribute(GSXML.TO_ATT, to);
     103        mr_query_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
     104       
     105       
     106        // paramList - empty for now
     107        Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     108        mr_query_request.appendChild(paramList);
     109       
     110       
     111        // content - contains the classifier node, may be more than one
     112        // call this resource list for now
     113        Element query_content = doc_.createElement(GSXML.CONTENT_ELEM);
     114        mr_query_request.appendChild(query_content);
     115       
     116        Element resource_list = doc_.createElement(GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER);
     117        Element resource = doc_.createElement(GSXML.RESOURCE_ELEM);
     118        resource.setAttribute(GSXML.NAME_ATT, node);
     119        resource_list.appendChild(resource);
     120        query_content.appendChild(resource_list);
     121       
     122        Element mr_query_response = (Element)mr_.process(mr_query_message);
     123       
     124        Element response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
     125        Node new_style = GSXML.getChildByTagName(response, "stylesheet");
     126        if (new_style !=null) {
     127        GSXSLT.mergeStylesheets(style_doc, (Element)new_style);
     128        response.removeChild(new_style);
     129        }
     130        // add the response to the page data
     131        page.appendChild(doc_.importNode(response, true));
     132
    96133    }
    97134   
    98     // get the info for the selected node
    99     Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    100     Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM);
    101     mr_query_message.appendChild(mr_query_request);
    102 
    103     mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
    104     mr_query_request.setAttribute(GSXML.TO_ATT, to);
    105 
    106     // paramList - empty for now
    107     Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    108     mr_query_request.appendChild(paramList);
    109 
    110 
    111     // content - contains the classifier node, may be more than one
    112     // call this resource list for now
    113     Element query_content = doc_.createElement(GSXML.CONTENT_ELEM);
    114     mr_query_request.appendChild(query_content);
    115    
    116     Element resource_list = doc_.createElement(GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER);
    117     Element resource = doc_.createElement(GSXML.RESOURCE_ELEM);
    118     resource.setAttribute(GSXML.NAME_ATT, node);
    119     resource_list.appendChild(resource);
    120     query_content.appendChild(resource_list);
    121 
    122     Element mr_query_response = (Element)mr_.process(mr_query_message);
    123 
    124     Element response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
    125     Node new_style = GSXML.getChildByTagName(response, "stylesheet");
    126     if (new_style !=null) {
    127         GSXSLT.mergeStylesheets(style_doc, (Element)new_style);
    128         response.removeChild(new_style);
    129     }
    130     // add the response to the page data
    131     page.appendChild(doc_.importNode(response, true));
    132 
    133135    GSXSLT.absoluteIncludePaths(style_doc, config_);
    134     return transformer_.transform(style_doc, page);
     136    return (Element)transformer_.transform(style_doc, page);
    135137    }
    136138
    137     protected String unknownBrowse(Element page, Element request, String browse_type) {
    138 
    139     return GSHTML.errorPage("unknown browse subtype: "+browse_type);
     139    protected Element unknownBrowse(Element page, Element request, String browse_type) {
     140    System.err.println("BrowseAction Error: unknown browse subtype: "+browse_type);
     141    return null;
    140142    }
    141143}
Note: See TracChangeset for help on using the changeset viewer.