Ignore:
Timestamp:
2003-07-11T16:29:16+12:00 (21 years ago)
Author:
kjdon
Message:

tidied up a lot of stuff, particularly the display text stuff, including how its formatted, and some of the service rack methods

File:
1 edited

Legend:

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

    r4861 r4903  
    7575
    7676    protected GDBMWrapper gdbm_src_ = null;
    77    
    7877    protected Element config_info_ = null; // the xml from the config file
    7978
     
    106105    dcr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE);
    107106    short_service_info_.appendChild(dcr_service);
    108 
    109     // set up service_info_map_ - for now, just has the same elements as above
    110     // should have full details about each service incl params lists etc.
    111     service_info_map_.put(DOCUMENT_STRUCTURE_RETRIEVE_SERVICE, dsr_service);
    112     service_info_map_.put(DOCUMENT_METADATA_RETRIEVE_SERVICE, dmr_service);
    113     service_info_map_.put(DOCUMENT_CONTENT_RETRIEVE_SERVICE, dcr_service);
    114107
    115108    // Open GDBM database for querying
     
    146139        short_service_info_.appendChild(cbmr_service);
    147140
    148         // service_info_map_
    149 
    150     // the metadata one has the same info for now  - should this advertise what metadata is available??
    151     Element cbmr_service_info = (Element) cbmr_service.cloneNode(true);
    152     service_info_map_.put(CLASSIFIER_METADATA_SERVICE, cbmr_service_info);
    153 
    154     //the browse one
    155     Element cb_service_info = (Element)cb_service.cloneNode(true);
    156     Element cl_list = doc_.createElement(GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
    157     cb_service_info.appendChild(cl_list);
    158    
    159141    // the format info
    160142    Element cb_format_info = doc_.createElement(GSXML.FORMAT_ELEM);
     
    166148        Element new_cl = (Element)doc_.importNode(cl, false); // just import this node, not the children
    167149       
    168         cl_list.appendChild(new_cl);
    169 
    170150        // get the format info out, and put inside a classifier element
    171151        Element format_cl = (Element)new_cl.cloneNode(false);
     
    185165    }
    186166       
    187    
    188     service_info_map_.put(CLASSIFIER_SERVICE, cb_service_info);
    189167    if (format_found) {
    190168        format_info_map_.put(CLASSIFIER_SERVICE, cb_format_info);
     
    201179    return true;
    202180    }
    203    
     181
     182    protected Element getServiceDescription(String service_id, String lang) {
     183
     184    if (service_id.equals(CLASSIFIER_SERVICE)) {
     185       
     186        Element class_list = (Element)GSXML.getChildByTagName(config_info_, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
     187        if (class_list == null) {
     188            // no classifiers specified
     189        return null;
     190        }
     191       
     192        Element cb_service = doc_.createElement(GSXML.SERVICE_ELEM);
     193        cb_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_BROWSE);
     194        cb_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE);
     195        cb_service.appendChild(GSXML.createDisplayTextElement(doc_, GSXML.DISPLAY_TEXT_NAME,  getTextString(CLASSIFIER_SERVICE+".name", lang)));
     196       
     197        Element cl_list = doc_.createElement(GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
     198        cb_service.appendChild(cl_list);
     199        NodeList classifiers = class_list.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
     200        for(int i=0; i<classifiers.getLength(); i++) {
     201        Element cl = (Element)classifiers.item(i);
     202        Element new_cl = (Element)doc_.importNode(cl, false); // just import this node, not the children
     203       
     204        cl_list.appendChild(new_cl);
     205        String text = GSXML.getDisplayText(cl,
     206                        GSXML.DISPLAY_TEXT_NAME,
     207                        lang, "en");
     208        if (text == null || text.equals("")) {
     209            // no display element was specified, use the metadata name
     210            // for now this looks in the class properties file
     211            // this needs to use a general metadata thing instead
     212            text = getTextString(cl.getAttribute(GSXML.CLASSIFIER_CONTENT_ATT), lang);
     213        }
     214       
     215        Element cl_name = GSXML.createDisplayTextElement(doc_, GSXML.DISPLAY_TEXT_NAME, text);
     216        new_cl.appendChild(cl_name);
     217       
     218        }
     219        return cb_service;
     220    }
     221   
     222    // these ones are probably never called, but put them here just in case
     223   
     224    if (service_id.equals(CLASSIFIER_METADATA_SERVICE)) {
     225       
     226        Element cbmr_service = doc_.createElement(GSXML.SERVICE_ELEM);
     227        cbmr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
     228        cbmr_service.setAttribute(GSXML.NAME_ATT, CLASSIFIER_METADATA_SERVICE);
     229        return cbmr_service;
     230    }
     231
     232    if (service_id.equals(DOCUMENT_STRUCTURE_RETRIEVE_SERVICE)) {
     233        Element dsr_service = doc_.createElement(GSXML.SERVICE_ELEM);
     234        dsr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
     235        dsr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_STRUCTURE_RETRIEVE_SERVICE);
     236        return dsr_service;
     237    }
     238    if (service_id.equals(DOCUMENT_METADATA_RETRIEVE_SERVICE)) {
     239        Element dmr_service = doc_.createElement(GSXML.SERVICE_ELEM);
     240        dmr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
     241        dmr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_METADATA_RETRIEVE_SERVICE);
     242        return dmr_service;
     243    }
     244
     245    if (service_id.equals(DOCUMENT_CONTENT_RETRIEVE_SERVICE)) {
     246        Element dcr_service = doc_.createElement(GSXML.SERVICE_ELEM);
     247        dcr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
     248        dcr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE);
     249        return dcr_service;
     250    }
     251
     252    return null;
     253    }
     254
    204255    /** this looks for any classifier specific display or format info from extra_info and adds it in to the correct place in info */
    205256    protected boolean extractExtraClassifierInfo(Element info, Element extra_info) {
     
    227278       
    228279        // get the display elements if any - displayName
    229         NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAYNAME_ELEM);
     280        NodeList display_names = node_extra.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
    230281        if (display_names !=null) {
    231282        Element display = owner.createElement(GSXML.DISPLAY_ELEM);
    232283        for (int j=0; j<display_names.getLength(); j++) {
    233284            Element e = (Element)display_names.item(j);
     285            cl.appendChild(owner.importNode(e, true));
    234286           
    235             Element display_name = GSXML.createTextElement(owner, GSXML.DISPLAY_NAME_ELEM, GSXML.getNodeText(e));
    236             display_name.setAttribute(GSXML.LANG_ATT, e.getAttribute(GSXML.LANG_ATT));
    237             display.appendChild(display_name);
    238         }
    239         cl.appendChild(display);
     287        }
    240288        }
    241289       
     
    253301    }
    254302       
    255 
    256     /** creates a display element containing all the text strings needed to display the service page, in the language specified
    257      * the retrieval services dont get displayed to the users - they are only used internally by the actions. so this returns an empty display element
    258      * for those services. CLASSIFIER_BROWSE service returns some info */
    259     protected Element createServiceDisplay(String service, String lang)
    260     {
    261     Element display = doc_.createElement(GSXML.DISPLAY_ELEM);
    262     if (!service.equals(CLASSIFIER_SERVICE)) {
    263         return display;
    264     }
    265 
    266     // CLASSIFIER_SERVICE
    267     display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_NAME_ELEM,  getTextString(service+".name", lang)));
    268     //display.appendChild(GSXML.createTextElement(doc_,  GSXML.DISPLAY_SUBMIT_ELEM, getTextString(service+".submit", lang)));
    269    
    270     // need to add in the classifier name info
    271     // add <classifier name="CL1">text name</classifier> to the
    272     // display node
    273     NodeList classifiers = config_info_.getElementsByTagName(GSXML.CLASSIFIER_ELEM);
    274     for (int i=0; i<classifiers.getLength(); i++) {
    275         Element cl = (Element)classifiers.item(i);
    276         Element disp = (Element)GSXML.getChildByTagName(cl, GSXML.DISPLAY_ELEM);
    277         String text = null;
    278         if (disp !=null) {
    279         text = GSXML.getDisplayText(disp,
    280                         GSXML.DISPLAY_NAME_ELEM,
    281                         lang, "en");
    282         }
    283         if (text == null || text.equals("")) {
    284         // no display element was specified, use the metadata name
    285         // for now this looks in the class properties file
    286         // this needs to use a general metadata thing instead
    287         text = getTextString(cl.getAttribute(GSXML.CLASSIFIER_CONTENT_ATT), lang);
    288         }
    289        
    290         Element cl_elem = doc_.createElement(GSXML.CLASSIFIER_ELEM);
    291         cl_elem.setAttribute(GSXML.NAME_ATT, cl.getAttribute(GSXML.NAME_ATT));
    292         Element cl_name = GSXML.createTextElement(doc_, GSXML.DISPLAY_NAME_ELEM, text);
    293         cl_elem.appendChild(cl_name);
    294        
    295         display.appendChild(cl_elem);
    296        
    297     }
    298    
    299     return display;
    300    
    301     }
    302303
    303304    /** parent is true if this node is definitely the  parent of something,
Note: See TracChangeset for help on using the changeset viewer.