1 18 package org.apache.beehive.netui.databinding.datagrid.runtime.config; 19 20 import java.util.ResourceBundle ; 21 import java.util.HashMap ; 22 import java.util.Enumeration ; 23 import java.text.MessageFormat ; 24 25 import org.apache.beehive.netui.databinding.datagrid.api.DataGridResourceProvider; 26 27 40 class DefaultDataGridResourceProvider 41 extends DataGridResourceProvider { 42 43 private static final Object VALUE_PLACEHOLDER = new Object (); 44 private static final String DEFAULT_RESOURCE_BUNDLE = "org.apache.beehive.netui.databinding.datagrid.runtime.util.data-grid-default"; 45 46 private ResourceBundle _defaultResourceBundle = null; 47 private ResourceBundle _resourceBundle = null; 48 private HashMap _resourceBundleKeys = null; 49 50 54 DefaultDataGridResourceProvider() { 55 } 56 57 64 public String getMessage(String key) { 65 return internalGetMessage(key); 66 } 67 68 74 public String formatMessage(String key, Object [] args) { 75 String msg = internalFormatMessage(getMessage(key), args); 76 return msg; 77 } 78 79 86 private final String internalGetMessage(String key) { 87 if(getResourceBundlePath() == null) 88 return getDefaultMessage(key); 89 else { 90 91 if(_resourceBundle == null) { 92 _resourceBundle = createResourceBundle(getResourceBundlePath()); 93 } 94 95 if(isEnableChaining() && _resourceBundleKeys == null) { 96 Enumeration e = _resourceBundle.getKeys(); 97 while(e.hasMoreElements()) 98 _resourceBundleKeys.put(e.nextElement(), VALUE_PLACEHOLDER); 99 } 100 101 if(!isEnableChaining() || _resourceBundleKeys.containsKey(key)) 102 return _resourceBundle.getString(key); 103 else 104 return _defaultResourceBundle.getString(key); 105 } 106 } 107 108 113 private String getDefaultMessage(String key) { 114 if(_defaultResourceBundle == null) 115 _defaultResourceBundle = createResourceBundle(DEFAULT_RESOURCE_BUNDLE); 116 return _defaultResourceBundle.getString(key); 117 } 118 119 } 120 | Popular Tags |