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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.