X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Futil%2FBundleCmsTheme.java;h=6b997e6a35c4f0e691b412b1d9129a2759b4ede7;hp=9a3cf9d47d87b653fcb5de6d346284e27950dc2c;hb=958c7142baa531d444d56725609c43c6a1ebd762;hpb=0fff629f700e9a9c742b6fe3874d408bee20ed10 diff --git a/org.argeo.cms.ui/src/org/argeo/cms/ui/util/BundleCmsTheme.java b/org.argeo.cms.ui/src/org/argeo/cms/ui/util/BundleCmsTheme.java index 9a3cf9d47..6b997e6a3 100644 --- a/org.argeo.cms.ui/src/org/argeo/cms/ui/util/BundleCmsTheme.java +++ b/org.argeo.cms.ui/src/org/argeo/cms/ui/util/BundleCmsTheme.java @@ -7,6 +7,7 @@ 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.List; @@ -15,6 +16,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; +import org.apache.commons.io.IOUtils; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; @@ -35,6 +37,7 @@ public class BundleCmsTheme extends AbstractCmsTheme { private final static String HEADER_CSS = "header.css"; private final static String FONTS_TXT = "fonts.txt"; + private final static String BODY_HTML = "body.html"; // private final static Log log = LogFactory.getLog(BundleCmsTheme.class); @@ -48,6 +51,8 @@ public class BundleCmsTheme extends AbstractCmsTheme { private String headerCss; private List fonts = new ArrayList<>(); + private String bodyHtml=""; + private String basePath; private String styleCssPath; // private String webCssPath; @@ -123,7 +128,13 @@ public class BundleCmsTheme extends AbstractCmsTheme { throw new IllegalArgumentException("Cannot read " + headerCssUrl, e); } } - } + + // body + URL bodyUrl = themeBundle.getEntry(basePath + BODY_HTML); + if (bodyUrl != null) { + loadBodyHtml(bodyUrl); + } +} public String getHtmlHeaders() { StringBuilder sb = new StringBuilder(); @@ -142,6 +153,13 @@ public class BundleCmsTheme extends AbstractCmsTheme { else return sb.toString(); } + + + + @Override + public String getBodyHtml() { + return bodyHtml; + } Set addCss(Bundle themeBundle, String path) { Set paths = new TreeSet<>(); @@ -188,6 +206,14 @@ public class BundleCmsTheme extends AbstractCmsTheme { } } + void loadBodyHtml(URL url) { + try (BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream(), UTF_8))) { + bodyHtml= IOUtils.toString(url,StandardCharsets.UTF_8); + } catch (IOException e) { + throw new IllegalArgumentException("Cannot load URL " + url, e); + } + } + void addImages(String pattern) { Enumeration themeResources = themeBundle.findEntries(basePath, pattern, true); if (themeResources == null)