public void processEvent(SystemEvent event) throws AbortProcessingException { FacesContext context = FacesContext.getCurrentInstance(); ExternalContext externalContext = context.getExternalContext(); Theme theme = (Theme) externalContext.getSessionMap().get(MOBI_THEME_KEY); boolean prod = context.isProjectStage(ProjectStage.Production); String name = CSSUtils.getThemeCSSFileName(theme, prod); String library = deriveLibrary(context.getAttributes()); UIComponent resource = createThemeResource(context, library, name); context.getViewRoot().addComponentResource(context, resource); }
private void writeOutDeviceStyleSheets( FacesContext facesContext, DeviceResource comp, Theme theme) throws IOException { /** * The component has three modes in which it executes. 1.) no attributes - then component tries * to detect a mobile device in from the user-agent. If a mobile device is discovered, then it * will fall into three possible matches, iphone, ipad, android and blackberry. If the mobile * device is not not know then ipad is loaded. Library is always assumed to be DEFAULT_LIBRARY. * * <p>2.) name attribute - component will default to using a library name of DEFAULT_LIBRARY. * The name attribute specifies one of the possible device themes; iphone.css, android.css or * bberry.css. Error will result if named resource could not be resolved. * * <p>3.) name and libraries attributes. - component will use the library and name specified by * the user. Component is fully manual in this mode. Error will result if name and library can * not generate a value resource. */ boolean prod = facesContext.isProjectStage(ProjectStage.Production); String cssFile = CSSUtils.getThemeCSSFileName(theme, prod); String library = deriveLibrary(facesContext.getAttributes()); Resource resource = facesContext .getApplication() .getResourceHandler() .createResource(cssFile, library, "text/css"); String resourceUrl = RESOURCE_URL_ERROR; if (resource != null) { resourceUrl = facesContext.getExternalContext().encodeResourceURL(resource.getRequestPath()); } else if (log.isLoggable(Level.WARNING)) { log.warning("Warning could not load resource " + library + "/" + theme); } ResponseWriter writer = facesContext.getResponseWriter(); writer.startElement(HTML.LINK_ELEM, comp); writer.writeAttribute(HTML.TYPE_ATTR, HTML.LINK_TYPE_TEXT_CSS, HTML.TYPE_ATTR); writer.writeAttribute(HTML.REL_ATTR, HTML.STYLE_REL_STYLESHEET, HTML.REL_ATTR); PassThruAttributeWriter.renderNonBooleanAttributes( writer, comp, new Attribute[] {new Attribute("media", null)}); writer.writeURIAttribute(HTML.HREF_ATTR, resourceUrl, HTML.HREF_ATTR); writer.endElement(HTML.LINK_ELEM); }
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException { // http://javaserverfaces.java.net/nonav/docs/2.0/pdldocs/facelets/index.html // Finally make sure the component is only rendered in the header of the // HTML document. UIComponent component = event.getComponent(); FacesContext context = FacesContext.getCurrentInstance(); if (log.isLoggable(Level.FINER)) { log.finer("processEvent for component = " + component.getClass().getName()); } context.getViewRoot().addComponentResource(context, component, HTML.HEAD_ELEM); ClientDescriptor client = ClientDescriptor.getInstance( (HttpServletRequest) context.getExternalContext().getRequest()); String themeParam = context.getExternalContext().getRequestParameterMap().get("theme"); Theme theme = null; if (client.isIE9orLessBrowser()) { theme = Theme.ARCHAIC; } else { theme = Theme.getEnum( themeParam != null ? themeParam : (String) event.getComponent().getAttributes().get("theme")); if (theme == null) { String targetView = (String) event.getComponent().getAttributes().get("view"); theme = CSSUtils.deriveTheme(targetView, JSFUtils.getRequest()); } } // android and honeycomb themes deprecated if (theme == Theme.ANDROID || theme == Theme.HONEYCOMB) { theme = Theme.ANDROID_DARK; } context.getExternalContext().getSessionMap().put(MOBI_THEME_KEY, theme); }