Changeset 3938


Ignore:
Timestamp:
2003-03-20T13:51:14+12:00 (21 years ago)
Author:
kjdon
Message:

configure takes two args - the xml for teh service plus some optional stuff - eg teh collection configuration file - its up to teh service now to extract what it needs. the query services need the index specific display elements and a general format element, the classifier services need classifier specific display and format stuff.

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/service
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPRetrieve.java

    r3901 r3938  
    5757
    5858    /** configure this service */
    59     public boolean configure(Element info)
     59    public boolean configure(Element info, Element extra_info)
    6060    {
    6161    // Do specific configuration
     
    7474
    7575    // Do generic configuration
    76     return super.configure(info);
     76    return super.configure(info, extra_info);
    7777    }
    7878
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java

    r3868 r3938  
    8585   
    8686    /** configure this service */
    87     public boolean configure(Element info)
     87    public boolean configure(Element info, Element extra_info)
    8888    {
    8989    // Do generic configuration
    90     if (super.configure(info) == false)
     90    if (super.configure(info, extra_info) == false)
    9191        return false;
    92 
     92   
    9393    // Do specific configuration
    9494    System.out.println("Configuring GS2MGPPSearch...");
     
    147147    service_info_map_.put(ADVANCED_FIELD_QUERY_SERVICE, afq_service_full);
    148148
     149
     150    //set up format info - the info is the same as that for text query
     151    Element format_info = (Element)format_info_map_.get(TEXT_QUERY_SERVICE);
     152    if (format_info != null) {
     153        format_info_map_.put(FIELD_QUERY_SERVICE, format_info);
     154        format_info_map_.put(ADVANCED_FIELD_QUERY_SERVICE, format_info);
     155    }
    149156    return true;
    150157    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java

    r3901 r3938  
    5959
    6060    /** configure this service */
    61     public boolean configure(Element info)
     61    public boolean configure(Element info, Element extra_info)
    6262    {
    6363    // Do specific configuration
     
    7676
    7777    // Do generic configuration
    78     return super.configure(info);
     78    return super.configure(info, extra_info);
    7979    }
    8080
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Retrieve.java

    r3910 r3938  
    2525
    2626// XML classes
     27import org.w3c.dom.Document;
    2728import org.w3c.dom.Element;
    2829import org.w3c.dom.NodeList;
     
    7071
    7172    /** configure this service */
    72     public boolean configure(Element info)
     73    public boolean configure(Element info, Element extra_info)
    7374    {
    7475    System.out.println("Configuring GS2Retrieve...");
     
    113114        }
    114115   
     116    // get the display and format elements from the coll config file for
     117    // the classifiers
     118    extractExtraClassifierInfo(info, extra_info);
     119    config_info_ = info;
     120   
    115121        // short_service_info_ - the browse one
    116122        Element cb_service = doc_.createElement(GSXML.SERVICE_ELEM);
     
    137143   
    138144    // the format info
    139     Element cb_format_info = doc_.createElement(GSXML.STYLESHEET_ELEM);
     145    Element cb_format_info = doc_.createElement(GSXML.FORMAT_ELEM);
    140146    boolean format_found = false;
    141147    // add in to the description a simplified list of classifiers
     
    172178    }
    173179   
     180    /** this looks for any classifier specific display or format info from extra_info and adds it in to the correct place in info */
     181    protected boolean extractExtraClassifierInfo(Element info, Element extra_info) {
     182   
     183    if (extra_info == null) {
     184        return false;
     185    }
     186   
     187    Document owner = info.getOwnerDocument();
     188    // so far we have display and format elements that we need for classifiers
     189    NodeList classifiers = info.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
     190    Element config_browse = (Element)GSXML.getChildByTagName(extra_info, GSXML.BROWSE_ELEM);
     191
     192    for (int i=0; i<classifiers.getLength();i++) {
     193        Element cl = (Element)classifiers.item(i);
     194        String name = cl.getAttribute(GSXML.NAME_ATT);
     195        Element node_extra = GSXML.getNamedElement(config_browse,
     196                               GSXML.CLASSIFIER_ELEM,
     197                               GSXML.NAME_ATT,
     198                               name);
     199        if (node_extra == null) {
     200        System.out.println("haven't found extra info for classifier named "+name);
     201        continue;
     202        }
     203       
     204        // get the display elements if any - displayName
     205        NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAYNAME_ELEM);
     206        if (display_names !=null) {
     207        Element display = owner.createElement(GSXML.DISPLAY_ELEM);
     208        for (int j=0; j<display_names.getLength(); j++) {
     209            Element e = (Element)display_names.item(j);
     210           
     211            Element display_name = GSXML.createTextElement(owner, GSXML.DISPLAY_NAME_ELEM, GSXML.getNodeText(e));
     212            display_name.setAttribute(GSXML.LANG_ATT, e.getAttribute(GSXML.LANG_ATT));
     213            display.appendChild(display_name);
     214        }
     215        cl.appendChild(display);
     216        }
     217       
     218        // get the format element if any
     219        Element format = (Element)GSXML.getChildByTagName(node_extra, GSXML.FORMAT_ELEM);
     220        if (format==null) { // try a generic one that applies to all classifiers
     221        format = (Element)GSXML.getChildByTagName(extra_info,
     222                              GSXML.FORMAT_ELEM);
     223        }
     224        if (format!=null) { // append to index info
     225        cl.appendChild(owner.importNode(format, true));
     226        }
     227    } // for each classifier
     228    return true;
     229    }
     230       
    174231
    175232    /** creates a display element containing all the text strings needed to display the service page, in the language specified
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Search.java

    r3862 r3938  
    2626// XML classes
    2727import org.w3c.dom.Element;
     28import org.w3c.dom.Document;
    2829import org.w3c.dom.NodeList;
    2930
     
    8283
    8384    /** configure this service */
    84     public boolean configure(Element info)
     85    public boolean configure(Element info, Element extra_info)
    8586    {
    8687    System.out.println("Configuring GS2Search...");
     88    addExtraQueryInfo(info, extra_info);
    8789    config_info_ = info;
    8890
     
    119121    }
    120122
     123    // add some format info to service map if there is any
     124    Element format = (Element) GSXML.getChildByTagName(info, GSXML.FORMAT_ELEM);
     125    if (format != null) {
     126        format_info_map_.put(TEXT_QUERY_SERVICE, doc_.importNode(format, true));
     127    }
     128       
    121129    return true;
    122130    }
    123131
    124132
    125     /** creates a new param element and adds it to the param list */
     133    protected boolean addExtraQueryInfo(Element info, Element extra_info){
     134
     135    if (extra_info == null) {
     136        return false;
     137    }
     138   
     139    Document owner = info.getOwnerDocument();
     140    // so far we have index specific display elements, and global format elements
     141    NodeList indexes = info.getElementsByTagName(GSXML.INDEX_ELEM);
     142    Element config_search = (Element)GSXML.getChildByTagName(extra_info, GSXML.SEARCH_ELEM);
     143   
     144    for (int i=0; i<indexes.getLength();i++) {
     145        Element ind = (Element)indexes.item(i);
     146        String name = ind.getAttribute(GSXML.NAME_ATT);
     147        Element node_extra = GSXML.getNamedElement(config_search,
     148                               GSXML.INDEX_ELEM,
     149                               GSXML.NAME_ATT,
     150                               name);
     151        if (node_extra == null) {
     152        System.out.println("haven't found extra info for index named "+name);
     153        continue;
     154        }
     155       
     156        // get the display elements if any - displayName
     157        NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAYNAME_ELEM);
     158        if (display_names !=null) {
     159        Element display = owner.createElement(GSXML.DISPLAY_ELEM);
     160        for (int j=0; j<display_names.getLength(); j++) {
     161            Element e = (Element)display_names.item(j);
     162           
     163            Element display_name = GSXML.createTextElement(owner, GSXML.DISPLAY_NAME_ELEM, GSXML.getNodeText(e));
     164            display_name.setAttribute(GSXML.LANG_ATT, e.getAttribute(GSXML.LANG_ATT));
     165            display.appendChild(display_name);
     166        }
     167        ind.appendChild(display);
     168        }
     169    } // for each index
     170   
     171    // get the format element if any
     172    Element format = (Element)GSXML.getChildByTagName(extra_info,
     173                              GSXML.FORMAT_ELEM);
     174    if (format!=null) { // append to  info
     175        info.appendChild(owner.importNode(format, true));
     176    }
     177    return true;
     178
     179
     180    }
     181/** creates a new param element and adds it to the param list */
    126182    protected void createParameter(String name, Element param_list,
    127183                   boolean display, String lang)
Note: See TracChangeset for help on using the changeset viewer.