]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms.ui/src/org/argeo/cms/script/Theme.java
Skip maven generated/copied theme resources
[lgpl/argeo-commons.git] / org.argeo.cms.ui / src / org / argeo / cms / script / Theme.java
index 51fc65ddab7f6d37cf1327443690d488dab2200c..a3dce2f57e58fd9e86c6a5a7df40920915dd3f10 100644 (file)
@@ -18,6 +18,7 @@ import org.apache.commons.logging.LogFactory;
 import org.argeo.cms.CmsException;
 import org.argeo.cms.util.BundleResourceLoader;
 import org.argeo.cms.util.ThemeUtils;
+import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.application.Application;
 import org.eclipse.rap.rwt.service.ResourceLoader;
 import org.osgi.framework.Bundle;
@@ -33,9 +34,25 @@ public class Theme {
        private String headerCss;
        private List<String> 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/";
+//                     cssPath = basePath;
+               } else {
+                       themeBundle = ThemeUtils.findThemeBundle(bundleContext, symbolicName);
+               }
+               basePath = "/";
+               cssPath = "/rap/";
+               this.themeId = RWT.DEFAULT_THEME_ID;
                addStyleSheets(themeBundle, new BundleResourceLoader(themeBundle));
                BundleResourceLoader themeBRL = new BundleResourceLoader(themeBundle);
                addResources(themeBRL, "*.png");
@@ -46,13 +63,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"));
@@ -64,11 +81,17 @@ public class Theme {
        }
 
        public void apply(Application application) {
-               for (String name : resources.keySet()) {
+               resources: for (String name : resources.keySet()) {
+                       if (name.startsWith("target/"))
+                               continue resources; // skip maven output
                        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 +114,7 @@ public class Theme {
        }
 
        void addStyleSheets(Bundle themeBundle, ResourceLoader ssRL) {
-               Enumeration<URL> themeResources = themeBundle.findEntries("/rap", "*.css", true);
+               Enumeration<URL> themeResources = themeBundle.findEntries(cssPath, "*.css", true);
                if (themeResources == null)
                        return;
                while (themeResources.hasMoreElements()) {
@@ -124,7 +147,7 @@ public class Theme {
 
        void addResources(BundleResourceLoader themeBRL, String pattern) {
                Bundle themeBundle = themeBRL.getBundle();
-               Enumeration<URL> themeResources = themeBundle.findEntries("/", pattern, true);
+               Enumeration<URL> themeResources = themeBundle.findEntries(basePath, pattern, true);
                if (themeResources == null)
                        return;
                while (themeResources.hasMoreElements()) {
@@ -145,4 +168,24 @@ public class Theme {
                return themeId;
        }
 
+       public void setThemeId(String themeId) {
+               this.themeId = 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;
+       }
+
 }