public DefaultWebResourceFilter(boolean isAmdEnabled) { this.javascriptWebResource = new JavascriptWebResource(isAmdEnabled); this.cssWebResource = new CssWebResource(isAmdEnabled); }
public String formatResource(String url, Map<String, String> attributes) { return formatResource(url, attributes, false); }
public String formatResource(String url, Map<String, String> attributes, boolean enableDeferJsAttribute) { if (!isValid(attributes)) { return ""; } StringBuilder buffer = new StringBuilder("<script type=\"text/javascript\" "); buffer.append("src=\"").append(StringEscapeUtils.escapeHtml4(url)).append("\" "); if (enableDeferJsAttribute && !attributes.containsKey(Config.ASYNC_SCRIPT_PARAM_NAME)) { buffer.append("defer "); } buffer.append(StringUtils.join(getParametersAsAttributes(attributes).iterator(), " ")); buffer.append("></script>\n"); return buffer.toString(); }
public boolean matches(String resourceName) { return javascriptWebResource.matches(resourceName) || cssWebResource.matches(resourceName); } }
public void writeHtmlTags(Writer writer, UrlMode urlMode, final Predicate<WebResource> predicate, final Predicate<ResourceUrl> legacyPredicate) { writeSyncResources(writer); // Writing data resources. try { new DataTagWriter().write(writer, Iterables.filter(data, predicate)); } catch (IOException ex) { Support.LOGGER.error("IOException encountered rendering data tags", ex); } // Writing urls. List<WebResourceFormatter> formatters = Arrays.asList(new CssWebResource(config.amdEnabled()), new JavascriptWebResource(config.amdEnabled())); writeFormattedResources(writer, urlMode, new ContainerPredicate(predicate, legacyPredicate), formatters, false); }
private void writeResourceTag(final UrlMode urlMode, final Container resource, final WebResourceFormatter formatter, final Writer writer, boolean isDeferJsAttributeEnabled, boolean writingPrefetchLinks) { PluginUrlResource urlResource = resource.getPluginUrlResource(); String formattedResource; if (formatter instanceof JavascriptWebResource) { Map<String, String> params = resource.getResourceUrl().getParams(); // this affects URI Map<String, String> attributes = new LinkedHashMap<>(urlResource.getParams().all()); if (config.useAsyncAttributeForScripts()) { params.put(Config.ASYNC_SCRIPT_PARAM_NAME, "true"); attributes.put(Config.ASYNC_SCRIPT_PARAM_NAME, ""); } attributes.put(Config.INITIAL_RENDERED_SCRIPT_PARAM_NAME, ""); formattedResource = ((JavascriptWebResource) formatter).formatResource(urlResource.getStaticUrl(urlMode), attributes, isDeferJsAttributeEnabled); } else { formattedResource = formatter.formatResource(urlResource.getStaticUrl(urlMode), urlResource.getParams().all()); } // insert the dependency information into the formatted resource if (!writingPrefetchLinks && config.isBatchContentTrackingEnabled()) { formattedResource = BatchResourceContentsWebFormatter.insertBatchResourceContents(resource, formattedResource); } writeContentAndSwallowErrors(writer, formattedResource); }