protected boolean isCssResource(FacesContext ctx, UIComponent r) { String rtype = r.getRendererType(); if ("javax.faces.resource.Stylesheet".equals(rtype)) { return true; } if (ResourceBundleRenderer.RENDERER_TYPE.equals(rtype) || PageResourceRenderer.RENDERER_TYPE.equals(rtype)) { String type = (String) r.getAttributes().get("type"); if (ResourceType.css.equals(type) || ResourceType.jsfcss.equals(type)) { return true; } return false; } String name = (String) r.getAttributes().get("name"); if (name == null) { return false; } name = name.toLowerCase(); if (name.contains(".css") || name.contains(".ecss")) { return true; } return false; }
@Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { Map<String, Object> attributes = component.getAttributes(); String name = (String) attributes.get("name"); String type = (String) attributes.get("type"); if (StringUtils.isBlank(type)) { log.error("Cannot encode page with empty type at %s" + component.getClientId()); return; } if (!ResourceType.css.equals(type) && !ResourceType.js.equals(type)) { log.error("Unsupported type '" + type + "' to encode page '" + name + "' at " + component.getClientId()); return; } if (ResourceType.css.equals(type)) { encodeEnd(context, component, ResourceType.css, PAGE_ENDPOINT_PATH + name + ".css"); } else if (ResourceType.js.equals(type)) { encodeEnd(context, component, ResourceType.js, PAGE_ENDPOINT_PATH + name + ".js"); } super.encodeEnd(context, component); }
@Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { Map<String, Object> attributes = component.getAttributes(); String name = (String) attributes.get("name"); String type = (String) attributes.get("type"); WebResourceManager wrm = Framework.getService(WebResourceManager.class); if (StringUtils.isBlank(type)) { log.error("Cannot encode bundle with empty type at %s" + component.getClientId()); return; } if (!ResourceType.css.equals(type) && !ResourceType.js.equals(type) && !ResourceType.html.equals(type)) { log.error("Unsupported type '" + type + "' to encode page '" + name + "' at " + component.getClientId()); return; } List<Resource> rs = wrm.getResources(new ResourceContextImpl(), name, type); if (rs != null && !rs.isEmpty()) { if (ResourceType.css.equals(type)) { encodeEnd(context, component, ResourceType.css, BUNDLE_ENDPOINT_PATH + name + ".css"); } else if (ResourceType.js.equals(type)) { encodeEnd(context, component, ResourceType.js, BUNDLE_ENDPOINT_PATH + name + ".js"); } else if (ResourceType.html.equals(type)) { for (Resource r : rs) { encodeEnd(context, component, ResourceType.html, COMPONENTS_PATH + r.getPath()); } } } super.encodeEnd(context, component); }
protected void encodeEnd(FacesContext context, UIComponent component, ResourceType type, String base) throws IOException { String url = resolveNuxeoResourceUrl(context, component, base); url = resolveUrlWithTimestamp(component, url); ResponseWriter writer = context.getResponseWriter(); if (ResourceType.css.equals(type)) { writer.startElement("link", component); writer.writeAttribute("type", "text/css", "type"); writer.writeAttribute("rel", "stylesheet", "rel"); writer.writeURIAttribute("href", url, "href"); writer.endElement("link"); } else if (ResourceType.js.equals(type)) { writer.startElement("script", component); writer.writeAttribute("type", "text/javascript", "type"); writer.writeURIAttribute("src", url, "src"); writer.endElement("script"); } else if (ResourceType.html.equals(type)) { writer.startElement("link", component); writer.writeAttribute("rel", "import", "rel"); writer.writeURIAttribute("href", url, "href"); writer.endElement("link"); } }