mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
added method to get I18nMessages from servlet request
This commit is contained in:
@@ -43,6 +43,8 @@ import java.lang.reflect.Field;
|
|||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The I18nMessages class instantiates a class and initializes all {@link String}
|
* The I18nMessages class instantiates a class and initializes all {@link String}
|
||||||
* fields with values from a resource bundle. The resource bundle must have the
|
* fields with values from a resource bundle. The resource bundle must have the
|
||||||
@@ -85,6 +87,22 @@ public final class I18nMessages
|
|||||||
return get(msgClass, Locale.ENGLISH);
|
return get(msgClass, Locale.ENGLISH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Returns a instance of the given message class with all message fields
|
||||||
* initialized.
|
* initialized.
|
||||||
@@ -156,7 +174,7 @@ public final class I18nMessages
|
|||||||
Class msgClass, Object instance)
|
Class msgClass, Object instance)
|
||||||
throws IllegalArgumentException, IllegalAccessException
|
throws IllegalArgumentException, IllegalAccessException
|
||||||
{
|
{
|
||||||
for (Field field : msgClass.getFields())
|
for (Field field : msgClass.getDeclaredFields())
|
||||||
{
|
{
|
||||||
if (field.getType().isAssignableFrom(String.class))
|
if (field.getType().isAssignableFrom(String.class))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user