private String getLocalizedString(String string, String type, String defaultValue) {
   if (Property.DEFAULT_LOCAL_STRING.equals(string)) {
     Method getter = getGetter();
     String propertyName = BeanUtils.getPropertyNameFromGetter(getter.getName());
     Class<?> propOwner = getter.getDeclaringClass();
     Bundle bundle = FrameworkUtil.getBundle(propOwner);
     ResourceBundle resourceBundle = Platform.getResourceBundle(bundle);
     String messageID = "meta." + propOwner.getName() + "." + propertyName + "." + type;
     String result = null;
     try {
       result = resourceBundle.getString(messageID);
     } catch (Exception e) {
       // Try to find the same property in parent classes
       for (Class parent = getter.getDeclaringClass().getSuperclass();
           parent != null && parent != Object.class;
           parent = parent.getSuperclass()) {
         try {
           Method parentGetter = parent.getMethod(getter.getName(), getter.getParameterTypes());
           Class<?> parentOwner = parentGetter.getDeclaringClass();
           Bundle parentBundle = FrameworkUtil.getBundle(parentOwner);
           if (parentBundle == null || parentBundle == bundle) {
             continue;
           }
           ResourceBundle parentResourceBundle = Platform.getResourceBundle(parentBundle);
           messageID = "meta." + parentOwner.getName() + "." + propertyName + "." + type;
           try {
             result = parentResourceBundle.getString(messageID);
             break;
           } catch (Exception e1) {
             // Just skip it
           }
         } catch (NoSuchMethodException e1) {
           // Just skip it
         }
       }
       if (result == null) {
         if (type.equals(Property.RESOURCE_TYPE_NAME)) {
           log.debug(
               "Resource '" + messageID + "' not found in bundle " + bundle.getSymbolicName());
         }
         return defaultValue;
       }
     }
     if (!result.equals(messageID)) {
       return result;
     }
     return defaultValue;
   }
   return string;
 }
Exemplo n.º 2
0
  /** Returns the string from the plugin's resource bundle, or 'key' if not found. */
  public static String getResourceString(String key) {
    ResourceBundle bundle = Platform.getResourceBundle(getDefault().getBundle());

    try {
      return (bundle != null) ? bundle.getString(key) : key;
    } catch (MissingResourceException e) {
      return key;
    }
  }
Exemplo n.º 3
0
 /** This method is called upon plug-in activation */
 public void start(BundleContext context) throws Exception {
   super.start(context);
   resourceBundle = Platform.getResourceBundle(getBundle());
   Defaults.applyDefaults(getPreferenceStore());
   javaDomain = new JavaSettings(getPreferenceStore());
 }
 /**
  * Returns this plug-in's resource bundle.
  *
  * @return the plugin's resource bundle
  */
 public ResourceBundle getResourceBundle() {
   if (fResourceBundle == null) fResourceBundle = Platform.getResourceBundle(getBundle());
   return fResourceBundle;
 }
Exemplo n.º 5
0
 protected ResourceBundle getPluginResourceBundle() {
   Bundle bundle = Platform.getBundle(Activator.getPluginId());
   return Platform.getResourceBundle(bundle);
 }
 protected ResourceBundle getPluginResourceBundle() {
   return Platform.getResourceBundle(Activator.getDefault().getBundle());
 }