Changeset 3568


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

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/action
Files:
7 edited

Legend:

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

    r3363 r3568  
    88import org.w3c.dom.Document;
    99
     10/** base class for Actions */
    1011abstract public class Action {
    1112
     13    /** the interface setup variables */
    1214    protected ConfigVars config_=null;
    13  
    1415    /** container Document to create XML Nodes */
    1516    protected Document doc_=null;
    1617    /** a converter class to parse XML and create Docs */
    1718    protected XMLConverter converter_=null;
    18     /** cgi args conveter */
     19    /** cgi args converter */
    1920    protected CGIArgConverter cgi_=null;
    2021    /** a transformer class to transform xml using xslt */
     
    5556    Element message = converter_.getDOM(xml_in).getDocumentElement();
    5657   
    57     return process(message);
     58    Element result = process(message);
     59    return converter_.getString(result);
    5860    }
    5961   
    60     abstract public String process(Element xml_in);
     62    abstract public Element process(Element xml_in);
    6163   
    6264
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/action/AppletAction.java

    r3512 r3568  
    1212import java.io.File;
    1313
     14/** action class for handling applets */
    1415public class AppletAction extends Action {
    1516   
    1617
    17     public String process (Element message) {
    18 
     18    public Element process (Element message) {
     19   
    1920
    2021    // find the stylesheet
     
    2223
    2324    if (stylesheet==null) {
    24         return GSHTML.errorPage("applet stylesheet not found!");
     25        System.err.println("AppletAction Error: applet stylesheet not found!");
     26        return null;
    2527    }
    26 
    27     Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);
    28 
    29     // subaction is display/request
    30     String request_type = request.getAttribute(GSXML.SUBACTION_ATT); // should be 'd' or 'r'
     28   
     29    Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
     30   
     31    // subaction is display (d) or request (r)
     32    String request_type = request.getAttribute(GSXML.SUBACTION_ATT);
    3133    if (!request_type.equals("d")&&!request_type.equals("r")) {
    32         return GSHTML.errorPage("the sa arg to a=a should be d or r!!");
     34        System.err.println("AppletAction Error: the sa arg should be either d or r, instead it was "+request_type+"!");
     35        return null;
    3336    }
    3437   
    3538    // get the collection and service param
    36     Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    37     cgi_.toLong(cgi_paramList);
    38     HashMap params = GSXML.extractParams(cgi_paramList);
     39    Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     40    HashMap params = GSXML.extractParams(cgi_param_list);
    3941
    4042    String collection = (String)params.get("collection");
     
    4951    }
    5052
    51     System.out.println("to="+to);
    52 
    53 
    5453    if (request_type.equals("d")) {
    5554        // we are just displaying the applet - get the description from
     
    6261        mr_message.appendChild(mr_request);
    6362        mr_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
     63        mr_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
    6464        mr_request.setAttribute(GSXML.TO_ATT, to);
    65         //mr_request.setAttribute(GSXML."info", "appletInfo");
    6665       
    6766        Element mr_response = (Element)mr_.process(mr_message);
    6867       
    69         System.out.println("applet mr response =");
    70         System.out.println(converter_.getString(mr_response));
    7168        // create the return page tree
    7269        Element page = doc_.createElement(GSXML.PAGE_ELEM);
    73         page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));
     70        page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
    7471        // add the lang stuff from message
    75         page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true));
     72        page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true));
    7673        // add the config stuff from message
    7774        page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
     
    9289        Document style_doc = converter_.getDOM(new File(stylesheet));
    9390        GSXSLT.absoluteIncludePaths(style_doc, config_);
    94         return transformer_.transform(style_doc, page);   
     91        return (Element)transformer_.transform(style_doc, page);   
    9592
    9693    }
     
    103100        mr_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
    104101        mr_request.setAttribute(GSXML.TO_ATT, to);
    105        
     102        mr_request.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
     103
    106104        // just append the params for now
    107         mr_request.appendChild(doc_.importNode(cgi_paramList, true));
     105        mr_request.appendChild(doc_.importNode(cgi_param_list, true));
    108106       
    109107        Element mr_response = (Element)mr_.process(mr_message);
    110         System.out.println("applet query response:");
    111         // dont need to create a page, just extract the info out.
    112         System.out.println(converter_.getString(mr_response));
    113108        // add in the applet data
    114109        String path = GSXML.RESPONSE_ELEM;
    115110        path = GSPath.appendLink(path, GSXML.APPLET_DATA_ELEM);
    116111        Element applet_info = (Element)GSXML.getNodeByPath(mr_response, path).getFirstChild();
    117         System.out.println("applet action: applet data =");
    118         System.out.println(converter_.getString(applet_info));
    119         return converter_.getString(applet_info);
     112        return applet_info;
    120113
    121114    }
    122     else {
    123         // should never get here
    124         return GSHTML.errorPage("applet action, wrong subaction type");
    125     }
     115    // should never get here
     116    return null;
    126117    }
    127118
  • 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}
  • 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}
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/action/PageAction.java

    r3512 r3568  
    1414public class PageAction extends Action {
    1515
    16     public String process (Element message) {
     16    public Element process (Element message) {
    1717   
    18     Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);
     18    Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
    1919    // the page name is the subaction
    2020    String page_name = request.getAttribute(GSXML.SUBACTION_ATT);
    21 
     21    if (page_name.equals("")) { // if no page specified, assume home page
     22        page_name = "home";
     23    }
     24   
    2225    // create the return page tree
    2326    Element page = doc_.createElement(GSXML.PAGE_ELEM);
    24     page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));
    25     // add the lang stuff from xml_in
    26     page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true));
    27     // add the system stuff from xml_in
     27    page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
     28    // add the lang stuff from message
     29    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true));
     30    // add the system stuff from message
    2831    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
    29 
    30     if (page_name.equals("")) {
    31         // for now send an error. change to always display the home page?
    32         return GSHTML.errorPage(" page action specified, but no page specified");
    33     }
     32   
    3433    if (page_name.equals("home")) {
    3534        return homePage(page, request);
     
    3736        return aboutPage(page, request);
    3837    } else {
    39         return GSHTML.errorPage("page: "+page_name+" not yet implemented");
     38        System.err.println("PageAction Error: unimplemented page specified!");
     39        return null;
    4040    }
    4141    }
    42 
    43 
    44     protected String homePage(Element page, Element orig_message) {
     42   
     43    protected Element homePage(Element page, Element orig_message) {
    4544   
    46     // first, get the list of collections from mr
    47    
     45    // first, get the message router info
    4846    Element coll_list_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    49     coll_list_message.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
    5047    Element coll_list_request = doc_.createElement(GSXML.REQUEST_ELEM);
    5148    coll_list_message.appendChild(coll_list_request);
    5249    coll_list_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
    53     //coll_list_request.setAttribute("info", "collectionList");
    54    
     50    coll_list_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
     51    System.out.println("PageAction: getting mesage router description.");
    5552    Element coll_list_response = (Element)mr_.process(coll_list_message);
    5653    if (coll_list_response==null) {
    57         return GSHTML.errorPage("couldn't query the mr about collections");
     54        System.err.println("PageAction Error: couldn't query the message router!");
     55        return null;
    5856    }
    5957   
    60     // second, get the metadata for each collection
     58    // second, get the metadata for each collection - we only want specific
     59    // elements but for now, we'll just get it all
    6160    NodeList colls = coll_list_response.getElementsByTagName(GSXML.COLLECTION_ELEM);
    62    
    63     //Element metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    64     //metadata_message.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
    65     //Element metadata_request = doc_.createElement(GSXML.REQUEST_ELEM);
    66     //metadata_message.appendChild(metadata_request);
    67     //metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);   
     61    // we will send all the requests in a single message
     62    Element metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    6863    for (int i=0; i<colls.getLength(); i++) {
    69         Element metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    70         metadata_message.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
    7164        Element metadata_request = doc_.createElement(GSXML.REQUEST_ELEM);
     65        metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
     66        metadata_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
     67        Element c = (Element)colls.item(i);
     68        String name = c.getAttribute(GSXML.NAME_ATT);       
     69        metadata_request.setAttribute(GSXML.TO_ATT, name); // overwrites the old value 
     70        // add this request to the message
    7271        metadata_message.appendChild(metadata_request);
    73         metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
    74    
    75         // get the metadata for each one
    76         Element c = (Element)colls.item(i);
    77         String name = c.getAttribute(GSXML.NAME_ATT);
    78         System.out.println("getting metadata for coll "+name);
    79        
    80         metadata_request.setAttribute(GSXML.TO_ATT, name); // overwrites the old value
    81         System.out.println("metadata message = \n"+converter_.getString(metadata_message));
    82         Element metadata_response = (Element)mr_.process(metadata_message);
    83         Element coll = (Element)metadata_response.getElementsByTagName(GSXML.COLLECTION_ELEM).item(0);
    84         if (coll==null) {
    85         System.out.println("coll is null, in \n"+converter_.getString(metadata_response));
     72    }
     73    System.out.println("PageAction: getting metadata for each collection.");
     74    Element metadata_response = (Element)mr_.process(metadata_message);
     75
     76    NodeList coll_responses = metadata_response.getElementsByTagName(GSXML.COLLECTION_ELEM);
     77    // check that have same number of responses as collections
     78    if (colls.getLength() != coll_responses.getLength()) {
     79        System.err.println("PageAction Error: didn't get a response for each collection - somethings gone wrong!");
     80        // for now, dont use the metadata
     81    } else {
     82        for (int i=0; i<colls.getLength(); i++) {
     83        Element c1 = (Element)colls.item(i);
     84        Element c2 = (Element)coll_responses.item(i);
     85        if (c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT))) {
     86            // add the metadata to the original response   
     87            GSXML.mergeMetadataLists(c1, c2); // add the metadata to the original response   
     88        } else {
     89            System.err.println("PageAction Error: response does not correspond to request!");
     90        }
     91       
    8692        }
    87         GSXML.mergeMetadataLists(c, coll); // add the metadata to the original response
    8893    }
    8994
     
    96101    Document style_doc = converter_.getDOM(new File(stylesheet));
    97102    GSXSLT.absoluteIncludePaths(style_doc, config_);
    98     //System.out.println("page=");
    99     //System.out.println(converter_.getString(page));
    100     return transformer_.transform(style_doc, page);   
     103    return (Element)transformer_.transform(style_doc, page);       
    101104   
    102              
    103105    } // homePage
    104106
    105     protected String aboutPage(Element page, Element request) {
     107    protected Element aboutPage(Element page, Element request) {
    106108
    107109    // extract the params from the cgi-request,
    108     // first convert short to long names
    109110    Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    110     cgi_.toLong(cgi_paramList);
    111111    HashMap params = GSXML.extractParams(cgi_paramList);
    112112   
     
    116116    }
    117117    if (coll_name == null || coll_name.equals("")) {
    118         return GSHTML.errorPage("about page - need to specify coll name or cluster name");
     118        System.err.println("PageAction Error: about page requested with no collection or cluster specified!");
     119        return null;
    119120    }
    120 
     121   
     122    // get the collection or cluster description
    121123    Element coll_about_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    122     coll_about_message.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
    123 
    124124    Element coll_about_request = doc_.createElement(GSXML.REQUEST_ELEM);
    125125    coll_about_message.appendChild(coll_about_request);
    126126    coll_about_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
    127127    coll_about_request.setAttribute(GSXML.TO_ATT, coll_name);
    128 
     128    coll_about_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
     129   
    129130    Element coll_about_response = (Element)mr_.process(coll_about_message);
    130131
    131     //  System.out.println("coll response=");
    132     //System.out.println(converter_.getString(coll_about_response));
    133132    // add the response to the page
    134133    page.appendChild(doc_.importNode(GSXML.getChildByTagName(coll_about_response, GSXML.RESPONSE_ELEM), true));
     
    138137    Document style_doc = converter_.getDOM(new File(stylesheet));
    139138    GSXSLT.absoluteIncludePaths(style_doc, config_);
    140     return transformer_.transform(style_doc, page);   
     139    return (Element)transformer_.transform(style_doc, page);   
    141140
    142141   
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/action/QueryAction.java

    r3512 r3568  
    55// XML classes
    66import org.w3c.dom.Node;
     7import org.w3c.dom.NodeList;
    78import org.w3c.dom.Text;
    89import org.w3c.dom.Document;
     
    1112import java.util.HashMap;
    1213import java.util.Map;
    13 //import java.util.Map;
    1414import java.util.Iterator;
    1515import java.io.File;
    1616
     17/** action class for queries */
    1718public class QueryAction extends Action {
    1819   
    19 
    20     public String process (Element message) {
    21 
     20    public Element process (Element message) {
     21
     22    // get the request - assume there is only one
     23    Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
    2224
    2325    // create the return page tree
    2426    Element page = doc_.createElement(GSXML.PAGE_ELEM);
    25     page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));
     27    page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
    2628    // add the lang stuff from message
    27     page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true));
     29    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true));
    2830    // add the system stuff from message
    29     page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
    30 
    31     Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);
     31       page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
     32
    3233    // query type is teh subaction
    3334    String query_type = request.getAttribute(GSXML.SUBACTION_ATT);
     
    4950   
    5051    // we may be able to generalize this for all query types?
    51     protected String textQuery(Element page, Element request) {
    52 
    53     // chack 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
     52    protected Element textQuery(Element page, Element request) {
     53
     54    // 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
    5455    String stylesheet = GSFile.stylesheetFile(config_, "textquery.xsl");
    5556    if (stylesheet==null) {
    56         return GSHTML.errorPage("textquery stylesheet not found!");
     57        System.err.println("QueryAction Error: textquery stylesheet not found!");
     58        return null;
    5759    }
    5860
    5961    // extract the params from the cgi-request, and check that we have a coll specified
    60     // first convert short to long names
    61     Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    62     cgi_.toLong(cgi_paramList);
    63     HashMap params = GSXML.extractParams(cgi_paramList);
     62    Element cgi_param_list = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     63    HashMap params = GSXML.extractParams(cgi_param_list);
    6464
    6565    String collection = (String)params.get("collection");
    6666    if (collection == null || collection.equals("")) {
    67         return GSHTML.errorPage("textquery, need to specify a colleciton!");
    68     }
    69 
    70     // the first part of the data for the page is the cgi-params
    71     Element cgi_request = (Element)doc_.importNode(request, true);
    72     page.appendChild(cgi_request);
    73 
    74     // 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
    75 
     67        System.err.println("QueryAction Error: no colleciton was specified!");
     68        return null;
     69    }
     70
     71    // get the service info from the MR - this will probably need to be cached somehow later on. and add the service node to the page
    7672    Element mr_info_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    7773    Element mr_info_request = doc_.createElement(GSXML.REQUEST_ELEM);
    7874    mr_info_message.appendChild(mr_info_request);
    7975    mr_info_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_DESCRIBE);
     76    mr_info_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
    8077
    8178    String to = collection;
     
    8481
    8582    Element mr_info_response = (Element) mr_.process(mr_info_message);
    86     System.err.println("describe response for service");
    87     System.err.println(converter_.getString(mr_info_response));
    88     Element description = doc_.createElement(GSXML.DESCRIPTION_ELEM);
    89     // just param list for now - may need content info too
     83
    9084    String path = GSXML.RESPONSE_ELEM;
    9185    path = GSPath.appendLink(path, GSXML.SERVICE_ELEM);
    92     path = GSPath.appendLink(path, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    93     Node pl = GSXML.getNodeByPath(mr_info_response, path);
    94     if (pl ==null) {
    95         System.out.println("pl is null");
    96     }
    97     else {
    98         System.out.println("pl name is "+pl.getNodeName());
    99    
    100         Element imported_paramList = (Element)doc_.importNode(pl, true);
    101         // convert the name to short
    102         cgi_.addShortNames(imported_paramList);
    103 
    104         description.appendChild(imported_paramList);
    105    
    106         // for each param in page_request, set the current value if present
    107         //actually, prob dont need to know the default value, just which one to display - overwrite the default att?
    108        
    109         Element param = (Element)imported_paramList.getFirstChild();
     86    Element description = (Element)doc_.importNode(GSXML.getNodeByPath(mr_info_response, path), true);
     87    Element pl = (Element)GSXML.getChildByTagName(description, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
     88   
     89    if (pl !=null) {
     90        // add short names to the params in the param list
     91        cgi_.addShortNames(pl);
     92
     93        // for each param in the description, overwrite teh default value with the currently set value if present
     94        Element param = (Element)pl.getFirstChild();
    11095        while (param !=null) {
    11196        if (param.getNodeName().equals(GSXML.PARAM_ELEM)) { // just in case
     
    119104        }
    120105    }
    121     cgi_request.appendChild(description);
     106   
     107    // part of the data for the description is the cgi-params
     108    // if we have this here, do we need to do the previous step?
     109    Element cgi_request = (Element)doc_.importNode(request, true);
     110    page.appendChild(cgi_request);
     111
     112    page.appendChild(description);
    122113   
    123114    // check the query string
    124115    String query = (String)params.get(GSXML.REQUEST_TYPE_QUERY);
    125116
    126     if (query==null|| query.equals("")) {
    127         // if there is no q set, just output the search form
    128 
    129         Document style_doc = converter_.getDOM(new File(stylesheet));
    130         GSXSLT.absoluteIncludePaths(style_doc, config_);
    131         return transformer_.transform(style_doc, page);       
    132     }
    133    
    134     // else do the request, output search box and results
    135     Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    136     Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM);
    137     mr_query_message.appendChild(mr_query_request);
    138 
    139     mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
    140     mr_query_request.setAttribute(GSXML.TO_ATT, to);
    141 
    142     // paramList
    143     Element paramList = doc_.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    144     mr_query_request.appendChild(paramList);
    145 
    146     Iterator i = params.entrySet().iterator();
    147     while (i.hasNext()) {
    148         Map.Entry e = (Map.Entry)i.next();
    149         String name = cgi_.toLong((String)e.getKey());
    150         if (!name.equals("")) {
    151         String value = (String)e.getValue();
    152         // if (!name.equals("c")) {
    153         Element p = doc_.createElement(GSXML.PARAM_ELEM);
    154         p.setAttribute(GSXML.NAME_ATT, name);
    155         p.setAttribute(GSXML.VALUE_ATT, value);
    156         paramList.appendChild(p);
    157         // }
     117    if (query!=null&& !query.equals("")) {
     118        // do the query
     119       
     120        Element mr_query_message = doc_.createElement(GSXML.MESSAGE_ELEM);
     121        Element mr_query_request = doc_.createElement(GSXML.REQUEST_ELEM);
     122        mr_query_message.appendChild(mr_query_request);
     123
     124        mr_query_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
     125        mr_query_request.setAttribute(GSXML.TO_ATT, to);
     126        mr_query_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
     127        // paramList
     128        // should we remove the query from the param list?
     129        Element query_param_list = (Element)doc_.importNode(cgi_param_list, true);
     130        mr_query_request.appendChild(query_param_list);
     131       
     132        // content - contains the query string
     133        Element query_content = GSXML.createTextElement(doc_, GSXML.CONTENT_ELEM, query);
     134        mr_query_request.appendChild(query_content);
     135       
     136        Element mr_query_response = (Element)mr_.process(mr_query_message);
     137       
     138        // this result is the list of docs.
     139        // now take that list, and get the Titles
     140        // for now, just create a whole new request
     141       
     142        // check that there are some resources - for now check the list, but later should use a numdocs metadata elem
     143        path = GSXML.RESPONSE_ELEM;
     144        path = GSPath.appendLink(path, GSXML.CONTENT_ELEM);
     145        path = GSPath.appendLink(path, GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER);
     146       
     147        Element resource_list = (Element)GSXML.getNodeByPath(mr_query_response,
     148                                 path); // resourceList not present if no docs found
     149        if (resource_list == null) {
     150       
     151        Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
     152       
     153        page.appendChild(doc_.importNode(result_response, true));
     154       
     155        Document style_doc = converter_.getDOM(new File(stylesheet));
     156        GSXSLT.absoluteIncludePaths(style_doc, config_);
     157        return (Element)transformer_.transform(style_doc, page);   
     158       
    158159        }
    159     }
    160 
    161     // content - contains the query string
    162     Element query_content = doc_.createElement(GSXML.CONTENT_ELEM);
    163     Text query_text = doc_.createTextNode(query);
    164     query_content.appendChild(query_text);
    165     mr_query_request.appendChild(query_content);
    166    
    167     Element mr_query_response = (Element)mr_.process(mr_query_message);
    168 
    169     // this result is the list of docs.
    170     // now take that list, and get the Titles
    171     // for now, just create a whole new request
    172 
    173     // check that there are some resources - for now check the list, but later should use a numdocs metadata elem
    174     path = GSXML.RESPONSE_ELEM;
    175     path = GSPath.appendLink(path, GSXML.CONTENT_ELEM);
    176     path = GSPath.appendLink(path, GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER);
    177 
    178     Element resource_list = (Element)GSXML.getNodeByPath(mr_query_response,
    179                                  path); // resourceList not present if no docs found
    180     if (resource_list == null) {
    181 
    182         Element result_response = (Element)GSXML.getChildByTagName(mr_query_response, GSXML.RESPONSE_ELEM);
     160       
     161        // we have a doc list, so get the metadata - for now, get title.
     162        // can we dynamically decide what metadata to get?
     163        Element mr_metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM);
     164        Element mr_metadata_request = doc_.createElement(GSXML.REQUEST_ELEM);
     165        mr_metadata_message.appendChild(mr_metadata_request);
     166       
     167        mr_metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
     168        mr_metadata_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
     169        to = GSPath.appendLink(collection, "MetadataRetrieve");
     170        mr_metadata_request.setAttribute(GSXML.TO_ATT, to);
     171       
     172        Element meta_content = doc_.createElement(GSXML.CONTENT_ELEM);
     173        mr_metadata_request.appendChild(meta_content);
     174       
     175        // the first part of the content is the doc list
     176        meta_content.appendChild(doc_.importNode(resource_list, true));
     177       
     178        // the second part of the content is the metadata list
     179        Element metadata_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
     180        Element title = doc_.createElement(GSXML.METADATA_ELEM);
     181        title.setAttribute(GSXML.NAME_ATT, "Title");
     182        metadata_list.appendChild(title);
     183        meta_content.appendChild(metadata_list);
     184
     185        Element mr_metadata_response = (Element)mr_.process(mr_metadata_message);
     186       
     187        Element result_response = (Element)GSXML.getChildByTagName(mr_metadata_response, GSXML.RESPONSE_ELEM);
    183188       
    184189        page.appendChild(doc_.importNode(result_response, true));
    185 
    186         Document style_doc = converter_.getDOM(new File(stylesheet));
    187         GSXSLT.absoluteIncludePaths(style_doc, config_);
    188         return transformer_.transform(style_doc, page);   
    189 
    190     }
    191 
    192     // we have a doc list, so get the metadata - for now, get title.
    193     // can we dynamically decide what metadata to get?
    194     // get the Title metadata
    195     Element mr_metadata_message = doc_.createElement(GSXML.MESSAGE_ELEM);
    196     Element mr_metadata_request = doc_.createElement(GSXML.REQUEST_ELEM);
    197     mr_metadata_message.appendChild(mr_metadata_request);
    198 
    199     mr_metadata_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
    200     to = GSPath.appendLink(collection, "MetadataRetrieve");
    201     mr_metadata_request.setAttribute(GSXML.TO_ATT, to);
    202    
    203     Element meta_content = doc_.createElement(GSXML.CONTENT_ELEM);
    204     mr_metadata_request.appendChild(meta_content);
    205 
    206     // the first part of the content is the doc list
    207     meta_content.appendChild(doc_.importNode(resource_list, true));
    208 
    209     // the second part of the content is the metadata list
    210     Element metadata_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    211     Element title = doc_.createElement(GSXML.METADATA_ELEM);
    212     title.setAttribute(GSXML.NAME_ATT, "Title");
    213     metadata_list.appendChild(title);
    214     meta_content.appendChild(metadata_list);
    215 
    216     Element mr_metadata_response = (Element)mr_.process(mr_metadata_message);
    217    
    218     Element result_response = (Element)GSXML.getChildByTagName(mr_metadata_response, GSXML.RESPONSE_ELEM);
    219    
    220     page.appendChild(doc_.importNode(result_response, true));
    221    
     190   
     191    } // do teh query
     192
     193   
     194    // output the page
    222195    // process using the stylesheet
    223196    Document style_doc = converter_.getDOM(new File(stylesheet));
    224197    GSXSLT.absoluteIncludePaths(style_doc, config_);
    225     return transformer_.transform(style_doc, page);   
    226    
    227     }
    228 
    229     protected String fieldQuery(Element page, Element request) {
    230     return GSHTML.errorPage("field query not implemented");
    231 
    232 
    233     }
    234     protected String unknownQuery(Element page, Element request, String query_type) {
    235 
    236     return GSHTML.errorPage("unknown query subtype - "+query_type+" query not implemented");
     198    return (Element)transformer_.transform(style_doc, page);   
     199   
     200    }
     201
     202    protected Element fieldQuery(Element page, Element request) {
     203    String p =  GSHTML.errorPage("field query not implemented");
     204
     205    return converter_.getDOM(p).getDocumentElement();
     206    }
     207    protected Element unknownQuery(Element page, Element request, String query_type) {
     208
     209    String p =  GSHTML.errorPage("unknown query subtype - "+query_type+" query not implemented");
     210    return null;//converter_.getDOM(p).getDocumentElement();
    237211    }
    238212}
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/action/ResourceAction.java

    r3512 r3568  
    1111import java.io.File;
    1212
     13/** Action class for retrieving Documents or Resources via the message router
     14 */
    1315public class ResourceAction extends Action {
    14 
    15 
    16     // could pass in action name, and have it dynamically decide the name
    17    
    18     public String process (Element message) {
    19 
     16 
     17    public Element process (Element message) {
     18   
    2019    // find the stylesheet
    2120    String stylesheet = GSFile.stylesheetFile(config_, "resource.xsl");
    2221
    2322    if (stylesheet==null) {
    24         return GSHTML.errorPage("resource stylesheet not found!");
     23        System.err.println("ResourceAction Error: resource stylesheet not found!");
     24        return null;
    2525    }
    26 
     26   
    2727    // for now, no subaction eventually we may want to have subactions such as text assoc or something ?
    2828   
    29     Element request = (Element)message.getElementsByTagName(GSXML.REQUEST_ELEM).item(0);
    30 
     29    // get the request - assume only one
     30    Element request = (Element)GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
    3131    Element cgi_paramList = (Element)GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    32     cgi_.toLong(cgi_paramList);
    3332    HashMap params = GSXML.extractParams(cgi_paramList);
    3433
    3534    String resource_name = (String)params.get("resource");
    3635    if (resource_name == null || resource_name.equals("")) {
    37         // no doc to show
    38         return GSHTML.errorPage("no resource specified");
     36        System.err.println("ResourceAction Error: no resource specified!");
     37        return null;
    3938    }
    40    
    41    
     39       
    4240    // create the return page tree
    4341    Element page = doc_.createElement(GSXML.PAGE_ELEM);
    44     page.setAttribute(GSXML.LANG_ATT, message.getAttribute(GSXML.LANG_ATT));
     42    page.setAttribute(GSXML.LANG_ATT, request.getAttribute(GSXML.LANG_ATT));
    4543    // add the lang stuff from message
    46     page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.TRANSLATION_ELEM), true));
     44    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.DISPLAY_ELEM), true));
    4745    // add the config stuff from message
    4846    page.appendChild(doc_.importNode(GSXML.getChildByTagName(message, GSXML.CONFIGURATION_ELEM), true));
    49 
    50 
    5147
    5248    // build up the mr request
     
    5551    mr_message.appendChild(mr_request);
    5652    mr_request.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
     53    mr_request.setAttribute(GSXML.LANG_ATT, page.getAttribute(GSXML.LANG_ATT));
    5754    mr_request.setAttribute("resourceType", "core");
    5855    String to = (String)params.get("collection"); // collection name
     
    8279    Document style_doc = converter_.getDOM(new File(stylesheet));
    8380    GSXSLT.absoluteIncludePaths(style_doc, config_);
    84     return transformer_.transform(style_doc, page);   
     81    return (Element)transformer_.transform(style_doc, page);   
    8582
    8683    }
Note: See TracChangeset for help on using the changeset viewer.