Search in sources :

Example 6 with Theme

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;
}
Also used : ModuleThemeInfo(org.pentaho.platform.api.ui.ModuleThemeInfo) Theme(org.pentaho.platform.api.ui.Theme)

Example 7 with 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);
    }
}
Also used : InputStream(java.io.InputStream) SAXReader(org.dom4j.io.SAXReader) MissingResourceException(java.util.MissingResourceException) Element(org.dom4j.Element) ModuleThemeInfo(org.pentaho.platform.api.ui.ModuleThemeInfo) Theme(org.pentaho.platform.api.ui.Theme) ThemeResource(org.pentaho.platform.api.ui.ThemeResource) ResourceBundle(java.util.ResourceBundle) Document(org.dom4j.Document) MissingResourceException(java.util.MissingResourceException)

Example 8 with Theme

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;
}
Also used : HashMap(java.util.HashMap) Theme(org.pentaho.platform.api.ui.Theme)

Aggregations

Theme (org.pentaho.platform.api.ui.Theme)8 ModuleThemeInfo (org.pentaho.platform.api.ui.ModuleThemeInfo)5 ThemeResource (org.pentaho.platform.api.ui.ThemeResource)4 HashMap (java.util.HashMap)3 InputStream (java.io.InputStream)2 ResourceBundle (java.util.ResourceBundle)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 SAXReader (org.dom4j.io.SAXReader)2 IUserSettingService (org.pentaho.platform.api.usersettings.IUserSettingService)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 MissingResourceException (java.util.MissingResourceException)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 IThemeManager (org.pentaho.platform.api.ui.IThemeManager)1 IThemeResolver (org.pentaho.platform.api.ui.IThemeResolver)1