Ignore:
Timestamp:
2016-07-28T12:53:59+12:00 (8 years ago)
Author:
kjdon
Message:

moved getDisplayText into ServiceRack from GSXML so that if there is a key specified we can use getTextString to look it up

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/ServiceRack.java

    r30616 r30629  
    447447    }
    448448
     449
     450    /**
     451     * Returns the appropriate language element from a display elem, display is
     452     * the containing element, name is the name of the element to look for, lang
     453     * is the preferred language, lang_default is the fall back lang, if neither
     454     * lang is found will return the first one it finds
     455     */
     456  public String getDisplayText(Element display, String name, String lang, String lang_default) {
     457    return getDisplayText(display, name, lang, lang_default, null);
     458  }
     459
     460  public String getDisplayText(Element display, String name, String lang, String lang_default, String dictionary_name) {
     461   
     462
     463        String def = null;
     464        String first = null;
     465        String key = null;
     466        NodeList elems = display.getElementsByTagName(GSXML.DISPLAY_TEXT_ELEM);
     467        if (elems.getLength() == 0)
     468            return "";
     469        for (int i = 0; i < elems.getLength(); i++)
     470        {
     471            Element e = (Element) elems.item(i);
     472            String n = e.getAttribute(GSXML.NAME_ATT);
     473            if (name.equals(n))
     474            {
     475                String l = e.getAttribute(GSXML.LANG_ATT);
     476                String k = e.getAttribute(GSXML.KEY_ATT);
     477                // if we have a specific lang value, return that
     478                if (!l.equals("") && lang.equals(l))
     479                {
     480                    return GSXML.getNodeText(e);
     481                }
     482                else if (!l.equals("") && lang_default.equals(l))
     483                {
     484                    def = GSXML.getNodeText(e);
     485                }
     486                else if (!k.equals("")) {
     487                  if ( key == null) {
     488                  // a key specified. only allowed one spec with key
     489                    key = k;
     490                  }
     491                }
     492                // we have no key and we don't match the languages
     493                else if (first == null)
     494                {
     495                  // but we are the first one, so we remember the value
     496                    first = GSXML.getNodeText(e);
     497                }
     498            }
     499            else
     500            {
     501                continue;
     502            }
     503        }
     504
     505       
     506        if (key != null) {
     507          String s = getTextString(key, lang, dictionary_name);
     508          // only use this one if a value was actually found
     509          if (!s.equals( "_"+key +"_")) {
     510            return s;
     511          }
     512        }
     513
     514        if (def != null)
     515        {
     516            return def;
     517        }
     518        if (first != null)
     519        {
     520            return first;
     521        }
     522        return "";
     523    }
     524
    449525    /** overloaded version for no args case */
    450526    protected String getTextString(String key, String lang)
     
    478554            if (result == null)
    479555            { // not found
    480                 return "_" + key + "_";
     556              //return "_" + key + "_";
     557              return null;
    481558            }
    482559            return result;
     
    513590          // try the ServiceRack properties
    514591          // at the moment we look for original_class_name.key, then just key
    515           // if there is lots of inheritance, may want to try down the list of superclasses too...
     592          // if there is lots of inheritance, may want to try down the list of superclasses too...?
    516593          class_name = "ServiceRack";
    517594          dict = new Dictionary(class_name, lang, this.class_loader);
Note: See TracChangeset for help on using the changeset viewer.