From: Mathieu Date: Thu, 1 Dec 2022 06:29:53 +0000 (+0100) Subject: LDAP-style localisation in ACR X-Git-Tag: v2.3.13~1 X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=0aace28903851405b765e917714dbd6f5e5955b8 LDAP-style localisation in ACR --- 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 index 000000000..7ef64c25a --- /dev/null +++ b/org.argeo.api.acr/src/org/argeo/api/acr/ldap/LdapAcrUtils.java @@ -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; + } +} diff --git a/org.argeo.api.acr/src/org/argeo/api/acr/ldap/NamingUtils.java b/org.argeo.api.acr/src/org/argeo/api/acr/ldap/NamingUtils.java index 9f7ec61d8..88b76ecd2 100644 --- a/org.argeo.api.acr/src/org/argeo/api/acr/ldap/NamingUtils.java +++ b/org.argeo.api.acr/src/org/argeo/api/acr/ldap/NamingUtils.java @@ -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"); +// } }