]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/osgi/BundleCmsTheme.java
Refactor CMS UX API
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / osgi / BundleCmsTheme.java
index 75a2212b65ce5fe6f3a51e07b7b5e925c1dce8db..3ab799f713e1ab9e802a20654efc81426c7de5b7 100644 (file)
@@ -10,6 +10,7 @@ import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Enumeration;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -17,7 +18,7 @@ import java.util.TreeSet;
 import java.util.stream.Collectors;
 
 import org.apache.commons.io.IOUtils;
-import org.argeo.api.cms.CmsTheme;
+import org.argeo.api.cms.ux.CmsTheme;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 
@@ -42,6 +43,8 @@ public class BundleCmsTheme implements CmsTheme {
 
 //     private final static Log log = LogFactory.getLog(BundleCmsTheme.class);
 
+       private CmsTheme parentTheme;
+
        private String themeId;
        private Set<String> webCssPaths = new TreeSet<>();
        private Set<String> rapCssPaths = new TreeSet<>();
@@ -52,7 +55,7 @@ public class BundleCmsTheme implements CmsTheme {
        private String headerCss;
        private List<String> fonts = new ArrayList<>();
 
-       private String bodyHtml="<body></body>";
+       private String bodyHtml = "<body></body>";
 
        private String basePath;
        private String styleCssPath;
@@ -61,7 +64,8 @@ public class BundleCmsTheme implements CmsTheme {
 //     private String swtCssPath;
        private Bundle themeBundle;
 
-       private Integer defaultIconSize = 16;
+       private Integer smallIconSize = 16;
+       private Integer bigIconSize = 32;
 
        public BundleCmsTheme() {
 
@@ -137,7 +141,7 @@ public class BundleCmsTheme implements CmsTheme {
                if (bodyUrl != null) {
                        loadBodyHtml(bodyUrl);
                }
-}
+       }
 
        public String getHtmlHeaders() {
                StringBuilder sb = new StringBuilder();
@@ -156,8 +160,6 @@ public class BundleCmsTheme implements CmsTheme {
                else
                        return sb.toString();
        }
-       
-       
 
        @Override
        public String getBodyHtml() {
@@ -211,7 +213,7 @@ public class BundleCmsTheme implements CmsTheme {
 
        void loadBodyHtml(URL url) {
                try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), UTF_8))) {
-               bodyHtml=       IOUtils.toString(url,StandardCharsets.UTF_8);
+                       bodyHtml = IOUtils.toString(url, StandardCharsets.UTF_8);
                } catch (IOException e) {
                        throw new IllegalArgumentException("Cannot load URL " + url, e);
                }
@@ -260,10 +262,11 @@ public class BundleCmsTheme implements CmsTheme {
                URL res = themeBundle.getEntry(resourceName);
                if (res == null) {
                        res = themeBundle.getResource(resourceName);
-                       if (res == null)
-                               return null;
-//                             throw new IllegalArgumentException(
-//                                             "Resource " + resourceName + " not found in bundle " + themeBundle.getSymbolicName());
+                       if (res == null) {
+                               if (parentTheme == null)
+                                       return null;
+                               return parentTheme.getResourceAsStream(resourceName);
+                       }
                }
                return res.openStream();
        }
@@ -272,43 +275,43 @@ public class BundleCmsTheme implements CmsTheme {
                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 getRapCssPath() {
-//             return rapCssPath;
-//     }
-//
-//     public void setRapCssPath(String cssPath) {
-//             this.rapCssPath = cssPath;
-//     }
-
        @Override
        public Set<String> getWebCssPaths() {
+               if (parentTheme != null) {
+                       Set<String> res = new HashSet<>(parentTheme.getWebCssPaths());
+                       res.addAll(webCssPaths);
+                       return res;
+               }
                return webCssPaths;
        }
 
        @Override
        public Set<String> getRapCssPaths() {
+               if (parentTheme != null) {
+                       Set<String> res = new HashSet<>(parentTheme.getRapCssPaths());
+                       res.addAll(rapCssPaths);
+                       return res;
+               }
                return rapCssPaths;
        }
 
        @Override
        public Set<String> getSwtCssPaths() {
+               if (parentTheme != null) {
+                       Set<String> res = new HashSet<>(parentTheme.getSwtCssPaths());
+                       res.addAll(swtCssPaths);
+                       return res;
+               }
                return swtCssPaths;
        }
 
        @Override
        public Set<String> getImagesPaths() {
+               if (parentTheme != null) {
+                       Set<String> res = new HashSet<>(parentTheme.getImagesPaths());
+                       res.addAll(imagesPaths);
+                       return res;
+               }
                return imagesPaths;
        }
 
@@ -318,17 +321,27 @@ public class BundleCmsTheme implements CmsTheme {
        }
 
        @Override
-       public Integer getDefaultIconSize() {
-               return defaultIconSize;
+       public int getSmallIconSize() {
+               return smallIconSize;
+       }
+
+       @Override
+       public int getBigIconSize() {
+               return bigIconSize;
        }
 
        @Override
        public InputStream loadPath(String path) throws IOException {
                URL url = themeBundle.getResource(path);
-               if (url == null)
-                       throw new IllegalArgumentException(
-                                       "Path " + path + " not found in bundle " + themeBundle.getSymbolicName());
-               return url.openStream();
+               if (url == null) {
+                       if (parentTheme != null)
+                               return parentTheme.loadPath(path);
+                       else
+                               throw new IllegalArgumentException(
+                                               "Path " + path + " not found in bundle " + themeBundle.getSymbolicName());
+               } else {
+                       return url.openStream();
+               }
        }
 
        private static Bundle findThemeBundle(BundleContext bundleContext, String themeId) {
@@ -357,4 +370,8 @@ public class BundleCmsTheme implements CmsTheme {
                return "Bundle CMS Theme " + themeId;
        }
 
+       public void setParentTheme(CmsTheme parentTheme) {
+               this.parentTheme = parentTheme;
+       }
+
 }