Commits

Sebastian Sdorra committed 8cd6307

added method to get I18nMessages from servlet request

Comments (0)

Files changed (1)

scm-core/src/main/java/sonia/scm/i18n/I18nMessages.java

 
 import java.util.Locale;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * The I18nMessages class instantiates a class and initializes all {@link String}
  * fields with values from a resource bundle. The resource bundle must have the
   }
 
   /**
+   * Same as {@link #get(java.lang.Class, java.util.Locale)}, with locale
+   * from servlet request ({@link HttpServletRequest#getLocale()}).
+   *
+   *
+   * @param msgClass message class
+   * @param request servlet request
+   * @param <T> type of message class
+   *
+   * @return
+   */
+  public static <T> T get(Class<T> msgClass, HttpServletRequest request)
+  {
+    return get(msgClass, request.getLocale());
+  }
+
+  /**
    * Returns a instance of the given message class with all message fields
    * initialized.
    *
     Class msgClass, Object instance)
     throws IllegalArgumentException, IllegalAccessException
   {
-    for (Field field : msgClass.getFields())
+    for (Field field : msgClass.getDeclaredFields())
     {
       if (field.getType().isAssignableFrom(String.class))
       {