Introduce body html in theming.
[lgpl/argeo-commons.git] / org.argeo.cms.ui.rap / src / org / argeo / cms / web / CmsWebApp.java
index 361e8a0d21778b04113ca896dd27c535769cee79..75509bd640dfec58071cceca6a219ddd93f826d7 100644 (file)
@@ -19,6 +19,7 @@ import org.eclipse.rap.rwt.application.Application.OperationMode;
 import org.eclipse.rap.rwt.client.WebClient;
 import org.eclipse.swt.widgets.Display;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.event.EventAdmin;
 
@@ -28,6 +29,7 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm
 
        private BundleContext bundleContext;
        private CmsApp cmsApp;
+       private String cmsAppId;
        private EventAdmin eventAdmin;
 
        private ServiceRegistration<ApplicationConfiguration> rwtAppReg;
@@ -38,13 +40,17 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm
        public void init(BundleContext bundleContext, Map<String, String> properties) {
                this.bundleContext = bundleContext;
                contextName = properties.get(CONTEXT_NAME);
-               if (cmsApp != null)
-                       themingUpdated();
+               if (cmsApp != null) {
+                       if (cmsApp.allThemesAvailable())
+                               publishWebApp();
+               }
        }
 
        public void destroy(BundleContext bundleContext, Map<String, String> properties) {
-               if (cmsApp != null)
+               if (cmsApp != null) {
                        cmsApp.removeCmsAppListener(this);
+                       cmsApp = null;
+               }
        }
 
        @Override
@@ -84,6 +90,7 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm
                        if (theme != null) {
                                properties.put(WebClient.THEME_ID, theme.getThemeId());
                                properties.put(WebClient.HEAD_HTML, theme.getHtmlHeaders());
+                               properties.put(WebClient.BODY_HTML, theme.getBodyHtml());
                        } else {
                                properties.put(WebClient.THEME_ID, RWT.DEFAULT_THEME_ID);
                        }
@@ -96,8 +103,8 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm
                        if (log.isDebugEnabled())
                                log.info("Added web entry point " + (contextName != null ? "/" + contextName : "") + entryPointName);
                }
-               if (log.isDebugEnabled())
-                       log.debug("Published CMS web app /" + (contextName != null ? contextName : ""));
+//             if (log.isDebugEnabled())
+//                     log.debug("Published CMS web app /" + (contextName != null ? contextName : ""));
        }
 
        CmsApp getCmsApp() {
@@ -110,10 +117,17 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm
 
        public void setCmsApp(CmsApp cmsApp, Map<String, String> properties) {
                this.cmsApp = cmsApp;
+               this.cmsAppId = properties.get(Constants.SERVICE_PID);
                this.cmsApp.addCmsAppListener(this);
        }
 
        public void unsetCmsApp(CmsApp cmsApp, Map<String, String> properties) {
+               String cmsAppId = properties.get(Constants.SERVICE_PID);
+               if (!cmsAppId.equals(this.cmsAppId))
+                       return;
+               if (this.cmsApp != null) {
+                       this.cmsApp.removeCmsAppListener(this);
+               }
                if (rwtAppReg != null)
                        rwtAppReg.unregister();
                this.cmsApp = null;
@@ -121,6 +135,11 @@ public class CmsWebApp implements ApplicationConfiguration, ExceptionHandler, Cm
 
        @Override
        public void themingUpdated() {
+               if (cmsApp != null && cmsApp.allThemesAvailable())
+                       publishWebApp();
+       }
+
+       protected void publishWebApp() {
                Dictionary<String, Object> regProps = LangUtils.dict(CONTEXT_NAME, contextName);
                if (rwtAppReg != null)
                        rwtAppReg.unregister();