Ignore:
Timestamp:
2002-10-11T13:36:37+13:00 (22 years ago)
Author:
kjdon
Message:

now handles GSDL2 style classifications

File:
1 edited

Legend:

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

    r3388 r3454  
    88import org.w3c.dom.Element;
    99
     10import java.util.HashMap;
     11import java.io.File;
    1012public class BrowseAction extends Action {
    1113   
    1214
    1315    public String process (Element message) {
     16
     17    // create the return page tree
     18    Element page = doc_.createElement("page");
     19    page.setAttribute("lang", message.getAttribute("lang"));
     20    // add the lang stuff from message
     21    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "translate"), true));
     22    // add the system stuff from message
     23    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, "config"), true));
    1424
    1525    Element request = (Element)message.getElementsByTagName("request").item(0);
     
    2030    String browse_type = GSPath.getFirstLink(info);
    2131   
    22     return unknownBrowse(request, browse_type);
     32    if (browse_type.equals("classifier")) {
     33        return classifierBrowse(page, request);
     34    }
     35    return unknownBrowse(page, request, browse_type);
    2336
    2437   
     
    2639   
    2740
    28     protected String unknownBrowse(Element request, String browse_type) {
     41    protected String classifierBrowse(Element page, Element request) {
     42
     43    // 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
     44    String stylesheet = GSFile.stylesheetFile(config_, "classifier.xsl");
     45    if (stylesheet==null) {
     46        return GSHTML.errorPage("classifier stylesheet not found!");
     47    }
     48    Document style_doc = converter_.getDOM(new File(stylesheet));
     49
     50    // extract the params from the cgi-request, and check that we have a coll specified
     51    // first convert short to long names
     52    Element cgi_paramList = (Element)GSXML.getChildByTagName(request, "paramList");
     53    cgi_.toLong(cgi_paramList);
     54    HashMap params = GSXML.extractParams(cgi_paramList);
     55
     56    String collection = (String)params.get("c");
     57    if (collection == null || collection.equals("")) {
     58        return GSHTML.errorPage("classifierbrowse, need to specify a collection!");
     59    }
     60
     61    // the first part of the data for the page is the cgi-params
     62    Element cgi_request = (Element)doc_.importNode(request, true);
     63    page.appendChild(cgi_request);
     64
     65    // 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
     67    Element mr_info_message = doc_.createElement("message");
     68    Element mr_info_request = doc_.createElement("request");
     69    mr_info_message.appendChild(mr_info_request);
     70    mr_info_request.setAttribute("type", "describe");
     71
     72    String to = collection;
     73    to = GSPath.appendLink(to, "ClassifierBrowse");
     74    mr_info_request.setAttribute("to", to);
     75
     76    Element mr_info_response = (Element) mr_.process(mr_info_message);
     77    Element description = doc_.createElement("description");
     78    Node cl = GSXML.getNodeByPath(mr_info_response, "response/service/classifierList");
     79
     80    Element imported_classList = (Element)doc_.importNode(cl, true);
     81
     82    description.appendChild(imported_classList);
     83    cgi_request.appendChild(description);
     84
     85
     86    // if there is a cl field in the cgi params, get the classifier info
     87    String node = (String)params.get("cl");
     88
     89    if (node==null|| node.equals("")) {
     90        System.out.println("no cl node selected");
     91        // if there is no cl set, just output the list
     92        GSXSLT.absoluteIncludePaths(style_doc, config_);
     93        return transformer_.transform(stylesheet, page);       
     94    }
     95   
     96    // get the info for the selected node
     97    Element mr_query_message = doc_.createElement("message");
     98    Element mr_query_request = doc_.createElement("request");
     99    mr_query_message.appendChild(mr_query_request);
     100
     101    mr_query_request.setAttribute("type", "query");
     102    mr_query_request.setAttribute("to", to);
     103
     104    // paramList - empty for now
     105    Element paramList = doc_.createElement("paramList");
     106    mr_query_request.appendChild(paramList);
     107
     108
     109    // content - contains the classifier node, may be more than one
     110    // call this resource list for now
     111    Element query_content = doc_.createElement("content");
     112    mr_query_request.appendChild(query_content);
     113   
     114    Element resource_list = doc_.createElement("resourceList");
     115    Element resource = doc_.createElement("resource");
     116    resource.setAttribute("name", node);
     117    resource_list.appendChild(resource);
     118    query_content.appendChild(resource_list);
     119
     120    Element mr_query_response = (Element)mr_.process(mr_query_message);
     121
     122    Element response = (Element)GSXML.getChildByTagName(mr_query_response, "response");
     123    Node new_style = GSXML.getChildByTagName(response, "stylesheet");
     124    if (new_style !=null) {
     125        GSXSLT.mergeStylesheets(style_doc, (Element)new_style);
     126        response.removeChild(new_style);
     127    }
     128    // add the response to the page data
     129    page.appendChild(doc_.importNode(response, true));
     130
     131    GSXSLT.absoluteIncludePaths(style_doc, config_);
     132    return transformer_.transform(style_doc, page);
     133    }
     134
     135    protected String unknownBrowse(Element page, Element request, String browse_type) {
    29136
    30137    return GSHTML.errorPage("unknown browse subtype: "+browse_type);
Note: See TracChangeset for help on using the changeset viewer.