Changeset 30839

Show
Ignore:
Timestamp:
22.09.2016 12:08:09 (3 years ago)
Author:
kjdon
Message:

displayItem handling moved to DisplayITemUtil class

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java

    r30670 r30839  
    3030import org.greenstone.gsdl3.service.ServiceRack; 
    3131import org.greenstone.gsdl3.util.Dictionary; 
     32import org.greenstone.gsdl3.util.DisplayItemUtil; 
    3233import org.greenstone.gsdl3.util.GSFile; 
    3334import org.greenstone.gsdl3.util.GSPath; 
     
    8990    /** list of services */ 
    9091    protected Element service_list = null; 
    91     /** list of metadata - all metadata, regardless of language goes in here */ 
     92    /** list of metadata - all metadata, regardless of language goes in here . metadata should be language neutral. Language specific strings are displayItems*/ 
    9293    protected Element metadata_list = null; 
    9394  /** language specific display items */ 
     
    105106 
    106107    protected Element _globalFormat = null; 
     108 
     109    /** 
     110     * A class loader that knows where to find resources  
     111     * put properties files, dtds etc in here 
     112     */ 
     113    protected ClassLoader class_loader = null; 
    107114 
    108115    public void setSiteHome(String home) 
     
    225232        //clearServices(); 
    226233        Element service_rack_list = (Element) GSXML.getChildByTagName(service_cluster_info, GSXML.SERVICE_CLASS_ELEM + GSXML.LIST_MODIFIER); 
    227         logger.error("cluster service rack list ="); 
    228         logger.error(GSXML.xmlNodeToString(service_rack_list)); 
    229234        if (service_rack_list == null) 
    230235        { 
     
    263268        { 
    264269          resolveMacros(display_list); 
    265             if (!addDisplayItems(display_list)) 
     270          if (!DisplayItemUtil.storeDisplayItems(this.display_item_list, display_list)) 
    266271            { 
    267272 
     
    316321      </displayItem> 
    317322  */ 
    318     protected boolean addDisplayItems(Element display_list) 
     323    protected boolean addDisplayItemsOld(Element display_list) 
    319324    { 
    320325 
     
    650655            if (param_list == null) 
    651656            { 
    652                 addAllDisplayInfo(description, lang); 
     657              Element di_list = result_doc.createElement(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER); 
     658              description.appendChild(di_list); 
     659              DisplayItemUtil.addLanguageSpecificDisplayItems(di_list, this.display_item_list, lang, DEFAULT_LANG, this.class_loader); 
    653660                description.appendChild(result_doc.importNode(this.service_list, true)); 
    654661                description.appendChild(result_doc.importNode(this.metadata_list, true)); 
     
    679686                    else if (info.equals(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER)) 
    680687                    { 
    681                         addAllDisplayInfo(description, lang); 
     688                      Element di_list = result_doc.createElement(GSXML.DISPLAY_TEXT_ELEM + GSXML.LIST_MODIFIER); 
     689                      description.appendChild(di_list); 
     690                      DisplayItemUtil.addLanguageSpecificDisplayItems(di_list, this.display_item_list, lang, DEFAULT_LANG, this.class_loader); 
     691 
    682692                    } 
    683693                    else if (info.equals(GSXML.LIBRARY_PARAM_ELEM+GSXML.LIST_MODIFIER)) 
     
    932942 
    933943    } 
    934   // from our store of displayItems, (eg name, description etc) add one of each to response. PIck the best fit for request lang. 
    935  
    936   protected boolean addAllDisplayInfo(Element description, String lang) 
    937   { 
    938     Document doc = description.getOwnerDocument(); 
    939     NodeList items = this.display_item_list.getChildNodes(); 
    940     for (int i = 0; i < items.getLength(); i++) 
    941       { // for each key 
    942     Element m = (Element) items.item(i); 
    943     // is there one with the specified language? 
    944     Element new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang); 
    945     if (new_m == null) { 
    946       // if not, have we got one with a key? 
    947       new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.KEY_ATT, null); 
    948       if (new_m != null) { 
    949         // look up the dictionary 
    950         String value = getTextString(new_m.getAttribute(GSXML.KEY_ATT), lang, new_m.getAttribute(GSXML.DICTIONARY_ATT)); 
    951         if (value != null) { 
    952           GSXML.setNodeText(new_m, value); 
    953         } 
    954         else { 
    955           // haven't found the key in the dictionary, ignore this display item 
    956           new_m = null; 
    957         } 
    958       } 
    959     } 
    960     if (new_m == null && lang != DEFAULT_LANG) { 
    961       // still haven't got a value. can we use the defualt lang? 
    962       new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG); 
    963     } 
    964     if (new_m == null) 
    965       { 
    966         // STILL haven't found one, lets use the first one with a lang att (so we don't just get the key one back 
    967         new_m = (Element) GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, null); 
    968       } 
    969     if (new_m != null) { 
    970       description.appendChild(doc.importNode(new_m, true)); 
    971     } 
    972       } // for each key 
    973     return true; 
    974      
    975   } 
    976    
    977  
    978   protected String getTextString(String key, String lang, String dictionary) { 
    979     return getTextString(key, lang, dictionary, null); 
    980   } 
    981  
    982   protected String getTextString(String key, String lang, String dictionary, String[] args) 
    983   { 
    984     Dictionary dict = new Dictionary(dictionary, lang); 
    985     String result = dict.get(key, args); 
    986     return result; 
    987   } 
    988    
    989944 
    990945    public HashMap<String, ServiceRack> getServiceMap()