X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fruntime%2FCmsContextImpl.java;fp=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Finternal%2Fruntime%2FCmsContextImpl.java;h=e14b21e7073cd39241250fa0ec337a2a795a83e8;hb=dca2b13e0e3ca3e7a9469e089b980c48c880ad1a;hp=2a81b6a7d11db963e7f8319f5e9761b9451dbad9;hpb=4e8d82137c2dce7145175eacbd225a52227b6f73;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsContextImpl.java b/org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsContextImpl.java index 2a81b6a7d..e14b21e70 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsContextImpl.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsContextImpl.java @@ -3,6 +3,7 @@ package org.argeo.cms.internal.runtime; import static java.util.Locale.ENGLISH; import java.lang.management.ManagementFactory; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -13,8 +14,6 @@ import java.util.concurrent.ExecutionException; import javax.security.auth.Subject; -import org.argeo.api.acr.spi.ProvidedContent; -import org.argeo.api.acr.spi.ProvidedRepository; import org.argeo.api.cms.CmsConstants; import org.argeo.api.cms.CmsContext; import org.argeo.api.cms.CmsDeployment; @@ -23,6 +22,7 @@ import org.argeo.api.cms.CmsSession; import org.argeo.api.cms.CmsSessionId; import org.argeo.api.cms.CmsState; import org.argeo.api.uuid.UuidFactory; +import org.argeo.cms.CmsDeployProperty; import org.argeo.cms.LocaleUtils; import org.argeo.cms.internal.auth.CmsSessionImpl; import org.ietf.jgss.GSSCredential; @@ -56,10 +56,14 @@ public class CmsContextImpl implements CmsContext { // } public void start() { - Object defaultLocaleValue = KernelUtils.getFrameworkProp(CmsConstants.I18N_DEFAULT_LOCALE); - defaultLocale = defaultLocaleValue != null ? new Locale(defaultLocaleValue.toString()) - : new Locale(ENGLISH.getLanguage()); - locales = LocaleUtils.asLocaleList(KernelUtils.getFrameworkProp(CmsConstants.I18N_LOCALES)); + List codes = CmsStateImpl.getDeployProperties(cmsState, CmsDeployProperty.LOCALE); + locales = getLocaleList(codes); + if (locales.size() == 0) + throw new IllegalStateException("At least one locale must be set"); + defaultLocale = locales.get(0); +// Object defaultLocaleValue = KernelUtils.getFrameworkProp(CmsConstants.I18N_DEFAULT_LOCALE); +// defaultLocale = defaultLocaleValue != null ? new Locale(defaultLocaleValue.toString()) +// : new Locale(ENGLISH.getLanguage()); // node repository // new ServiceTracker(bc, Repository.class, null) { // @Override @@ -145,6 +149,29 @@ public class CmsContextImpl implements CmsContext { throw new UnsupportedOperationException(); } + /** Returns null if argument is null. */ + private static List getLocaleList(List codes) { + if (codes == null) + return null; + ArrayList availableLocales = new ArrayList(); + for (String code : codes) { + if (code == null) + continue; + // variant not supported + int indexUnd = code.indexOf("_"); + Locale locale; + if (indexUnd > 0) { + String language = code.substring(0, indexUnd); + String country = code.substring(indexUnd + 1); + locale = new Locale(language, country); + } else { + locale = new Locale(code); + } + availableLocales.add(locale); + } + return availableLocales; + } + public void setCmsDeployment(CmsDeployment cmsDeployment) { this.cmsDeployment = cmsDeployment; }