X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fscript%2FTheme.java;h=3fa4bc451edae6b324603c5a0dadf5840a1e6bbe;hb=86ea60b48b0e813e5227be733d3cdd46f190665d;hp=51fc65ddab7f6d37cf1327443690d488dab2200c;hpb=a667d43d6a3ccef0e701320e9a61e50d8608615e;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms.ui/src/org/argeo/cms/script/Theme.java b/org.argeo.cms.ui/src/org/argeo/cms/script/Theme.java index 51fc65dda..3fa4bc451 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/script/Theme.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/script/Theme.java @@ -26,16 +26,32 @@ import org.osgi.framework.BundleContext; public class Theme { private final static Log log = LogFactory.getLog(Theme.class); - private String themeId; + private final String themeId; private Map css = new HashMap<>(); private Map resources = new HashMap<>(); private String headerCss; private List fonts = new ArrayList<>(); + private String basePath; + private String cssPath; + + public Theme(BundleContext bundleContext) { + this(bundleContext, null); + } + public Theme(BundleContext bundleContext, String symbolicName) { - this.themeId = symbolicName; - Bundle themeBundle = ThemeUtils.findThemeBundle(bundleContext, symbolicName); + 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"); @@ -46,13 +62,13 @@ public class Theme { addResources(themeBRL, "*.ico"); // fonts - URL fontsUrl = themeBundle.getEntry("fonts.txt"); + URL fontsUrl = themeBundle.getEntry(basePath + "fonts.txt"); if (fontsUrl != null) { loadFontsUrl(fontsUrl); } // common CSS header (plain CSS) - URL headerCssUrl = themeBundle.getEntry("header.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")); @@ -66,9 +82,13 @@ public class Theme { 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); } } @@ -91,7 +111,7 @@ public class Theme { } void addStyleSheets(Bundle themeBundle, ResourceLoader ssRL) { - Enumeration themeResources = themeBundle.findEntries("/rap", "*.css", true); + Enumeration themeResources = themeBundle.findEntries(cssPath, "*.css", true); if (themeResources == null) return; while (themeResources.hasMoreElements()) { @@ -124,7 +144,7 @@ public class Theme { void addResources(BundleResourceLoader themeBRL, String pattern) { Bundle themeBundle = themeBRL.getBundle(); - Enumeration themeResources = themeBundle.findEntries("/", pattern, true); + Enumeration themeResources = themeBundle.findEntries(basePath, pattern, true); if (themeResources == null) return; while (themeResources.hasMoreElements()) { @@ -145,4 +165,20 @@ public class Theme { return themeId; } + public String getBasePath() { + return basePath; + } + + public void setBasePath(String basePath) { + this.basePath = basePath; + } + + public String getCssPath() { + return cssPath; + } + + public void setCssPath(String cssPath) { + this.cssPath = cssPath; + } + }