use of org.pentaho.platform.api.ui.Theme in project pentaho-platform by pentaho.
the class ThemeServlet method handleRequest.
public void handleRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
// look for a passed in theme context (content generator, other named area)
String moduleName = req.getParameter("context");
OutputStream out = resp.getOutputStream();
// $NON-NLS-1$
resp.setContentType("text/javascript");
// $NON-NLS-1$
resp.setHeader("Cache-Control", "no-cache");
IUserSettingService settingsService = PentahoSystem.get(IUserSettingService.class, getPentahoSession(req));
// NOTE: this code should be kept in sync with that of PentahoWebContextFilter.java
String activeTheme = (String) getPentahoSession(req).getAttribute("pentaho-user-theme");
String ua = req.getHeader("User-Agent");
// check if we're coming from a mobile device, if so, lock to system default (ruby)
if (!StringUtils.isEmpty(ua) && ua.matches(".*(?i)(iPad|iPod|iPhone|Android).*")) {
activeTheme = PentahoSystem.getSystemSetting("default-theme", "ruby");
}
if (activeTheme == null) {
try {
activeTheme = settingsService.getUserSetting("pentaho-user-theme", null).getSettingValue();
} catch (Exception ignored) {
// the user settings service is not valid in the agile-bi deployment of the
// server
}
if (activeTheme == null) {
activeTheme = PentahoSystem.getSystemSetting("default-theme", "ruby");
}
}
out.write(("\n\n// Theming scripts. This file is generated by (" + getClass().getName() + ") and cannot be found on disk\n").getBytes());
out.write(("var active_theme = \"" + activeTheme + "\";\n\n").getBytes());
// Build-up JSON graph for system theme.
JSONObject root = new JSONObject();
JSONObject themeObject;
for (String systemThemeName : themeManager.getSystemThemeIds()) {
Theme theme = themeManager.getSystemTheme(systemThemeName);
themeObject = new JSONObject();
root.put(theme.getId(), themeObject);
themeObject.put("rootDir", theme.getThemeRootDir());
for (ThemeResource res : theme.getResources()) {
themeObject.append("resources", res.getLocation());
}
}
out.write(("var core_theme_tree = " + root.toString() + ";\n\n").getBytes());
out.write("// Inject the theme script to handle the insertion of requested theme resources\n\n".getBytes());
ModuleThemeInfo moduleThemeinfo = themeManager.getModuleThemeInfo(moduleName);
if (moduleThemeinfo != null) {
// Build-up JSON graph for module theme.
root = new JSONObject();
for (Theme theme : moduleThemeinfo.getModuleThemes()) {
themeObject = new JSONObject();
root.put(theme.getName(), themeObject);
themeObject.put("rootDir", theme.getThemeRootDir());
for (ThemeResource res : theme.getResources()) {
themeObject.append("resources", res.getLocation());
}
}
out.write(("var module_theme_tree = " + root.toString() + ";\n\n").getBytes());
}
// createElement & insertBefore
out.write(("(function() {\n" + "var script = document.createElement('script');\n" + "script.type = 'text/javascript';\n" + // "script.async = false;\n" +
"script.src = CONTEXT_PATH + 'js/themeResources.js';\n" + "var existing = document.getElementsByTagName('script')[0];\n" + "existing.parentNode.insertBefore(script, existing);\n" + "}());").getBytes());
} catch (IOException e) {
logger.debug("IO exception creating Theme info", e);
throw new ServletException(e);
} catch (JSONException e) {
logger.debug("JSON exception creating Theme info", e);
throw new ServletException(e);
}
}
use of org.pentaho.platform.api.ui.Theme in project pentaho-platform by pentaho.
the class PluginThemeResolver method findPluginThemes.
private void findPluginThemes(String pluginId) {
try {
InputStream pluginManifestStream = resLoader.getResourceAsStream(pluginManager.getClassLoader(pluginId), "themes.xml");
if (pluginManifestStream == null) {
return;
}
ResourceBundle resourceBundle = null;
try {
resourceBundle = ResourceBundle.getBundle("themes", LocaleHelper.getDefaultLocale(), pluginManager.getClassLoader(pluginId));
} catch (Exception ignored) {
/* optional bundle */
}
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("${")) {
themeName = resourceBundle.getString(themeName);
}
Theme theme = new Theme(themeId, themeName, "content/" + 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 PluginThemeResolver method getSystemThemes.
public Map<String, Theme> getSystemThemes() {
Map<String, Theme> systemThemes = new HashMap<String, Theme>();
// Find the declared default plugin for themes. Add it's themes to the map first. Any that come in later will
// overwrite it.
String defaultThemePlugin = PentahoSystem.getSystemSetting("default-theme-plugin", "userconsole");
ModuleThemeInfo defaultThemePluginInfo = moduleThemes.get(defaultThemePlugin);
if (defaultThemePluginInfo == null) {
logger.debug("Unable to find the default theme plugin: " + defaultThemePlugin);
} else {
// Add all system themes from the default plugin in now.
for (Theme theme : defaultThemePluginInfo.getSystemThemes()) {
systemThemes.put(theme.getId(), theme);
}
}
// theme plugin will override the default.
for (String module : moduleThemes.keySet()) {
if (module.equals(defaultThemePlugin)) {
continue;
}
for (Theme theme : moduleThemes.get(module).getSystemThemes()) {
systemThemes.put(theme.getId(), theme);
}
}
return systemThemes;
}
use of org.pentaho.platform.api.ui.Theme in project pentaho-platform by pentaho.
the class StyledHtmlAxisServiceLister method createContent.
@Override
public void createContent(AxisConfiguration axisConfiguration, ConfigurationContext context, OutputStream out) throws Exception {
// write out the style sheet and the HTML document
// $NON-NLS-1$
out.write("<html>\n<head>".getBytes());
final IPentahoSession session = PentahoSessionHolder.getSession();
IUserSettingService settingsService = PentahoSystem.get(IUserSettingService.class, session);
String activeThemeName;
if (session == null || settingsService == null) {
activeThemeName = PentahoSystem.getSystemSetting("default-activeThemeName", "onyx");
} else {
activeThemeName = StringUtils.defaultIfEmpty((String) session.getAttribute("pentaho-user-activeThemeName"), settingsService.getUserSetting("pentaho-user-activeThemeName", PentahoSystem.getSystemSetting("default-activeThemeName", "onyx")).getSettingValue());
}
IThemeManager themeManager = PentahoSystem.get(IThemeManager.class, null);
Theme theme = themeManager.getSystemTheme(activeThemeName);
final ServletContext servletContext = (ServletContext) PentahoSystem.getApplicationContext().getContext();
if (servletContext != null) {
for (ThemeResource res : theme.getResources()) {
if (res.getLocation().endsWith(".css")) {
out.write(("<link rel=\"stylesheet\" href=\"" + PentahoSystem.getApplicationContext().getFullyQualifiedServerURL() + theme.getThemeRootDir() + res.getLocation() + "\">").getBytes());
}
}
}
// $NON-NLS-1$
out.write("</head>\n<body>\n".getBytes());
// get the list of services from the core ListServices
super.createContent(axisConfiguration, context, out);
// $NON-NLS-1$
out.write("\n</html>\n".getBytes());
}
use of org.pentaho.platform.api.ui.Theme in project pentaho-platform by pentaho.
the class DefaultThemeManager method collectAllSystemThemes.
public Map<String, Theme> collectAllSystemThemes() {
Map<String, Theme> systemThemes = new HashMap<String, Theme>();
for (IThemeResolver resolver : resolvers) {
Map<String, Theme> themes = resolver.getSystemThemes();
for (String themeId : themes.keySet()) {
// populate the cache
cache.putInRegionCache(THEME_CACHE_REGION, SYSTEM_THEMES + "-" + themeId, themes.get(themeId));
}
systemThemes.putAll(themes);
}
return systemThemes;
}
Aggregations