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/BuildAction.java

    r3513 r3568  
    1717   
    1818
    19     public String process (Element message) {
     19    public Element process (Element message) {
    2020
    21     //find the stylesheet
     21    //find the stylesheet - cant go any further if not found
    2222    String stylesheet = GSFile.stylesheetFile(config_, "build.xsl");
    2323
    2424    if (stylesheet==null) {
    25         return GSHTML.errorPage("build stylesheet not found!");
     25        System.err.println("BuildAction Error: build stylesheet not found!");
     26        return null;
    2627    }
     28
     29    Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);
     30    String service_name = request.getAttribute(GSXML.SUBACTION_ATT);
     31    // get the param list
     32    Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     33    HashMap params = GSXML.extractParams(cgi_param_list);
    2734
    2835    // create the return page tree
    2936    Element page = doc_.createElement(GSXML.PAGE_ELEM);
    30     page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));
     37    page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
    3138    // add the lang stuff from message
    32     page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true));
     39    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true));
    3340    // add the system stuff from message
    3441    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
     42   
    3543
    36     Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);
    37     String service_name = request.getAttribute(GSXML.SUBACTION_ATT);
     44    //  we need to do the request before getting the description-
     45    // it may have changedthe action may change the descripiton, eg
     46    // deleting a collection changes the collection list
     47    String collection = (String)params.get("collection");
     48    String to = "build"; // knwo this cos its build action - loaded by a cluster called build
     49    to = GSPath.appendLink(to, service_name);
    3850   
    39     // get the param list
    40     Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    41     cgi_.toLong(cgi_paramList);
    42     HashMap params = GSXML.extractParams(cgi_paramList);
     51    if (collection != null && !collection.equals("")) {
     52       
     53        // a collection has been specified - do the request
     54        Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);
     55        Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM);
     56        mr_query_message.appendChild(mr_query_request);
     57       
     58        mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_BUILD);
     59        mr_query_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
     60       
     61        mr_query_request.setAttribute(GSXML.TO_ATT, to);
     62       
     63        // paramList
     64        Element query_param_list = (Element) doc_.importNode(cgi_param_list, true);
     65        mr_query_request.appendChild(query_param_list);
     66       
     67        Element mr_query_response = (Element)mr_.process(mr_query_message);
     68        Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
     69        // append the response to the page
     70        page.appendChild(doc_.importNode(result_response, true));
     71    }
    4372
    44     // the first part of the data for the page is the cgi-params
    45     Element cgi_request = (Element)doc_.importNode(request, true);
    46     page.appendChild(cgi_request);
     73    // another part of the page is the service description
    4774
    48     // the second part of the page is the param list for the service
    49     // request the service info for the selected service - should be cached?
    50    
     75    // request the service info for the selected service - should be cached
    5176    Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    5277    Element mr_info_request = doc_.createElement(GSXML.REQUEST_ELEM);
    5378    mr_info_message.appendChild(mr_info_request);
    5479    mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
     80    mr_info_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
    5581
    56     String to = "build"; // knwo this cos its build action - loaded by a cluster called build
    57     to = GSPath.appendLink(to, service_name);
    5882    mr_info_request.setAttribute(GSXML.TO_ATT, to);
    59 
     83   
    6084    Element mr_info_response = (Element) mr_.process(mr_info_message);
    61     System.err.println("describe response for service");
    62     System.err.println(converter_.getString(mr_info_response));
    63     Element description = doc_.createElement(GSXML.DESCRIPTION_ELEM);
    64     // just param list for now - may need content info too
    6585
    6686    String path = GSXML.RESPONSE_ELEM;
    6787    path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
    68     path = GSPath.appendLink(path, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     88    Element description = (Element)doc_.importNode(GSXML.getNodeByPath(mr_info_response, path), true);
    6989
    70     Node pl = GSXML.getNodeByPath(mr_info_response, path);
    71     if (pl ==null) {
    72         System.out.println("pl is null");
    73     }
    74     else {
    75         System.out.println("pl name is "+pl.getNodeName());
    76     }
    77     Element imported_paramList = (Element)doc_.importNode(pl, true);
    78     // convert the name to short
    79     cgi_.addShortNames(imported_paramList);
     90    Element pl = (Element)GSXML.getChildByTagName(description, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     91   
     92    if (pl !=null) {
     93        // add short names to the params in the param list
     94        cgi_.addShortNames(pl);
    8095
    81     description.appendChild(imported_paramList);
    82    
    83     // for each param in page_request, set the current value if present
    84     //actually, prob dont need to know the default value, just which one to display - overwrite the default att?
    85    
    86     Element param = (Element)imported_paramList.getFirstChild();
    87     while (param !=null) {
    88         if (param.getNodeName().equals(GSXML.PARAM_ELEM)) { // just in case
    89         String name = param.getAttribute(GSXML.NAME_ATT);
    90         String current = (String)params.get(name);
    91         if (current !=null && !current.equals("")) {
    92             param.setAttribute(GSXML.DEFAULT_ATT, current);
     96        // for each param in the description, overwrite teh default value with the currently set value if present
     97        Element param = (Element)pl.getFirstChild();
     98        while (param !=null) {
     99        if (param.getNodeName().equals(GSXML.PARAM_ELEM)) { // just in case
     100            String name = param.getAttribute(GSXML.NAME_ATT);
     101            String current = (String)params.get(name);
     102            if (current !=null && !current.equals("")) {
     103            param.setAttribute(GSXML.DEFAULT_ATT, current);
     104            }
    93105        }
    94         }
    95         param = (Element)param.getNextSibling();
    96     }
    97    
    98     cgi_request.appendChild(description);
    99    
    100     // now see if we need to actually do anything - only if a colleciton has been set
    101     String collection = (String)params.get("collection");
    102     if (collection == null || collection.equals("")) {
    103         // no coll set - just output the form
    104        
    105         Document style_doc = converter_.getDOM(new File(stylesheet));
    106         GSXSLT.absoluteIncludePaths(style_doc, config_);
    107         return transformer_.transform(style_doc, page);       
    108     }
    109    
    110     // else do the request, output search box and results
    111     Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    112     Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM);
    113     mr_query_message.appendChild(mr_query_request);
    114 
    115     mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_BUILD);
    116     mr_query_request.setAttribute(GSXML.TO_ATT, to);
    117 
    118     // paramList
    119     Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    120     mr_query_request.appendChild(paramList);
    121 
    122     Iterator i = params.entrySet().iterator();
    123     while (i.hasNext()) {
    124         Map.Entry e = (Map.Entry)i.next();
    125         String name = cgi_.toLong((String)e.getKey());
    126         if (!name.equals("")) {
    127         String value = (String)e.getValue();
    128         // if (!name.equals("c")) {
    129         Element p = doc_.createElement(GSXML.PARAM_ELEM);
    130         p.setAttribute(GSXML.NAME_ATT, name);
    131         p.setAttribute(GSXML.VALUE_ATT, value);
    132         paramList.appendChild(p);
    133         // }
     106        param = (Element)param.getNextSibling();
    134107        }
    135108    }
     109    page.appendChild(description);
     110
     111    // part of the data for the page is the cgi-params
     112    // if we have this here, do we need to do the previous step?
     113    Element cgi_request = (Element)doc_.importNode(request, true);
     114    page.appendChild(cgi_request);
    136115   
    137     Element mr_query_response = (Element)mr_.process(mr_query_message);
    138116
    139     // this result is a message
    140     Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
    141     page.appendChild(doc_.importNode(result_response, true));
    142 
     117    // now process the page and return the result
    143118    Document style_doc = converter_.getDOM(new File(stylesheet));
    144119   
    145120    GSXSLT.absoluteIncludePaths(style_doc, config_);
    146     return transformer_.transform(style_doc, page);   
     121    return (Element)transformer_.transform(style_doc, page);   
    147122    }     
    148123}
Note: See TracChangeset for help on using the changeset viewer.