Search in sources :

Example 6 with ModuleThemeInfo

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);
    }
}
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)

Aggregations

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