Changeset 30629 for main/trunk


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

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
2 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);
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r30584 r30629  
    139139    public static final String FROM_ATT = "from";
    140140    public static final String LANG_ATT = "lang";
     141  public static final String KEY_ATT = "key";
    141142    public static final String HREF_ATT = "href";
    142143    public static final String TYPE_ATT = "type";
     
    12611262    return att_value;
    12621263  }
    1263     /**
    1264      * Returns the appropriate language element from a display elem, display is
    1265      * the containing element, name is the name of the element to look for, lang
    1266      * is the preferred language, lang_default is the fall back lang if neither
    1267      * lang is found, will return the first one it finds
    1268      */
    1269     public static String getDisplayText(Element display, String name, String lang, String lang_default)
    1270     {
    1271 
    1272         String def = null;
    1273         String first = null;
    1274         NodeList elems = display.getElementsByTagName(DISPLAY_TEXT_ELEM);
    1275         if (elems.getLength() == 0)
    1276             return "";
    1277         for (int i = 0; i < elems.getLength(); i++)
    1278         {
    1279             Element e = (Element) elems.item(i);
    1280             String n = e.getAttribute(NAME_ATT);
    1281             if (name.equals(n))
    1282             {
    1283                 String l = e.getAttribute(LANG_ATT);
    1284                 if (lang.equals(l))
    1285                 {
    1286                     return getNodeText(e);
    1287                 }
    1288                 else if (lang_default.equals(l))
    1289                 {
    1290                     def = getNodeText(e);
    1291                 }
    1292                 else if (first == null)
    1293                 {
    1294                     first = getNodeText(e);
    1295                 }
    1296             }
    1297             else
    1298             {
    1299                 continue;
    1300             }
    1301         }
    1302 
    1303         if (def != null)
    1304         {
    1305             return def;
    1306         }
    1307         if (first != null)
    1308         {
    1309             return first;
    1310         }
    1311         return "";
    1312     }
    13131264
    13141265    // replaces < > " ' & in the original with their entities
Note: See TracChangeset for help on using the changeset viewer.