]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/internal/runtime/CmsContextImpl.java
Refactor deploy properties and move legacy CMS exception.
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / internal / runtime / CmsContextImpl.java
index ef9f0ec9a8df203ad6a50a588a1cf9b79ec88fa3..e14b21e7073cd39241250fa0ec337a2a795a83e8 100644 (file)
@@ -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;
@@ -20,6 +21,8 @@ import org.argeo.api.cms.CmsLog;
 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;
@@ -35,6 +38,8 @@ public class CmsContextImpl implements CmsContext {
        private CmsState cmsState;
        private CmsDeployment cmsDeployment;
        private UserAdmin userAdmin;
+       private UuidFactory uuidFactory;
+//     private ProvidedRepository contentRepository;
 
        // i18n
        private Locale defaultLocale;
@@ -51,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<String> 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<Repository, Repository>(bc, Repository.class, null) {
 //                     @Override
@@ -140,6 +149,29 @@ public class CmsContextImpl implements CmsContext {
                throw new UnsupportedOperationException();
        }
 
+       /** Returns null if argument is null. */
+       private static List<Locale> getLocaleList(List<String> codes) {
+               if (codes == null)
+                       return null;
+               ArrayList<Locale> availableLocales = new ArrayList<Locale>();
+               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;
        }
@@ -152,6 +184,22 @@ public class CmsContextImpl implements CmsContext {
                this.userAdmin = userAdmin;
        }
 
+       public UuidFactory getUuidFactory() {
+               return uuidFactory;
+       }
+
+       public void setUuidFactory(UuidFactory uuidFactory) {
+               this.uuidFactory = uuidFactory;
+       }
+
+//     public ProvidedRepository getContentRepository() {
+//             return contentRepository;
+//     }
+//
+//     public void setContentRepository(ProvidedRepository contentRepository) {
+//             this.contentRepository = contentRepository;
+//     }
+
        @Override
        public Locale getDefaultLocale() {
                return defaultLocale;
@@ -171,6 +219,11 @@ public class CmsContextImpl implements CmsContext {
                return availableSince != null;
        }
 
+       @Override
+       public CmsState getCmsState() {
+               return cmsState;
+       }
+
        /*
         * STATIC
         */
@@ -242,10 +295,18 @@ public class CmsContextImpl implements CmsContext {
                cmsSessionsByLocalId.remove(cmsSession.getLocalId());
        }
 
+       /**
+        * The {@link CmsSession} related to this UUID, or <code>null</null> if not
+        * registered.
+        */
        public synchronized CmsSessionImpl getCmsSessionByUuid(UUID uuid) {
                return cmsSessionsByUuid.get(uuid);
        }
 
+       /**
+        * The {@link CmsSession} related to this local id, or <code>null</null> if not
+        * registered.
+        */
        public synchronized CmsSessionImpl getCmsSessionByLocalId(String localId) {
                return cmsSessionsByLocalId.get(localId);
        }