use of org.pentaho.platform.api.ui.Theme in project pentaho-platform by pentaho.
the class DefaultThemeManager method getModuleTheme.
public Theme getModuleTheme(String moduleName, String themeId) {
if (themeId == null) {
return null;
}
Theme theme = null;
ModuleThemeInfo moduleThemeInfo = (ModuleThemeInfo) cache.getFromRegionCache(THEME_CACHE_REGION, MODULE_THEMES + "-" + moduleName);
if (moduleThemeInfo == null) {
// may have been flushed, try to fetch it
moduleThemeInfo = collectAllModuleThemes().get(moduleName);
if (moduleThemeInfo == null) {
logger.debug("Unable to retrieve module theme for (" + moduleName + ") as the module theme definition was not found");
return null;
}
}
for (Theme t : moduleThemeInfo.getModuleThemes()) {
if (t.getId().equals(themeId)) {
theme = t;
break;
}
}
if (theme == null) {
logger.error(MessageFormat.format("Unable to find requested module theme: %s module: %s", themeId, moduleName));
}
return theme;
}
use of org.pentaho.platform.api.ui.Theme 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);
}
}
use of org.pentaho.platform.api.ui.Theme in project pentaho-platform by pentaho.
the class ServletContextThemeResolver method getSystemThemes.
public Map<String, Theme> getSystemThemes() {
resolveThemes();
Map<String, Theme> systemThemes = new HashMap<String, Theme>();
// Loop through other modules and add their system themes.
for (String module : moduleThemes.keySet()) {
for (Theme theme : moduleThemes.get(module).getSystemThemes()) {
systemThemes.put(theme.getId(), theme);
}
}
return systemThemes;
}
Aggregations