X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms.ui%2Fsrc%2Forg%2Fargeo%2Fcms%2Fui%2Futil%2FBundleCmsTheme.java;h=9a3cf9d47d87b653fcb5de6d346284e27950dc2c;hb=c5d120d226b31b3d930fc3006c56ac9e4d29ed2a;hp=a4749fbabe150f4624782f45ead79e274dc7fd1f;hpb=ed21871d5963cd7a53c96b23f2e81ec78416001d;p=lgpl%2Fargeo-commons.git 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 a4749fbab..9a3cf9d47 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 @@ -33,6 +33,9 @@ public class BundleCmsTheme extends AbstractCmsTheme { public final static String CMS_THEME_PROPERTY = "argeo.cms.theme"; public final static String CMS_THEME_BUNDLE_PROPERTY = "argeo.cms.theme.bundle"; + private final static String HEADER_CSS = "header.css"; + private final static String FONTS_TXT = "fonts.txt"; + // private final static Log log = LogFactory.getLog(BundleCmsTheme.class); private String themeId; @@ -40,6 +43,7 @@ public class BundleCmsTheme extends AbstractCmsTheme { private Set rapCssPaths = new TreeSet<>(); private Set swtCssPaths = new TreeSet<>(); private Set imagesPaths = new TreeSet<>(); + private Set fontsPaths = new TreeSet<>(); private String headerCss; private List fonts = new ArrayList<>(); @@ -91,22 +95,28 @@ public class BundleCmsTheme extends AbstractCmsTheme { webCssPaths = addCss(themeBundle, "/css/"); rapCssPaths = addCss(themeBundle, "/rap/"); swtCssPaths = addCss(themeBundle, "/swt/"); - addResources("*.png"); - addResources("*.gif"); - addResources("*.jpg"); - addResources("*.jpeg"); - addResources("*.svg"); - addResources("*.ico"); + addImages("*.png"); + addImages("*.gif"); + addImages("*.jpg"); + addImages("*.jpeg"); + addImages("*.svg"); + addImages("*.ico"); + + addFonts("*.woff"); + addFonts("*.woff2"); // fonts - URL fontsUrl = themeBundle.getEntry(basePath + "fonts.txt"); + URL fontsUrl = themeBundle.getEntry(basePath + FONTS_TXT); if (fontsUrl != null) { loadFontsUrl(fontsUrl); } // common CSS header (plain CSS) - URL headerCssUrl = themeBundle.getEntry(basePath + "header.css"); + URL headerCssUrl = themeBundle.getEntry(basePath + HEADER_CSS); if (headerCssUrl != null) { + // added to plain Web CSS + webCssPaths.add(basePath + HEADER_CSS); + // and it will also be used by RAP: try (BufferedReader buffer = new BufferedReader(new InputStreamReader(headerCssUrl.openStream(), UTF_8))) { headerCss = buffer.lines().collect(Collectors.joining("\n")); } catch (IOException e) { @@ -135,28 +145,30 @@ public class BundleCmsTheme extends AbstractCmsTheme { Set addCss(Bundle themeBundle, String path) { Set paths = new TreeSet<>(); - Enumeration themeResources = themeBundle.findEntries(path, "*.css", true); - if (themeResources == null) - return paths; - while (themeResources.hasMoreElements()) { - String resource = themeResources.nextElement().getPath(); - // remove first '/' so that RWT registers it - resource = resource.substring(1); - if (!resource.endsWith("/")) { - paths.add(resource); - } - } // common CSS Enumeration commonResources = themeBundle.findEntries(styleCssPath, "*.css", true); - if (commonResources == null) - return paths; - while (commonResources.hasMoreElements()) { - String resource = commonResources.nextElement().getPath(); - // remove first '/' so that RWT registers it - resource = resource.substring(1); - if (!resource.endsWith("/")) { - paths.add(resource); + if (commonResources != null) { + while (commonResources.hasMoreElements()) { + String resource = commonResources.nextElement().getPath(); + // remove first '/' so that RWT registers it + resource = resource.substring(1); + if (!resource.endsWith("/")) { + paths.add(resource); + } + } + } + + // specific CSS + Enumeration themeResources = themeBundle.findEntries(path, "*.css", true); + if (themeResources != null) { + while (themeResources.hasMoreElements()) { + String resource = themeResources.nextElement().getPath(); + // remove first '/' so that RWT registers it + resource = resource.substring(1); + if (!resource.endsWith("/")) { + paths.add(resource); + } } } return paths; @@ -176,7 +188,7 @@ public class BundleCmsTheme extends AbstractCmsTheme { } } - void addResources(String pattern) { + void addImages(String pattern) { Enumeration themeResources = themeBundle.findEntries(basePath, pattern, true); if (themeResources == null) return; @@ -195,6 +207,25 @@ public class BundleCmsTheme extends AbstractCmsTheme { } + void addFonts(String pattern) { + Enumeration themeResources = themeBundle.findEntries(basePath, pattern, true); + if (themeResources == null) + return; + while (themeResources.hasMoreElements()) { + String resource = themeResources.nextElement().getPath(); + // remove first '/' so that RWT registers it + resource = resource.substring(1); + if (!resource.endsWith("/")) { +// if (resources.containsKey(resource)) +// log.warn("Overriding " + resource + " from " + themeBundle.getSymbolicName()); +// resources.put(resource, themeBRL); + fontsPaths.add(resource); + } + + } + + } + @Override public InputStream getResourceAsStream(String resourceName) throws IOException { URL res = themeBundle.getEntry(resourceName); @@ -252,6 +283,11 @@ public class BundleCmsTheme extends AbstractCmsTheme { return imagesPaths; } + @Override + public Set getFontsPaths() { + return fontsPaths; + } + @Override public InputStream loadPath(String path) throws IOException { URL url = themeBundle.getResource(path); @@ -277,4 +313,14 @@ public class BundleCmsTheme extends AbstractCmsTheme { return themeBundle; } + @Override + public int hashCode() { + return themeId.hashCode(); + } + + @Override + public String toString() { + return "Bundle CMS Theme " + themeId; + } + }