protected ro.isdc.wro.model.resource.Resource toWroResource(String bundle, Resource resource) { ro.isdc.wro.model.resource.ResourceType type = toWroResourceType(resource.getType()); if (type == null) { if (log.isDebugEnabled()) { log.debug("Cannot handle resource type '" + resource.getType() + "' for resource '" + resource.getName() + "'"); } return null; } String uri = NuxeoUriLocator.getUri(resource); if (uri == null) { log.error( "Cannot handle resource '" + resource.getName() + "' for bundle '" + bundle + "': no uri resolved"); return null; } ro.isdc.wro.model.resource.Resource res = ro.isdc.wro.model.resource.Resource.create(uri, type); res.setMinimize(resource.isShrinkable()); return res; }
public static boolean isProcessorEnabled(String alias, String uri) { Resource res = getResource(uri); if (res != null) { return res.getProcessors().contains(alias); } return false; }
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(); }
@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; }
@Override public String getContributionId(Resource contrib) { return contrib.getName(); }
protected Map<String, Resource> getSubResources(DAG graph, Resource r, String type) { Map<String, Resource> res = new HashMap<>(); List<String> deps = r.getDependencies(); if (deps != null) { for (String dn : deps) { Resource d = getResource(dn); if (d == null) { log.error("Unknown resource dependency named '" + dn + "'"); continue; } if (!ResourceType.matches(type, d)) { continue; } res.put(dn, d); try { graph.addEdge(r.getName(), dn); } catch (CycleDetectedException e) { log.error("Cycle detected in resource dependencies: ", e); break; } res.putAll(getSubResources(graph, d, type)); } } return res; }
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; }
case jsfjs: for (Resource r : retrieveResources(wrm, bundle, type)) { String rtarget = r.getTarget(); ComponentConfig config = getJSFResourceComponentConfig(r, "javax.faces.resource.Script", rtarget == null ? targetValue : rtarget, includeTimestamp, nextHandler); case jsfcss: for (Resource r : retrieveResources(wrm, bundle, type)) { String rtarget = r.getTarget(); ComponentConfig config = getJSFResourceComponentConfig(r, "javax.faces.resource.Stylesheet", rtarget == null ? targetValue : rtarget, includeTimestamp, nextHandler);
@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 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); } } }
public static String getUri(Resource resource) { return Resource.PREFIX + resource.getName(); }
public static final boolean matches(String type, Resource r) { if (StringUtils.isBlank(type) || ResourceType.any.name().equals(type.toLowerCase())) { return true; } String rt = r.getType(); if (StringUtils.isBlank(rt)) { return true; } if (type.toLowerCase().equals(rt.toLowerCase())) { return true; } return false; }
@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; }
case jsfjs: for (Resource r : retrieveResources(wrm, page, type)) { String rtarget = r.getTarget(); ComponentConfig config = getJSFResourceComponentConfig(r, "javax.faces.resource.Script", rtarget == null ? targetValue : rtarget, includeTimestamp, nextHandler); case jsfcss: for (Resource r : retrieveResources(wrm, page, type)) { String rtarget = r.getTarget(); ComponentConfig config = getJSFResourceComponentConfig(r, "javax.faces.resource.Stylesheet", rtarget == null ? targetValue : rtarget, includeTimestamp, nextHandler);