]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.ui/src/org/argeo/cms/util/ThemeUtils.java
[maven-release-plugin] prepare release argeo-commons-2.1.84
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / util / ThemeUtils.java
1 package org.argeo.cms.util;
2
3 import java.net.URL;
4 import java.util.Enumeration;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 import org.eclipse.rap.rwt.application.Application;
9 import org.osgi.framework.Bundle;
10 import org.osgi.framework.BundleContext;
11
12 public class ThemeUtils {
13 final static Log log = LogFactory.getLog(ThemeUtils.class);
14
15 public static Bundle findThemeBundle(BundleContext bundleContext, String themeId) {
16 if (themeId == null)
17 return null;
18 // TODO optimize
19 // TODO deal with multiple versions
20 Bundle themeBundle = null;
21 if (themeId != null) {
22 for (Bundle bundle : bundleContext.getBundles())
23 if (themeId.equals(bundle.getSymbolicName())) {
24 themeBundle = bundle;
25 break;
26 }
27 }
28 return themeBundle;
29 }
30
31 public static void addThemeResources(Application application, Bundle themeBundle, BundleResourceLoader themeBRL,
32 String pattern) {
33 Enumeration<URL> themeResources = themeBundle.findEntries("/", pattern, true);
34 if (themeResources == null)
35 return;
36 while (themeResources.hasMoreElements()) {
37 String resource = themeResources.nextElement().getPath();
38 // remove first '/' so that RWT registers it
39 resource = resource.substring(1);
40 if (!resource.endsWith("/")) {
41 application.addResource(resource, themeBRL);
42 if (log.isTraceEnabled())
43 log.trace("Registered " + resource + " from theme " + themeBundle);
44 }
45
46 }
47
48 }
49
50 }