Changeset 30670 for main/trunk


Ignore:
Timestamp:
2016-08-04T12:08:33+12:00 (8 years ago)
Author:
kjdon
Message:

can now get displayItem values from a dictionary. for collections, this enables us to more easily get the name and descriptions translated for the demo colls.

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection
Files:
2 edited

Legend:

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

    r30563 r30670  
    3333import org.apache.log4j.Logger;
    3434import org.greenstone.gsdl3.core.ModuleInterface;
     35import org.greenstone.gsdl3.util.CollectionClassLoader;
     36import org.greenstone.gsdl3.util.Dictionary;
    3537import org.greenstone.gsdl3.util.GSFile;
    3638import org.greenstone.gsdl3.util.GSXML;
     
    8385
    8486    protected XMLTransformer transformer = null;
     87    /**
     88     * A class loader that knows about the collection resources directory can
     89     * put properties files, dtds etc in here
     90     */
     91    CollectionClassLoader class_loader = null;
    8592
    8693    /** same as setClusterName */
     
    113120            return false;
    114121        }
     122        // set up the class loader
     123        this.class_loader = new CollectionClassLoader(this.getClass().getClassLoader(), this.site_home, this.cluster_name);
    115124
    116125        macro_resolver.addMacro("_httpcollection_", this.site_http_address + "/collect/" + this.cluster_name);
     
    909918        return response;
    910919    }
     920
     921  // override this to use collection class loader
     922  protected String getTextString(String key, String lang, String dictionary, String[] args)
     923  {
     924    Dictionary dict = new Dictionary(dictionary, lang, this.class_loader);
     925    String result = dict.get(key, args);
     926    if (result == null)
     927      { // not found
     928    //return "_" + key + "_";
     929    return null;
     930      }
     931    return result;
     932  }
     933
    911934}
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/ServiceCluster.java

    r30557 r30670  
    2929import org.greenstone.gsdl3.core.ModuleInterface;
    3030import org.greenstone.gsdl3.service.ServiceRack;
     31import org.greenstone.gsdl3.util.Dictionary;
    3132import org.greenstone.gsdl3.util.GSFile;
    3233import org.greenstone.gsdl3.util.GSPath;
     
    326327            {
    327328                Element d = (Element) displaynodes.item(k);
    328                 String lang = d.getAttribute(GSXML.LANG_ATT);
    329                 if (lang == null || lang.equals(""))
    330                 {
    331                     //set the lang to teh default
    332                     d.setAttribute(GSXML.LANG_ATT, DEFAULT_LANG);
    333                 }
    334329                String name = d.getAttribute(GSXML.NAME_ATT);
    335330                Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, name);
     
    359354  }
    360355
    361     // protected boolean addPlugins(Element plugin_list)
    362     // {
    363     //  if (plugin_list == null)
    364     //      return false;
    365     //  NodeList pluginNodes = plugin_list.getElementsByTagName(GSXML.PLUGIN_ELEM);
    366     //  if (pluginNodes.getLength() > 0)
    367     //  {
    368     //      for (int k = 0; k < pluginNodes.getLength(); k++)
    369     //      {
    370     //          this.plugin_item_list.appendChild(this.doc.importNode(pluginNodes.item(k), true));
    371     //      }
    372     //  }
    373 
    374     //  return true;
    375     // }
    376356    protected boolean resolveMacros(Element display_list)
    377357    {
     
    952932
    953933    }
    954 
    955     protected boolean addAllDisplayInfo(Element description, String lang)
    956     {
    957       Document doc = description.getOwnerDocument();
    958         NodeList items = this.display_item_list.getChildNodes();
    959         for (int i = 0; i < items.getLength(); i++)
    960         { // for each key
    961             Element m = (Element) items.item(i);
    962             // findthe child with the correct language
    963             Element new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang);
    964             if (new_m == null && lang != DEFAULT_LANG)
    965             {
    966                 // use the default lang
    967                 new_m = GSXML.getNamedElement(m, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG);
    968             }
    969             if (new_m == null)
    970             {
    971                 // just get the first one
    972                 new_m = (Element) GSXML.getChildByTagName(m, GSXML.DISPLAY_TEXT_ELEM);
    973             }
    974             description.appendChild(doc.importNode(new_m, true));
    975         }
    976         return true;
    977 
    978     }
    979 
    980     protected Element getDisplayTextElement(String key, String lang)
    981     {
    982 
    983         Element this_item = GSXML.getNamedElement(this.display_item_list, GSXML.DISPLAY_TEXT_ELEM, GSXML.NAME_ATT, key);
    984         if (this_item == null)
    985         {
    986             return null;
    987         }
    988 
    989         Element this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, lang);
    990         if (this_lang == null && lang != DEFAULT_LANG)
    991         {
    992             // try the default
    993             this_lang = GSXML.getNamedElement(this_item, GSXML.DISPLAY_TEXT_ELEM, GSXML.LANG_ATT, DEFAULT_LANG);
    994         }
    995         if (this_lang == null)
    996         {
    997             // just return the first one
    998             return GSXML.getFirstElementChild(this_item);//(Element)this_item.getFirstChild().cloneNode(true);
    999         }
    1000         return (Element) this_lang.cloneNode(true);
    1001 
    1002     }
     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 
    1003989
    1004990    public HashMap<String, ServiceRack> getServiceMap()
Note: See TracChangeset for help on using the changeset viewer.