use of org.pentaho.platform.api.ui.IThemeManager in project pentaho-platform by pentaho.
the class ThemeResource method getSystemThemes.
/**
* List the current supported themes in the platform
*
* @return list of themes
*/
@GET
@Path("/list")
@Produces({ APPLICATION_JSON, APPLICATION_XML })
@Facet(name = "Unsupported")
public List<Theme> getSystemThemes() {
ArrayList<Theme> themes = new ArrayList<Theme>();
IThemeManager themeManager = PentahoSystem.get(IThemeManager.class);
List<String> ids = themeManager.getSystemThemeIds();
for (String id : ids) {
org.pentaho.platform.api.ui.Theme theme = themeManager.getSystemTheme(id);
if (theme.isHidden() == false) {
themes.add(new Theme(id, theme.getName()));
}
}
return themes;
}
use of org.pentaho.platform.api.ui.IThemeManager in project pentaho-platform by pentaho.
the class ThemeManagerIT method testThemes.
@Test
public void testThemes() throws Exception {
// setup mock context
MockServletContext context = new MockServletContext();
context.addResourcePaths("/", Arrays.asList("test-module/"));
context.addResourcePaths("/test-module/", Arrays.asList("themes.xml"));
File themesDotXML = new File(getSolutionPath() + "/system/themeplugin/themes.xml");
context.setResource("/test-module/themes.xml", themesDotXML.toURI().toURL());
context.setResourceAsStream("/test-module/themes.xml", new FileInputStream(themesDotXML));
PentahoSystem.getApplicationContext().setContext(context);
StandaloneSession session = new StandaloneSession();
PentahoSessionHolder.setSession(session);
PentahoSystem.get(IPluginManager.class).reload();
IThemeManager themeManager = PentahoSystem.get(IThemeManager.class);
assertTrue(themeManager.getSystemThemeIds().contains("core"));
assertNotNull(themeManager.getModuleThemeInfo("themeplugin"));
assertEquals(1, themeManager.getModuleThemeInfo("themeplugin").getSystemThemes().size());
Set<ThemeResource> resources = themeManager.getModuleThemeInfo("themeplugin").getSystemThemes().get(0).getResources();
assertEquals(3, resources.size());
assertNotNull(themeManager.getModuleThemeInfo("test-module"));
assertEquals(1, themeManager.getModuleThemeInfo("test-module").getSystemThemes().size());
resources = themeManager.getModuleThemeInfo("test-module").getSystemThemes().get(0).getResources();
assertEquals(3, resources.size());
}
use of org.pentaho.platform.api.ui.IThemeManager 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.IThemeManager in project pentaho-platform by pentaho.
the class ThemeResource method setTheme.
/**
* Set the current theme to the one provided in this request
*
* @param theme (theme to be changed to)
*
* @return
*/
@POST
@Path("/set")
@Consumes({ WILDCARD })
@StatusCodes({ @ResponseCode(code = 200, condition = "Successfully set theme."), @ResponseCode(code = 403, condition = "Illegal set operation.") })
@Produces("text/plain")
@Facet(name = "Unsupported")
public Response setTheme(String theme) {
IThemeManager themeManager = PentahoSystem.get(IThemeManager.class);
List<String> ids = themeManager.getSystemThemeIds();
if ((ids != null) && (ids.indexOf(theme) >= 0)) {
getPentahoSession().setAttribute("pentaho-user-theme", theme);
IUserSettingService settingsService = PentahoSystem.get(IUserSettingService.class, getPentahoSession());
settingsService.setUserSetting("pentaho-user-theme", theme);
return getActiveTheme();
} else {
// Prevent log forging/injection
String cleanTheme = theme.replace('\n', ' ').replace('\r', ' ');
// We do not want to NLS-ize this message
logger.error("Attempt to set invalid theme: " + cleanTheme);
return Response.status(Response.Status.FORBIDDEN).entity("").build();
}
}
Aggregations