- Bundle themeBundle;
- if (symbolicName == null) {
- themeBundle = bundleContext.getBundle();
- basePath = "/theme/internal/";
- cssPath = basePath;
- } else {
- themeBundle = ThemeUtils.findThemeBundle(bundleContext, symbolicName);
- basePath = "/";
- cssPath = "/rap/";
- }
- this.themeId = themeBundle.getSymbolicName();
- addStyleSheets(themeBundle, new BundleResourceLoader(themeBundle));
- BundleResourceLoader themeBRL = new BundleResourceLoader(themeBundle);
- addResources(themeBRL, "*.png");
- addResources(themeBRL, "*.gif");
- addResources(themeBRL, "*.jpg");
- addResources(themeBRL, "*.jpeg");
- addResources(themeBRL, "*.svg");
- addResources(themeBRL, "*.ico");
-
- // fonts
- URL fontsUrl = themeBundle.getEntry(basePath + "fonts.txt");
- if (fontsUrl != null) {
- loadFontsUrl(fontsUrl);
- }
-
- // common CSS header (plain CSS)
- URL headerCssUrl = themeBundle.getEntry(basePath + "header.css");
- if (headerCssUrl != null) {
- try (BufferedReader buffer = new BufferedReader(new InputStreamReader(headerCssUrl.openStream(), UTF_8))) {
- headerCss = buffer.lines().collect(Collectors.joining("\n"));
- } catch (IOException e) {
- throw new CmsException("Cannot read " + headerCssUrl, e);
- }
- }
-
- }
-
- public void apply(Application application) {
- for (String name : resources.keySet()) {
- application.addResource(name, resources.get(name));
- if (log.isDebugEnabled())
- log.debug("Added resource " + name);
- }
- for (String name : css.keySet()) {
- application.addStyleSheet(themeId, name, css.get(name));
- if (log.isDebugEnabled())
- log.debug("Added RAP CSS " + name);
- }
- }
-
- public String getAdditionalHeaders() {
- StringBuilder sb = new StringBuilder();
- if (headerCss != null) {
- sb.append("<style type='text/css'>\n");
- sb.append(headerCss);
- sb.append("\n</style>\n");
- }
- for (String link : fonts) {
- sb.append("<link rel='stylesheet' href='");
- sb.append(link);
- sb.append("'/>\n");
- }
- if (sb.length() == 0)
- return null;
- else
- return sb.toString();
- }
-
- void addStyleSheets(Bundle themeBundle, ResourceLoader ssRL) {
- Enumeration<URL> themeResources = themeBundle.findEntries(cssPath, "*.css", true);
- if (themeResources == null)
- return;
- while (themeResources.hasMoreElements()) {
- String resource = themeResources.nextElement().getPath();
- // remove first '/' so that RWT registers it
- resource = resource.substring(1);
- if (!resource.endsWith("/")) {
- if (css.containsKey(resource))
- log.warn("Overriding " + resource + " from " + themeBundle.getSymbolicName());
- css.put(resource, ssRL);
- }
-
- }
-