コード例 #1
0
ファイル: MessageText.java プロジェクト: aprasa/oldwork
  private static String getResourceBundleString(String key) {
    if (key == null) {
      return "";
    }

    String value = RESOURCE_BUNDLE.getString(key);

    // Replace {*} with a lookup of *
    if (value != null && value.indexOf('}') > 0) {
      Matcher matcher = PAT_PARAM_ALPHA.matcher(value);
      while (matcher.find()) {
        key = matcher.group(1);
        try {
          String text = getResourceBundleString(key);
          if (text != null) {
            value = value.replaceAll("\\Q{" + key + "}\\E", text);
          }
        } catch (MissingResourceException e) {
          // ignore error
        }
      }
    }

    return value;
  }
コード例 #2
0
ファイル: MessageText.java プロジェクト: aprasa/oldwork
 public static boolean keyExistsForDefaultLocale(final String key) {
   try {
     DEFAULT_BUNDLE.getString(key);
     return true;
   } catch (MissingResourceException e) {
     return false;
   }
 }
コード例 #3
0
ファイル: MessageText.java プロジェクト: aprasa/oldwork
  public static boolean integratePluginMessages(ResourceBundle bundle) {
    synchronized (pluginResourceBundles) {
      pluginResourceBundles.add(bundle);
    }

    RESOURCE_BUNDLE.addResourceMessages(bundle);
    setResourceBundle(RESOURCE_BUNDLE);

    return true;
  }
コード例 #4
0
ファイル: MessageText.java プロジェクト: aprasa/oldwork
 public static String getDefaultLocaleString(String key) {
   // TODO Auto-generated method stub
   try {
     return DEFAULT_BUNDLE.getString(key);
   } catch (MissingResourceException e) {
     // we support the usage of non-resource strings as long as they are wrapped in !
     if (key.startsWith("!") && key.endsWith("!")) {
       return (key.substring(1, key.length() - 1));
     }
     return '!' + key + '!';
   }
 }
コード例 #5
0
ファイル: MessageText.java プロジェクト: aprasa/oldwork
  // TODO: This is slow. For every call, IntegratedResourceBundle creates
  //       a hashtables and fills it with the old resourceBundle, then adds
  //       the new one, and then puts it all back into a ListResourceBundle.
  //       As we get more plugins, the time to add a new plugin's language file
  //       increases dramatically (even if the language file only has 1 entry!)
  //       Fix this by:
  //         - Create only one IntegratedResourceBundle
  //         - extending ResourceBundle
  //         - override handleGetObject, store in hashtable
  //         - function to add another ResourceBundle, adds to hashtable
  public static boolean integratePluginMessages(String localizationPath, ClassLoader classLoader) {
    boolean integratedSuccessfully = false;
    if (null != localizationPath
        && localizationPath.length() != 0
        && !pluginLocalizationPaths.containsKey(localizationPath)) {
      synchronized (pluginLocalizationPaths) {
        pluginLocalizationPaths.put(localizationPath, classLoader);
      }

      RESOURCE_BUNDLE.addPluginBundle(localizationPath, classLoader);
      setResourceBundle(RESOURCE_BUNDLE);

      integratedSuccessfully = true;
    }
    return integratedSuccessfully;
  }
コード例 #6
0
ファイル: MessageText.java プロジェクト: aprasa/oldwork
  private static void setResourceBundle(IntegratedResourceBundle bundle) {
    RESOURCE_BUNDLE = bundle;

    Iterator keys = RESOURCE_BUNDLE.getKeysLight();

    String platform_suffix = getPlatformSuffix();

    Set platformKeys = new HashSet();

    while (keys.hasNext()) {
      String key = (String) keys.next();
      if (key.endsWith(platform_suffix)) platformKeys.add(key);
    }

    platform_specific_keys = platformKeys;
  }