Support i18n in directory
[lgpl/argeo-commons.git] / org.argeo.util / src / org / argeo / util / directory / ldap / LdapEntry.java
index cf293cee2e94aa2ec6eda2312ae4aef2209a19ab..823bc9502e6eb9a57c9e51e6d381c9c29b94f9c8 100644 (file)
@@ -1,8 +1,10 @@
 package org.argeo.util.directory.ldap;
 
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Dictionary;
 import java.util.List;
+import java.util.Locale;
 import java.util.Set;
 import java.util.StringJoiner;
 import java.util.TreeSet;
@@ -29,7 +31,11 @@ public interface LdapEntry {
        /*
         * UTILITIES
         */
-       public static void addObjectClasses(Dictionary<String, Object> properties, Set<String> objectClasses) {
+       /**
+        * Convert a collection of object classes to the format expected by an LDAP
+        * backend.
+        */
+       public static void addObjectClasses(Dictionary<String, Object> properties, Collection<String> objectClasses) {
                String value = properties.get(LdapAttrs.objectClasses.name()).toString();
                Set<String> currentObjectClasses = new TreeSet<>(Arrays.asList(value.toString().split("\n")));
                currentObjectClasses.addAll(objectClasses);
@@ -37,4 +43,14 @@ public interface LdapEntry {
                currentObjectClasses.forEach((s) -> values.add(s));
                properties.put(LdapAttrs.objectClasses.name(), values.toString());
        }
+
+       public static Object getLocalized(Dictionary<String, Object> properties, String key, Locale locale) {
+               if (locale == null)
+                       return null;
+               Object value = null;
+               value = properties.get(key + ";lang-" + locale.getLanguage() + "-" + locale.getCountry());
+               if (value == null)
+                       value = properties.get(key + ";lang-" + locale.getLanguage());
+               return value;
+       }
 }