1 package org
.argeo
.cms
.web
;
3 import java
.util
.Dictionary
;
4 import java
.util
.HashMap
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
9 import org
.argeo
.cms
.ui
.CmsApp
;
10 import org
.argeo
.cms
.ui
.CmsAppListener
;
11 import org
.argeo
.cms
.ui
.CmsTheme
;
12 import org
.argeo
.util
.LangUtils
;
13 import org
.eclipse
.rap
.rwt
.RWT
;
14 import org
.eclipse
.rap
.rwt
.application
.Application
;
15 import org
.eclipse
.rap
.rwt
.application
.ApplicationConfiguration
;
16 import org
.eclipse
.rap
.rwt
.client
.WebClient
;
17 import org
.osgi
.framework
.BundleContext
;
18 import org
.osgi
.framework
.ServiceRegistration
;
19 import org
.osgi
.service
.event
.EventAdmin
;
21 /** An RWT web app integrating with a {@link CmsApp}. */
22 public class CmsWebApp
implements ApplicationConfiguration
, CmsAppListener
{
23 private final static Log log
= LogFactory
.getLog(CmsWebApp
.class);
25 private BundleContext bundleContext
;
26 private CmsApp cmsApp
;
27 private EventAdmin eventAdmin
;
29 private ServiceRegistration
<ApplicationConfiguration
> rwtAppReg
;
31 private final static String CONTEXT_NAME
= "contextName";
32 private String contextName
;
34 public void init(BundleContext bundleContext
, Map
<String
, String
> properties
) {
35 this.bundleContext
= bundleContext
;
36 contextName
= properties
.get(CONTEXT_NAME
);
39 // registerIfAllThemesAvailable();
42 public void destroy(BundleContext bundleContext
, Map
<String
, String
> properties
) {
44 cmsApp
.removeCmsAppListener(this);
48 public void configure(Application application
) {
49 for (String uiName
: cmsApp
.getUiNames()) {
50 CmsTheme theme
= cmsApp
.getTheme(uiName
);
52 WebThemeUtils
.apply(application
, theme
);
54 // for (CmsTheme theme : themes.values())
55 // WebThemeUtils.apply(application, theme);
57 Map
<String
, String
> properties
= new HashMap
<>();
58 addEntryPoints(application
, properties
);
62 protected void addEntryPoints(Application application
, Map
<String
, String
> commonProperties
) {
63 for (String uiName
: cmsApp
.getUiNames()) {
64 Map
<String
, String
> properties
= new HashMap
<>(commonProperties
);
65 CmsTheme theme
= cmsApp
.getTheme(uiName
);
67 properties
.put(WebClient
.THEME_ID
, theme
.getThemeId());
68 properties
.put(WebClient
.HEAD_HTML
, theme
.getHtmlHeaders());
70 properties
.put(WebClient
.THEME_ID
, RWT
.DEFAULT_THEME_ID
);
71 // if (themeId != null)
72 // log.warn("Theme id " + themeId + " was specified but it was not found, using default RWT theme.");
74 application
.addEntryPoint("/" + uiName
, () -> {
75 CmsWebEntryPoint entryPoint
= new CmsWebEntryPoint(this, uiName
);
76 entryPoint
.setEventAdmin(eventAdmin
);
79 if (log
.isDebugEnabled())
80 log
.info("Added web entry point /" + (contextName
!= null ? contextName
: "") + "/" + uiName
);
82 log
.debug("Published CMS web app /" + (contextName
!= null ? contextName
: ""));
85 // private void registerIfAllThemesAvailable() {
86 // boolean themeMissing = false;
87 // uiNames: for (String uiName : cmsApp.getUiNames()) {
88 // String themeId = cmsApp.getThemeId(uiName);
89 // if (RWT.DEFAULT_THEME_ID.equals(themeId))
91 // if (!themes.containsKey(themeId)) {
92 // themeMissing = true;
96 // if (!themeMissing) {
97 // Dictionary<String, Object> regProps = LangUtils.dict(CONTEXT_NAME, contextName);
98 // if (bundleContext != null) {
99 // rwtAppReg = bundleContext.registerService(ApplicationConfiguration.class, this, regProps);
100 // log.info("Published CMS web app /" + (contextName != null ? contextName : ""));
109 public void setCmsApp(CmsApp cmsApp
, Map
<String
, String
> properties
) {
110 this.cmsApp
= cmsApp
;
111 this.cmsApp
.addCmsAppListener(this);
112 // registerIfAllThemesAvailable();
115 public void unsetCmsApp(CmsApp cmsApp
, Map
<String
, String
> properties
) {
116 if (rwtAppReg
!= null)
117 rwtAppReg
.unregister();
122 public void themingUpdated() {
123 Dictionary
<String
, Object
> regProps
= LangUtils
.dict(CONTEXT_NAME
, contextName
);
124 if (rwtAppReg
!= null)
125 rwtAppReg
.unregister();
126 if (bundleContext
!= null) {
127 rwtAppReg
= bundleContext
.registerService(ApplicationConfiguration
.class, this, regProps
);
128 if (log
.isDebugEnabled())
129 log
.debug("Publishing CMS web app /" + (contextName
!= null ? contextName
: "") + " ...");
133 public void setEventAdmin(EventAdmin eventAdmin
) {
134 this.eventAdmin
= eventAdmin
;