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

    r4142 r4903  
    7979    protected Document doc_ = null;
    8080
    81     /** XML element for describe requests - list of supported services */
     81    /** XML element for describe requests - list of supported services
     82    - this is static     */
    8283    protected Element short_service_info_ = null;
    8384
    84     /** XML element for describe requests - map of service name to full
    85     description */
    86     protected HashMap service_info_map_ = null;
    8785    /** XML element for stylesheet requests - map of service name to format
    8886    elem */
     
    117115    doc_ = converter_.newDOM();
    118116    short_service_info_ = doc_.createElement(GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
    119     service_info_map_ = new HashMap();
    120117    format_info_map_ = new HashMap();
    121118    }
     
    191188        String to = GSPath.getFirstLink(request.getAttribute(GSXML.TO_ATT));       
    192189        Element response = null;
    193         if (service_info_map_.containsKey(to)) {
    194             try {
     190        try {
    195191            Class c = this.getClass();
    196192            Class []params = {Class.forName("org.w3c.dom.Element")};
    197 
     193           
    198194            String method_name = "process"+to;
    199195            Method m = null;
     
    226222            mainResult.appendChild(doc_.importNode(response, true));
    227223            }
    228                        
    229             } catch (ClassNotFoundException e) {
    230             System.err.println("ServiceRack error: Element class not found");
    231             return null;
    232             }
    233         } else {
    234             // else error in to field
    235             System.err.println("ServiceRack describe request: error in 'to' field, non-existant service "+to+" specified!");
     224           
     225        } catch (ClassNotFoundException e) {
     226            System.err.println("ServiceRack error: Element class not found");
    236227            return null;
    237228        }
     
    242233       
    243234    }
     235
     236 
    244237
    245238    /** process method for describe requests
     
    258251   
    259252    // describe a particular service   
    260     if (service_info_map_.containsKey(to)) {
    261         response.appendChild(getServiceDescription(to, lang));
     253    //if (service_info_map_.containsKey(to)) {
     254    Element description = getServiceDescription(to, lang);
     255    if (description != null) { // may be null if non-existant service
     256        response.appendChild(description);
    262257        response.setAttribute(GSXML.FROM_ATT, to);
    263         return response;
    264258    }
    265     // else error in to field
    266     System.err.println("ServiceRack describe request: error in 'to' field, to='"+to+"'.");
    267     return null;
     259    return response;
    268260   
    269261    }
     
    288280        return response;
    289281    }
    290     // else error in to field
     282    // else no format info
    291283    System.err.println("ServiceRack describe request: no format info for "+to+".");
    292284    return response;
    293285    }   
    294286   
    295     // the following two should be overwritten for info with any language stuff in it
    296287    /** returns the service list for the subclass */
    297288    protected Element getServiceList(String lang) {
    298     // for now, it is static and there is no lang stuff
    299     return short_service_info_;
     289    // for now, it is static and has no language stuff
     290    return (Element) short_service_info_.cloneNode(true);
    300291    }
    301292   
    302293    /** returns a specific service description */
    303     protected Element getServiceDescription(String service, String lang) {
    304     Element descript = (Element)((Element)service_info_map_.get(service)).cloneNode(true);
    305     // for now, create the display element on the fly - look at caching it later
    306     Element display = createServiceDisplay(service, lang);
    307     addServiceDisplay(descript, display);
    308     return descript;
    309     }
    310    
    311    
    312     /** adds the display element into the description - appends to the root for now, but may do something fancy later */
    313     protected boolean addServiceDisplay(Element descript, Element display) {
    314     if (descript.getOwnerDocument() != display.getOwnerDocument()) {
    315         display = (Element)descript.getOwnerDocument().importNode(display, true);
    316     }
    317     descript.appendChild(display);
    318     return true;
    319     }
     294    abstract protected Element getServiceDescription(String service, String lang);
    320295
    321296    protected Element getServiceFormat(String service) {
     
    323298    return format;
    324299    }
    325     /** creates a display element containing all the text strings needed to display the service page, in the language specified */
    326     abstract protected Element createServiceDisplay(String service, String lang);
    327300
    328301    /** overloaded version for no args case */
     
    345318    return result;
    346319    }
     320
     321   
    347322}
     323
Note: See TracChangeset for help on using the changeset viewer.