Remove unused package.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / i18n / LocaleUtils.java
index e422e21fea8212608520fd7d935d4288522d973a..71a31413efb6086330020b1b7d5a92ee63753aa2 100644 (file)
 package org.argeo.cms.i18n;
 
+import java.util.List;
 import java.util.Locale;
-import java.util.ResourceBundle;
 
-import org.argeo.eclipse.ui.specific.UiContext;
+import org.argeo.cms.auth.CurrentUser;
 
-/** Utilities simplifying the development of localization enums. */
+/**
+ * Utilities simplifying the development of localization enums.
+ * 
+ * @deprecated Use {@link org.argeo.cms.LocaleUtils}
+ */
+@Deprecated
 public class LocaleUtils {
        public static Object local(Enum<?> en) {
-               return local(en, getCurrentLocale(), "/OSGI-INF/l10n/bundle");
+               return org.argeo.cms.LocaleUtils.local(en);
        }
 
        public static Object local(Enum<?> en, Locale locale) {
-               return local(en, locale, "/OSGI-INF/l10n/bundle");
+               return org.argeo.cms.LocaleUtils.local(en, locale);
        }
 
        public static Object local(Enum<?> en, Locale locale, String resource) {
-               return local(en, locale, resource, en.getClass().getClassLoader());
+               return org.argeo.cms.LocaleUtils.local(en, locale, resource);
        }
 
-       public static Object local(Enum<?> en, Locale locale, String resource,
-                       ClassLoader classLoader) {
-               ResourceBundle rb = ResourceBundle.getBundle(resource, locale,
-                               classLoader);
-               return rb.getString(en.name());
+       public static Object local(Enum<?> en, Locale locale, String resource, ClassLoader classLoader) {
+               return org.argeo.cms.LocaleUtils.local(en, locale, resource, classLoader);
        }
 
        public static String lead(String raw, Locale locale) {
-               return raw.substring(0, 1).toUpperCase(locale) + raw.substring(1);
+               return org.argeo.cms.LocaleUtils.lead(raw, locale);
        }
 
        public static String lead(Localized localized) {
-               return lead(localized, getCurrentLocale());
+               return org.argeo.cms.LocaleUtils.lead(localized);
        }
 
        public static String lead(Localized localized, Locale locale) {
-               return lead(localized.local(locale).toString(), locale);
+               return org.argeo.cms.LocaleUtils.lead(localized, locale);
        }
 
        static Locale getCurrentLocale() {
-               return UiContext.getLocale();
+               return CurrentUser.locale();
+               // return UiContext.getLocale();
+               // FIXME look into Subject or settings
+               // return Locale.getDefault();
        }
-       // private String id;
-       // private ClassLoader classLoader;
-       // private final Object defaultLocal;
-       //
-       // public Msg() {
-       // defaultLocal = null;
-       // }
-       //
-       // public Msg(Object defaultMessage) {
-       // this.defaultLocal = defaultMessage;
-       // }
-       //
-       // public String getId() {
-       // return id;
-       // }
-       //
-       // public void setId(String id) {
-       // this.id = id;
-       // }
-       //
-       // public ClassLoader getClassLoader() {
-       // return classLoader;
-       // }
-       //
-       // public void setClassLoader(ClassLoader classLoader) {
-       // this.classLoader = classLoader;
-       // }
-       //
-       // public Object getDefault() {
-       // return defaultLocal;
-       // }
-       //
-       // public String toString() {
-       // return local().toString();
-       // }
-       //
-       // /** When used as the first word of a sentence. */
-       // public String lead() {
-       // return lead(UiContext.getLocale());
-       // }
-       //
-       // public String lead(Locale locale) {
-       // return lead(this, locale);
-       // }
 
-       // private static String lead(Msg msg, Locale locale) {
-       // String raw = msg.local(locale).toString();
-       // return lead(raw, locale);
-       // }
-
-       // public Object local() {
-       // Object local = local(this);
-       // if (local == null)
-       // local = getDefault();
-       // if (local == null)
-       // throw new CmsException("No translation found for " + id);
-       // return local;
-       // }
-       //
-       // public Object local(Locale locale) {
-       // Object local = local(this, locale);
-       // if (local == null)
-       // local = getDefault();
-       // if (local == null)
-       // throw new CmsException("No translation found for " + id);
-       // return local;
-       // }
-       //
-       // private static Object local(Msg msg) {
-       // Locale locale = UiContext.getLocale();
-       // return local(msg, locale);
-       // }
-       //
-       // public static Object local(Msg msg, Locale locale) {
-       // String key = msg.getId();
-       // int lastDot = key.lastIndexOf('.');
-       // String className = key.substring(0, lastDot);
-       // String fieldName = key.substring(lastDot + 1);
-       // ResourceBundle rb = ResourceBundle.getBundle("/OSGI-INF/l10n/bundle",
-       // locale, msg.getClassLoader());
-       // // ResourceBundle rb = ResourceBundle.getBundle(className, locale,
-       // // msg.getClassLoader());
-       // return rb.getString(fieldName);
-       // }
-
-       // public static void init(Class<?> clss) {
-       // final Field[] fieldArray = clss.getDeclaredFields();
-       // ClassLoader loader = clss.getClassLoader();
-       //
-       // for (Field field : fieldArray) {
-       // if (Modifier.isStatic(field.getModifiers())
-       // && field.getType().isAssignableFrom(Msg.class)) {
-       // try {
-       // Object obj = field.get(null);
-       // String id = clss.getCanonicalName() + "." + field.getName();
-       // obj.getClass().getMethod("setId", String.class)
-       // .invoke(obj, id);
-       // obj.getClass()
-       // .getMethod("setClassLoader", ClassLoader.class)
-       // .invoke(obj, loader);
-       // } catch (Exception e) {
-       // throw new CmsException("Cannot prepare field " + field);
-       // }
-       // }
-       // }
-       // }
+       /** Returns null if argument is null. */
+       public static List<Locale> asLocaleList(Object locales) {
+               return org.argeo.cms.LocaleUtils.asLocaleList(locales);
+       }
 }