3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
5 import java
.util
.ArrayList
;
6 import java
.util
.HashMap
;
10 import org
.apache
.commons
.logging
.Log
;
11 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.eclipse
.gemini
.blueprint
.context
.BundleContextAware
;
13 import org
.eclipse
.rap
.rwt
.application
.Application
;
14 import org
.eclipse
.rap
.rwt
.application
.Application
.OperationMode
;
15 import org
.eclipse
.rap
.rwt
.application
.ApplicationConfiguration
;
16 import org
.eclipse
.rap
.rwt
.application
.EntryPointFactory
;
17 import org
.eclipse
.rap
.rwt
.application
.ExceptionHandler
;
18 import org
.eclipse
.rap
.rwt
.client
.WebClient
;
19 import org
.eclipse
.rap
.rwt
.service
.ResourceLoader
;
20 import org
.osgi
.framework
.BundleContext
;
22 /** Configures an Argeo CMS RWT application. */
23 public class CmsApplication
implements CmsConstants
, ApplicationConfiguration
,
25 final static Log log
= LogFactory
.getLog(CmsApplication
.class);
27 private Map
<String
, EntryPointFactory
> entryPoints
= new HashMap
<String
, EntryPointFactory
>();
28 private Map
<String
, Map
<String
, String
>> entryPointsBranding
= new HashMap
<String
, Map
<String
, String
>>();
29 private Map
<String
, List
<String
>> styleSheets
= new HashMap
<String
, List
<String
>>();
31 private List
<String
> resources
= new ArrayList
<String
>();
33 // private Bundle clientScriptingBundle;
34 private BundleContext bundleContext
;
36 public void configure(Application application
) {
38 application
.setOperationMode(OperationMode
.SWT_COMPATIBILITY
);
39 application
.setExceptionHandler(new CmsExceptionHandler());
41 // TODO load all pics under icons
42 // loading animated gif
43 application
.addResource(LOADING_IMAGE
,
44 createResourceLoader(LOADING_IMAGE
));
46 application
.addResource(NO_IMAGE
, createResourceLoader(NO_IMAGE
));
48 for (String resource
: resources
) {
49 application
.addResource(resource
, new BundleResourceLoader(
51 if (log
.isDebugEnabled())
52 log
.debug("Registered resource " + resource
);
56 for (String entryPoint
: entryPoints
.keySet()) {
57 Map
<String
, String
> properties
= new HashMap
<String
, String
>();
58 if (entryPointsBranding
.containsKey(entryPoint
)) {
59 properties
= entryPointsBranding
.get(entryPoint
);
60 if (properties
.containsKey(WebClient
.FAVICON
)) {
61 String faviconRelPath
= properties
62 .get(WebClient
.FAVICON
);
63 application
.addResource(faviconRelPath
,
64 new BundleResourceLoader(bundleContext
));
65 if (log
.isTraceEnabled())
66 log
.trace("Registered favicon " + faviconRelPath
);
70 if (!properties
.containsKey(WebClient
.BODY_HTML
))
71 properties
.put(WebClient
.BODY_HTML
,
72 DEFAULT_LOADING_BODY
);
75 application
.addEntryPoint("/" + entryPoint
,
76 entryPoints
.get(entryPoint
), properties
);
77 log
.info("Registered entry point /" + entryPoint
);
81 for (String themeId
: styleSheets
.keySet()) {
82 List
<String
> cssLst
= styleSheets
.get(themeId
);
83 for (String css
: cssLst
) {
84 application
.addStyleSheet(themeId
, css
,
85 new BundleResourceLoader(bundleContext
));
90 // application.addPhaseListener(new CmsPhaseListener());
92 } catch (RuntimeException e
) {
93 // Easier access to initialisation errors
94 log
.error("Unexpected exception when configuring RWT application.",
100 private static ResourceLoader
createResourceLoader(final String resourceName
) {
101 return new ResourceLoader() {
102 public InputStream
getResourceAsStream(String resourceName
)
104 return getClass().getClassLoader().getResourceAsStream(
110 public void setEntryPoints(
111 Map
<String
, EntryPointFactory
> entryPointFactories
) {
112 this.entryPoints
= entryPointFactories
;
115 public void setEntryPointsBranding(
116 Map
<String
, Map
<String
, String
>> entryPointBranding
) {
117 this.entryPointsBranding
= entryPointBranding
;
120 public void setStyleSheets(Map
<String
, List
<String
>> styleSheets
) {
121 this.styleSheets
= styleSheets
;
124 public void setBundleContext(BundleContext bundleContext
) {
125 this.bundleContext
= bundleContext
;
128 public void setResources(List
<String
> resources
) {
129 this.resources
= resources
;
132 class CmsExceptionHandler
implements ExceptionHandler
{
135 public void handleException(Throwable throwable
) {
136 CmsSession
.current
.get().exception(throwable
);
141 // class CmsPhaseListener implements PhaseListener {
142 // private static final long serialVersionUID = -1966645586738534609L;
145 // public PhaseId getPhaseId() {
146 // return PhaseId.RENDER;
150 // public void beforePhase(PhaseEvent event) {
151 // CmsSession cmsSession = CmsSession.current.get();
152 // String state = cmsSession.getState();
153 // if (state == null)
154 // cmsSession.navigateTo("~");
158 // public void afterPhase(PhaseEvent event) {
165 private static String DEFAULT_LOADING_BODY
= "<div"
166 + " style=\"position: absolute; left: 50%; top: 50%; margin: -32px -32px; width: 64px; height:64px\">"
167 + "<img src=\"./rwt-resources/icons/loading.gif\" width=\"32\" height=\"32\" style=\"margin: 16px 16px\"/>"