Changeset 27049


Ignore:
Timestamp:
2013-03-12T11:57:15+13:00 (11 years ago)
Author:
kjdon
Message:

adding some code for getting gs3 properties files strings. AutoText key for xml is gs3::filename::key, eg gs3::interface_default::home_b. streamlining some code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • documentation/trunk/shared/Dictionary.java

    r27035 r27049  
    2929    private MacroFile aux_macros = null;
    3030    private HashMap metadata = null;
     31  private HashMap gs3_dictionaries = null;
    3132    private Locale locale = null;
    3233    private String lang = null;
     
    3839    static final private int PERLMODULES = 5;
    3940    static final private int METADATA = 6;
     41  static final private int GS3 = 7;
    4042
    4143    protected String gsdl_home = null;
    42     protected String gsdl_or_gsdl3src_home = null;
     44  protected String gsdl_or_gsdl3src_home = null;
     45  protected boolean isGS3 = false;
    4346   
    4447    private ClassLoader classloader = null;
     
    6467    } else {
    6568        gsdl_or_gsdl3src_home = gsdl3_src_home;
     69        isGS3 = true;
    6670    }
    6771
    6872    this.classloader = new MyClassLoader(this.getClass().getClassLoader());
     73
     74    // load up the common dictionaries
     75    glidict = ResourceBundle.getBundle("dictionary", this.locale, this.classloader);
     76    perldict = ResourceBundle.getBundle("strings", this.locale, this.classloader);
     77    metadata = new HashMap();
     78    if (isGS3) {
     79      gs3_dictionaries = new HashMap();
     80     
     81    } else {
     82      core_macros = new MacroFile(MacroFile.CORE);
     83      aux_macros = new MacroFile(MacroFile.AUX);       
     84    }
    6985    }
    7086   
     
    7490    public String get(String key, String args) {
    7591   
    76     boolean isGS3 = false;
    77     String gsdl3_src_home = System.getProperty("GSDL3SRCHOME");
    78     if(gsdl3_src_home != null && !gsdl3_src_home.equals("")) {
    79         File gs3_installation = new File (gsdl3_src_home);
    80         if(gs3_installation.exists()) {
    81             isGS3 = true;
    82         }
    83     }
     92    // boolean isGS3 = false;
     93    // String gsdl3_src_home = System.getProperty("GSDL3SRCHOME");
     94    // if(gsdl3_src_home != null && !gsdl3_src_home.equals("")) {
     95    // File gs3_installation = new File (gsdl3_src_home);
     96    // if(gs3_installation.exists()) {
     97    //      isGS3 = true;
     98    // }
     99    // }
    84100   
    85101    int pos = key.indexOf("::");
     
    92108    //System.err.println("pack = "+package_name+", key="+key_name);
    93109
     110    if (isGS3 && package_name.equals("gs3")) {
     111      pos = key_name.indexOf("::");
     112      if (pos==-1) {
     113        System.err.println("invalid key: "+key+". Should be gs3::properties_filename::key");
     114        return "";
     115      }
     116      String properties_filename = key_name.substring(0, pos);
     117      key_name = key_name.substring(pos+2);
     118      loadGS3Dictionary(properties_filename);
     119      return getGS3DictionaryText(properties_filename, key_name, args);
     120    }
    94121    if (package_name.equals("glidict")) {
    95         loadDictionary(GLIDICT);
     122      //loadDictionary(GLIDICT);
    96123        return getDictionaryText(glidict, key_name, args);
    97124    }
    98125    if (package_name.equals("perlmodules")) {
    99         loadDictionary(PERLMODULES);
     126      //loadDictionary(PERLMODULES);
    100127        return getDictionaryText(perldict, key_name, args);
    101128    }
    102129    if(!isGS3) {
    103130        if (package_name.equals("coredm")) {
    104             loadDictionary(COREDM);
     131          //loadDictionary(COREDM);
    105132            return getMacroText(core_macros, key_name);
    106133        }
    107134        if (package_name.equals("auxdm")) {
    108             loadDictionary(AUXDM);
     135          //loadDictionary(AUXDM);
    109136            return getMacroText(aux_macros, key_name);
    110137        }
     
    175202    }
    176203
     204    public String getGS3DictionaryText(String properties_filename, String key_name, String args) {
     205      ResourceBundle bundle = (ResourceBundle)gs3_dictionaries.get(properties_filename);
     206      return getDictionaryText(bundle, key_name, args);
     207    }
     208
    177209    private String getMacroText(MacroFile macros, String key) {
    178210    return macros.get(key);
     
    228260    case GLIDICT:
    229261        if (this.glidict == null) {
     262          System.err.println("loading glidict dictionary bundle");
    230263        glidict = ResourceBundle.getBundle("dictionary", this.locale, this.classloader);
    231264       
    232         }
     265    } else {
     266      System.err.println("glidict already loaded");
     267    }
    233268        break;
    234269    case PERLMODULES:
     
    253288    }
    254289   
     290    private boolean loadGS3Dictionary(String properties_filename) {
     291
     292      System.err.println("****loading dictionary "+properties_filename);
     293      if (gs3_dictionaries.containsKey(properties_filename)) {
     294    System.err.println("gs3 dict "+properties_filename+" already loaded");
     295    return true; // already loaded
     296      }
     297   
     298      ResourceBundle bundle = ResourceBundle.getBundle(properties_filename, this.locale, this.classloader);
     299      if (bundle != null) {
     300    gs3_dictionaries.put(properties_filename, bundle);
     301    return true;
     302      }
     303      System.err.println("couldn't load gs3 dict "+properties_filename);
     304      return false;
     305     
     306    }
     307
    255308    private boolean loadMetadata(String namespace) {
    256     if (metadata == null) {
    257         metadata = new HashMap();
    258     }
    259309
    260310    if (metadata.containsKey(namespace)) {
     
    308358    private String gliclassesdir = null;
    309359    private String perldir = null;
     360      private String gs3classesdir = null;
    310361
    311362    public MyClassLoader(ClassLoader parent) {
     
    314365        gliclassesdir = gsdl_or_gsdl3src_home+File.separator+"gli"+File.separator+"classes";
    315366        perldir = gsdl_home+File.separator+"perllib";
    316        
     367        if (isGS3) {
     368          gs3classesdir = gsdl_or_gsdl3src_home+File.separator+"web"+File.separator+"WEB-INF"+File.separator+"classes";
     369        }
    317370    }
    318371
    319372    public URL findResource(String name) {
     373     
    320374        try {
    321375        File resource_path = new File(this.gliclassesdir, name);
     
    326380        if (resource_path.exists()) {
    327381            return new URL("file://"+resource_path.getAbsolutePath());
     382        }
     383        if (isGS3) {
     384          resource_path = new File(this.gs3classesdir, name);
     385          if (resource_path.exists()) {
     386            return new URL("file://"+resource_path.getAbsolutePath());
     387          }
    328388        }
    329389        } catch (Exception e) {};
Note: See TracChangeset for help on using the changeset viewer.