use of org.pentaho.platform.api.ui.ModuleThemeInfo in project pentaho-platform by pentaho.
the class ServletContextThemeResolver method findPluginThemes.
private void findPluginThemes(String pluginId) {
// some implementations return folders without a leading slash, fix it now
if (pluginId.startsWith("/") == false) {
pluginId = "/" + pluginId;
}
try {
InputStream pluginManifestStream = context.getResourceAsStream(pluginId + "themes.xml");
if (pluginManifestStream == null) {
return;
}
ResourceBundle resourceBundle = null;
try {
resourceBundle = ResourceBundle.getBundle("themes", LocaleHelper.getDefaultLocale());
} catch (MissingResourceException ignored) {
// resource bundles are optional
}
// getResourcePaths returns directories with slashes, remove those now
pluginId = pluginId.replace("/", "");
SAXReader rdr = XMLParserFactoryProducer.getSAXReader(null);
Document pluginManifest = rdr.read(pluginManifestStream);
String rootThemeFolder = pluginManifest.getRootElement().attributeValue("root-folder");
// Plugins supplying styles whether local or system must have a root_theme_folder
if (rootThemeFolder == null) {
return;
}
// Things look good. Build-up theme information for this plugin.
ModuleThemeInfo moduleThemeInfo = new ModuleThemeInfo(pluginId);
List<Element> pluginNodes = pluginManifest.getRootElement().elements();
for (Element themeNode : pluginNodes) {
String themeId = themeNode.getName();
String themeName = StringUtils.defaultIfEmpty(themeNode.attributeValue("display-name"), themeId);
if (themeName.startsWith("${") && resourceBundle != null) {
themeName = resourceBundle.getString(themeName);
}
Theme theme = new Theme(themeId, themeName, pluginId + "/" + rootThemeFolder + "/" + themeId + "/");
theme.setHidden("true".equals(themeNode.attributeValue("hidden")));
if ("true".equals(themeNode.attributeValue("system"))) {
moduleThemeInfo.getSystemThemes().add(theme);
} else {
moduleThemeInfo.getModuleThemes().add(theme);
}
List<Element> resourceList = themeNode.elements();
for (Element res : resourceList) {
theme.addResource(new ThemeResource(theme, res.getText()));
}
}
moduleThemes.put(pluginId, moduleThemeInfo);
} catch (Exception e) {
logger.debug("Error parsing plugin themes", e);
}
}
Aggregations