Search in sources :

Example 1 with ThemeContext

use of com.sun.webui.theme.ThemeContext in project Payara by payara.

the class AdminguiThemeContext method getInstance.

/**
 *	<p> Return an instance of <code>ThemeContext</code> creating one
 *	    if necessary and persisting it in the <code>ApplicationMap</code>.
 */
public static synchronized ThemeContext getInstance(FacesContext context, String themeName, String themeVersion) {
    Map map = context.getExternalContext().getApplicationMap();
    String themeKey = THEME_CONTEXT + themeName + themeVersion;
    ThemeContext themeContext = (ThemeContext) map.get(themeKey);
    if (themeContext == null) {
        themeContext = new AdminguiThemeContext(themeName, themeVersion);
        map.put(themeKey, themeContext);
    }
    return themeContext;
}
Also used : ThemeContext(com.sun.webui.theme.ThemeContext) JSFThemeContext(com.sun.webui.jsf.theme.JSFThemeContext) ServletThemeContext(com.sun.webui.theme.ServletThemeContext) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with ThemeContext

use of com.sun.webui.theme.ThemeContext in project Payara by payara.

the class AdminguiThemeContext method getInstance.

/**
 *	<p> Return an instance of <code>ThemeContext</code>
 *	    using properties provided via <code>Integration point</code>.
 */
public static synchronized ThemeContext getInstance(FacesContext context, Properties propMap) {
    Map map = context.getExternalContext().getApplicationMap();
    String themeName = (String) propMap.get(THEME_NAME_KEY);
    String themeVersion = (String) propMap.get(THEME_VERSION_KEY);
    String themeKey = THEME_CONTEXT + themeName + themeVersion;
    ThemeContext themeContext = (ThemeContext) map.get(themeKey);
    if (themeContext == null) {
        themeContext = new AdminguiThemeContext(themeName, themeVersion);
        map.put(themeKey, themeContext);
    }
    return themeContext;
}
Also used : ThemeContext(com.sun.webui.theme.ThemeContext) JSFThemeContext(com.sun.webui.jsf.theme.JSFThemeContext) ServletThemeContext(com.sun.webui.theme.ServletThemeContext) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with ThemeContext

use of com.sun.webui.theme.ThemeContext in project Payara by payara.

the class ThemeHandlers method getTheme.

/**
 *	<p> This method initializes the theme using the given
 *	    <code>themeName</code> and <code>themeVersion</code>.  If these
 *	    values are not supplied, "suntheme" and "4.2" will be used
 *	    respectively.  This method should be invoked before the theme is
 *	    accessed (for example on the initPage or beforeCreate of the login
 *	    page).</p>
 */
@Handler(id = "getTheme", input = { @HandlerInput(name = "themeName", type = String.class), @HandlerInput(name = "themeVersion", type = String.class) }, output = { @HandlerOutput(name = "themeContext", type = ThemeContext.class) })
public static void getTheme(HandlerContext handlerCtx) {
    String themeName = (String) handlerCtx.getInputValue("themeName");
    String themeVersion = (String) handlerCtx.getInputValue("themeVersion");
    ThemeContext themeContext = AdminguiThemeContext.getInstance(handlerCtx.getFacesContext(), themeName, themeVersion);
    handlerCtx.setOutputValue("themeContext", themeContext);
}
Also used : AdminguiThemeContext(org.glassfish.admingui.theme.AdminguiThemeContext) ThemeContext(com.sun.webui.theme.ThemeContext) Handler(com.sun.jsftemplating.annotation.Handler)

Example 4 with ThemeContext

use of com.sun.webui.theme.ThemeContext in project Payara by payara.

the class ThemeHandlers method getThemeFromIntegrationPoints.

/**
 *	<p> This method gets the <code>themeName</code> and <code>themeVersion</code>
 *	    via <code>Integration Point</code>.  If more than one is provided
 *	    the one with the lowest <code>priority</code> number will be used.
 *	    This method should be invoked before the theme is
 *	    accessed (for example on the initPage or beforeCreate of the login page).</p>
 */
@Handler(id = "getThemeFromIntegrationPoints", output = { @HandlerOutput(name = "themeContext", type = ThemeContext.class) })
public static void getThemeFromIntegrationPoints(HandlerContext handlerCtx) {
    FacesContext ctx = handlerCtx.getFacesContext();
    String type = "org.glassfish.admingui:customtheme";
    List<IntegrationPoint> ipList = PluginHandlers.getIntegrationPoints(ctx, type);
    if (ipList != null) {
        // if more than one integration point is provided then we
        // need to find the lowest priority number
        int lowest = getLowestPriorityNum(ipList);
        for (IntegrationPoint ip : ipList) {
            int priority = ip.getPriority();
            if (priority == lowest) {
                String content = ip.getContent();
                if (content == null || content.equals("")) {
                    throw new IllegalArgumentException("No Properties File Name Provided!");
                }
                ClassLoader pluginCL = ConsoleClassLoader.findModuleClassLoader(ip.getConsoleConfigId());
                URL propertyFileURL = pluginCL.getResource("/" + content);
                try {
                    Properties propertyMap = new Properties();
                    propertyMap.load(propertyFileURL.openStream());
                    ThemeContext themeContext = AdminguiThemeContext.getInstance(ctx, propertyMap);
                    themeContext.setDefaultClassLoader(pluginCL);
                    handlerCtx.setOutputValue("themeContext", themeContext);
                } catch (Exception ex) {
                    throw new RuntimeException("Unable to access properties file '" + content + "'!", ex);
                }
            }
        }
    }
}
Also used : AdminguiThemeContext(org.glassfish.admingui.theme.AdminguiThemeContext) ThemeContext(com.sun.webui.theme.ThemeContext) FacesContext(javax.faces.context.FacesContext) ConsoleClassLoader(org.glassfish.admingui.common.plugin.ConsoleClassLoader) IntegrationPoint(org.glassfish.admingui.connector.IntegrationPoint) Properties(java.util.Properties) IntegrationPoint(org.glassfish.admingui.connector.IntegrationPoint) URL(java.net.URL) Handler(com.sun.jsftemplating.annotation.Handler)

Aggregations

ThemeContext (com.sun.webui.theme.ThemeContext)4 Handler (com.sun.jsftemplating.annotation.Handler)2 JSFThemeContext (com.sun.webui.jsf.theme.JSFThemeContext)2 ServletThemeContext (com.sun.webui.theme.ServletThemeContext)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AdminguiThemeContext (org.glassfish.admingui.theme.AdminguiThemeContext)2 URL (java.net.URL)1 Properties (java.util.Properties)1 FacesContext (javax.faces.context.FacesContext)1 ConsoleClassLoader (org.glassfish.admingui.common.plugin.ConsoleClassLoader)1 IntegrationPoint (org.glassfish.admingui.connector.IntegrationPoint)1