protected ComponentConfig getJSFResourceComponentConfig(Resource resource, String rendererType, String target, String includeTimestamp, FaceletHandler nextHandler) { String componentType = UIOutput.COMPONENT_TYPE; String uri = resource.getURI(); String resourceName; String resourceLib; int i = uri != null ? uri.indexOf(":") : -1; if (i > 0) { resourceLib = uri.substring(0, i); resourceName = uri.substring(i + 1); } else { resourceLib = null; resourceName = uri; } List<TagAttribute> attrs = new ArrayList<TagAttribute>(); attrs.add(getTagAttribute("name", resourceName)); if (!StringUtils.isBlank(resourceLib)) { attrs.add(getTagAttribute("library", resourceLib)); } if (!StringUtils.isBlank(target)) { attrs.add(getTagAttribute("target", target)); } if (!StringUtils.isBlank(includeTimestamp)) { attrs.add(getTagAttribute("includeTimestamp", includeTimestamp)); } TagAttributesImpl attributes = new TagAttributesImpl(attrs.toArray(new TagAttribute[] {})); ComponentConfig cconfig = TagConfigFactory.createComponentConfig(config, tagId, attributes, nextHandler, componentType, rendererType); return cconfig; }
@Override protected String resolveUrl(FacesContext context, UIComponent component) throws IOException { Map<String, Object> attributes = component.getAttributes(); String name = (String) attributes.get("name"); if (name != null) { Resource r = resolveNuxeoResource(context, component, name); if (r != null) { String url = getUrlWithParams(context, component, r.getURI()); url = resolveUrlWithTimestamp(component, url); return url; } } return null; }
@Override public InputStream locate(String uri) throws IOException { Resource resource = getResource(uri); if (resource != null) { String ruri = resource.getURI(); if (ruri == null) { log.error("Cannot handle resource '" + resource.getName() + "': no resolved uri"); return null; } final UriLocator uriLocator = uriLocatorFactory.getInstance(ruri); if (uriLocator != null) { return uriLocator.locate(ruri); } } return null; }
protected void includeXHTML(FaceletContext ctx, UIComponent parent, List<Resource> rs, FaceletHandler leaf) throws IOException { if (rs != null && !rs.isEmpty()) { for (Resource r : rs) { String uri = r.getURI(); if (StringUtils.isBlank(uri)) { log.error("Invalid resource '" + r.getName() + "': no uri defined at " + tag.getLocation()); continue; } TagAttributeImpl srcAttr = getTagAttribute("src", uri); TagAttributesImpl attributes = new TagAttributesImpl(new TagAttribute[] { srcAttr }); TagConfig xconfig = TagConfigFactory.createTagConfig(config, tagId, attributes, leaf); new IncludeHandler(xconfig).apply(ctx, parent); } } }
protected String resolveNuxeoResourcePath(org.nuxeo.ecm.web.resources.api.Resource resource) { if (resource == null) { return null; } String name = resource.getName(); if (ResourceType.css.matches(resource)) { String suffixed = name; if (!suffixed.endsWith(ResourceType.css.getSuffix())) { suffixed += ResourceType.css.getSuffix(); } return BUNDLE_ENDPOINT_PATH + suffixed; } else if (ResourceType.js.matches(resource)) { String suffixed = name; if (!suffixed.endsWith(ResourceType.js.getSuffix())) { suffixed += ResourceType.js.getSuffix(); } return BUNDLE_ENDPOINT_PATH + suffixed; } else if (ResourceType.html.matches(resource)) { // assume html resources are copied to the war "components" sub-directory for now return COMPONENTS_PATH + resource.getPath(); } // fallback on URI return resource.getURI(); }