X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Fosgi%2FBundleCmsTheme.java;h=f60d3352e98c61c921b260c7be244183b91c085b;hb=54df376a9c2dd458a82eaa09bfbb718fe699dd0d;hp=3ab799f713e1ab9e802a20654efc81426c7de5b7;hpb=df60fd8de17590b8f4ab32fd0278e57aaaedbfa2;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/osgi/BundleCmsTheme.java b/org.argeo.cms/src/org/argeo/cms/osgi/BundleCmsTheme.java index 3ab799f71..f60d3352e 100644 --- a/org.argeo.cms/src/org/argeo/cms/osgi/BundleCmsTheme.java +++ b/org.argeo.cms/src/org/argeo/cms/osgi/BundleCmsTheme.java @@ -7,7 +7,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashSet; @@ -17,8 +16,8 @@ import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; -import org.apache.commons.io.IOUtils; import org.argeo.api.cms.ux.CmsTheme; +import org.argeo.cms.util.StreamUtils; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -32,11 +31,17 @@ import org.osgi.framework.BundleContext; * / ** /*.{png,gif,jpeg,...}.
*/ public class BundleCmsTheme implements CmsTheme { - public final static String DEFAULT_CMS_THEME_BUNDLE = "org.argeo.theme.argeo2"; +// public final static String DEFAULT_CMS_THEME_BUNDLE = "org.argeo.theme.argeo2"; - public final static String CMS_THEME_PROPERTY = "argeo.cms.theme"; +// public final static String CMS_THEME_PROPERTY = "argeo.cms.theme"; + @Deprecated public final static String CMS_THEME_BUNDLE_PROPERTY = "argeo.cms.theme.bundle"; + /** Declared theme ID, to be used by OSGi services to reference it as parent. */ + public final static String THEME_ID_PROPERTY = "themeId"; + public final static String SMALL_ICON_SIZE_PROPERTY = "smallIconSize"; + public final static String BIG_ICON_SIZE_PROPERTY = "bigIconSize"; + private final static String HEADER_CSS = "header.css"; private final static String FONTS_TXT = "fonts.txt"; private final static String BODY_HTML = "body.html"; @@ -46,6 +51,8 @@ public class BundleCmsTheme implements CmsTheme { private CmsTheme parentTheme; private String themeId; + private String declaredThemeId;; + private Set webCssPaths = new TreeSet<>(); private Set rapCssPaths = new TreeSet<>(); private Set swtCssPaths = new TreeSet<>(); @@ -72,6 +79,12 @@ public class BundleCmsTheme implements CmsTheme { } public void init(BundleContext bundleContext, Map properties) { + declaredThemeId = properties.get(THEME_ID_PROPERTY); + if (properties.containsKey(SMALL_ICON_SIZE_PROPERTY)) + smallIconSize = Integer.valueOf(properties.get(SMALL_ICON_SIZE_PROPERTY)); + if (properties.containsKey(BIG_ICON_SIZE_PROPERTY)) + smallIconSize = Integer.valueOf(properties.get(BIG_ICON_SIZE_PROPERTY)); + initResources(bundleContext, null); } @@ -104,6 +117,10 @@ public class BundleCmsTheme implements CmsTheme { // swtCssPath = "/swt/"; // this.themeId = RWT.DEFAULT_THEME_ID; this.themeId = themeBundle.getSymbolicName(); + if (declaredThemeId != null && !declaredThemeId.equals(themeId)) + throw new IllegalArgumentException( + "Declared theme id " + declaredThemeId + " is different from " + themeId); + webCssPaths = addCss(themeBundle, "/css/"); rapCssPaths = addCss(themeBundle, "/rap/"); swtCssPaths = addCss(themeBundle, "/swt/"); @@ -213,7 +230,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 = StreamUtils.toString(in); } catch (IOException e) { throw new IllegalArgumentException("Cannot load URL " + url, e); } @@ -374,4 +391,12 @@ public class BundleCmsTheme implements CmsTheme { this.parentTheme = parentTheme; } + public void setSmallIconSize(Integer smallIconSize) { + this.smallIconSize = smallIconSize; + } + + public void setBigIconSize(Integer bigIconSize) { + this.bigIconSize = bigIconSize; + } + }