Changeset 29556


Ignore:
Timestamp:
2014-12-08T14:40:17+13:00 (9 years ago)
Author:
kjdon
Message:

added in a getTextString method - to look up a string from the dictionary. copied from ServiceRack, but without the use of a collection class loader

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/Action.java

    r29092 r29556  
    77import org.apache.log4j.Logger;
    88import org.greenstone.gsdl3.core.ModuleInterface;
     9import org.greenstone.gsdl3.util.Dictionary;
    910import org.greenstone.gsdl3.util.GSConstants;
    1011import org.greenstone.gsdl3.util.GSParams;
     
    314315        return format_elem;
    315316    }
     317
     318    protected String getTextString(String key, String lang, String dictionary, String[] args)
     319    {
     320      logger.error("lang = "+lang);
     321        if (dictionary != null)
     322        {
     323            // just try the one specified dictionary
     324          Dictionary dict = new Dictionary(dictionary, lang);
     325            String result = dict.get(key, args);
     326            if (result == null)
     327            { // not found
     328                return "_" + key + "_";
     329            }
     330            return result;
     331        }
     332
     333        // otherwise we try class names for dictionary names
     334        String class_name = this.getClass().getName();
     335        class_name = class_name.substring(class_name.lastIndexOf('.') + 1);
     336        Dictionary dict = new Dictionary(class_name, lang);
     337        String result = dict.get(key, args);
     338        if (result != null)
     339        {
     340            return result;
     341        }
     342
     343        // we have to try super classes
     344        Class c = this.getClass().getSuperclass();
     345        while (result == null && c != null)
     346        {
     347            class_name = c.getName();
     348            class_name = class_name.substring(class_name.lastIndexOf('.') + 1);
     349            if (class_name.equals("ServiceRack"))
     350            {
     351                // this is as far as we go
     352                break;
     353            }
     354            dict = new Dictionary(class_name, lang);
     355            result = dict.get(key, args);
     356            c = c.getSuperclass();
     357        }
     358        if (result == null)
     359        {
     360            return "_" + key + "_";
     361        }
     362        return result;
     363
     364    }
     365
    316366}
Note: See TracChangeset for help on using the changeset viewer.