LDAP-style localisation in ACR
authorMathieu <mbaudier@argeo.org>
Thu, 1 Dec 2022 06:29:53 +0000 (07:29 +0100)
committerMathieu <mbaudier@argeo.org>
Thu, 1 Dec 2022 06:29:53 +0000 (07:29 +0100)
org.argeo.api.acr/src/org/argeo/api/acr/ldap/LdapAcrUtils.java [new file with mode: 0644]
org.argeo.api.acr/src/org/argeo/api/acr/ldap/NamingUtils.java

diff --git a/org.argeo.api.acr/src/org/argeo/api/acr/ldap/LdapAcrUtils.java b/org.argeo.api.acr/src/org/argeo/api/acr/ldap/LdapAcrUtils.java
new file mode 100644 (file)
index 0000000..7ef64c2
--- /dev/null
@@ -0,0 +1,31 @@
+package org.argeo.api.acr.ldap;
+
+import java.util.Locale;
+
+import javax.xml.namespace.QName;
+
+import org.argeo.api.acr.Content;
+import org.argeo.api.acr.ContentName;
+
+/** Utilities around ACR and LDAP conventions. */
+public class LdapAcrUtils {
+
+       /** singleton */
+       private LdapAcrUtils() {
+       }
+
+       public static Object getLocalized(Content content, QName key, Locale locale) {
+               if (locale == null)
+                       throw new IllegalArgumentException("A locale must be specified");
+               Object value = null;
+               if (locale.getCountry() != null && !locale.getCountry().equals(""))
+                       value = content.get(new ContentName(key.getNamespaceURI(),
+                                       key.getLocalPart() + ";lang-" + locale.getLanguage() + "-" + locale.getCountry()));
+               if (value == null)
+                       value = content
+                                       .get(new ContentName(key.getNamespaceURI(), key.getLocalPart() + ";lang-" + locale.getLanguage()));
+               if (value == null)
+                       value = content.get(key);
+               return value;
+       }
+}
index 9f7ec61d8b48846a7939ce84d2c0547b7116790d..88b76ecd29520148ca68bc16edd32b10370e20de 100644 (file)
@@ -96,11 +96,11 @@ public class NamingUtils {
 
        }
 
-       public static void main(String args[]) {
-               ZonedDateTime now = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
-               String str = utcLdapDate.format(now);
-               System.out.println(str);
-               utcLdapDate.parse(str);
-               utcLdapDate.parse("19520512000000Z");
-       }
+//     public static void main(String args[]) {
+//             ZonedDateTime now = ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC);
+//             String str = utcLdapDate.format(now);
+//             System.out.println(str);
+//             utcLdapDate.parse(str);
+//             utcLdapDate.parse("19520512000000Z");
+//     }
 }