Search in sources :

Example 1 with IThemeManager

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;
}
Also used : ArrayList(java.util.ArrayList) IThemeManager(org.pentaho.platform.api.ui.IThemeManager) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Facet(org.codehaus.enunciate.Facet)

Example 2 with IThemeManager

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());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) IThemeManager(org.pentaho.platform.api.ui.IThemeManager) ThemeResource(org.pentaho.platform.api.ui.ThemeResource) File(java.io.File) MockServletContext(com.mockrunner.mock.web.MockServletContext) FileInputStream(java.io.FileInputStream) BaseTest(org.pentaho.test.platform.engine.core.BaseTest) Test(org.junit.Test)

Example 3 with IThemeManager

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());
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IThemeManager(org.pentaho.platform.api.ui.IThemeManager) Theme(org.pentaho.platform.api.ui.Theme) ServletContext(javax.servlet.ServletContext) ThemeResource(org.pentaho.platform.api.ui.ThemeResource)

Example 4 with IThemeManager

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();
    }
}
Also used : IUserSettingService(org.pentaho.platform.api.usersettings.IUserSettingService) IThemeManager(org.pentaho.platform.api.ui.IThemeManager) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) StatusCodes(org.codehaus.enunciate.jaxrs.StatusCodes) Facet(org.codehaus.enunciate.Facet)

Aggregations

IThemeManager (org.pentaho.platform.api.ui.IThemeManager)4 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Facet (org.codehaus.enunciate.Facet)2 ThemeResource (org.pentaho.platform.api.ui.ThemeResource)2 IUserSettingService (org.pentaho.platform.api.usersettings.IUserSettingService)2 MockServletContext (com.mockrunner.mock.web.MockServletContext)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 ServletContext (javax.servlet.ServletContext)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 StatusCodes (org.codehaus.enunciate.jaxrs.StatusCodes)1 Test (org.junit.Test)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 IPluginManager (org.pentaho.platform.api.engine.IPluginManager)1 Theme (org.pentaho.platform.api.ui.Theme)1 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)1