Changeset 27049
- Timestamp:
- 2013-03-12T11:57:15+13:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
documentation/trunk/shared/Dictionary.java
r27035 r27049 29 29 private MacroFile aux_macros = null; 30 30 private HashMap metadata = null; 31 private HashMap gs3_dictionaries = null; 31 32 private Locale locale = null; 32 33 private String lang = null; … … 38 39 static final private int PERLMODULES = 5; 39 40 static final private int METADATA = 6; 41 static final private int GS3 = 7; 40 42 41 43 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; 43 46 44 47 private ClassLoader classloader = null; … … 64 67 } else { 65 68 gsdl_or_gsdl3src_home = gsdl3_src_home; 69 isGS3 = true; 66 70 } 67 71 68 72 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 } 69 85 } 70 86 … … 74 90 public String get(String key, String args) { 75 91 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 // } 84 100 85 101 int pos = key.indexOf("::"); … … 92 108 //System.err.println("pack = "+package_name+", key="+key_name); 93 109 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 } 94 121 if (package_name.equals("glidict")) { 95 122 //loadDictionary(GLIDICT); 96 123 return getDictionaryText(glidict, key_name, args); 97 124 } 98 125 if (package_name.equals("perlmodules")) { 99 126 //loadDictionary(PERLMODULES); 100 127 return getDictionaryText(perldict, key_name, args); 101 128 } 102 129 if(!isGS3) { 103 130 if (package_name.equals("coredm")) { 104 131 //loadDictionary(COREDM); 105 132 return getMacroText(core_macros, key_name); 106 133 } 107 134 if (package_name.equals("auxdm")) { 108 135 //loadDictionary(AUXDM); 109 136 return getMacroText(aux_macros, key_name); 110 137 } … … 175 202 } 176 203 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 177 209 private String getMacroText(MacroFile macros, String key) { 178 210 return macros.get(key); … … 228 260 case GLIDICT: 229 261 if (this.glidict == null) { 262 System.err.println("loading glidict dictionary bundle"); 230 263 glidict = ResourceBundle.getBundle("dictionary", this.locale, this.classloader); 231 264 232 } 265 } else { 266 System.err.println("glidict already loaded"); 267 } 233 268 break; 234 269 case PERLMODULES: … … 253 288 } 254 289 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 255 308 private boolean loadMetadata(String namespace) { 256 if (metadata == null) {257 metadata = new HashMap();258 }259 309 260 310 if (metadata.containsKey(namespace)) { … … 308 358 private String gliclassesdir = null; 309 359 private String perldir = null; 360 private String gs3classesdir = null; 310 361 311 362 public MyClassLoader(ClassLoader parent) { … … 314 365 gliclassesdir = gsdl_or_gsdl3src_home+File.separator+"gli"+File.separator+"classes"; 315 366 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 } 317 370 } 318 371 319 372 public URL findResource(String name) { 373 320 374 try { 321 375 File resource_path = new File(this.gliclassesdir, name); … … 326 380 if (resource_path.exists()) { 327 381 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 } 328 388 } 329 389 } catch (Exception e) {};
Note:
See TracChangeset
for help on using the changeset viewer.