/** * This is called to use a minification naming strategy to find resources. * If a minified file cant by found then the base location is used as the * fall back * * @return an InputStream r null if nothing can be found for the resource * name */ private InputStream getResourceAsStreamViaMinificationStrategy() { InputStream inputStream = null; final String location = getLocation(); if (minificationStrategyInPlay(location)) { final String minifiedLocation = getMinifiedLocation(location); inputStream = getResourceAsStream(minifiedLocation); } if (inputStream == null) { inputStream = getResourceAsStream(location); } return inputStream; }
public void streamResource(final OutputStream out) throws DownloadException { final InputStream resourceStream = getResourceAsStreamViaMinificationStrategy(); if (resourceStream == null) { log.warn("Resource not found: {}", this); return; } streamResource(resourceStream, out); }
public void serveResource(final HttpServletRequest request, final HttpServletResponse response) throws DownloadException { log.debug("Serving: {}", this); final InputStream resourceStream = getResourceAsStreamViaMinificationStrategy(); if (resourceStream == null) { log.warn("Resource not found: {}", this); return; } final String contentType = getContentType(); if (StringUtils.isNotBlank(contentType)) { response.setContentType(contentType); } final OutputStream out; try { out = response.getOutputStream(); } catch (final IOException e) { throw new DownloadException(e); } streamResource(resourceStream, out); log.debug("Serving file done."); }
@Override public String toString() { final String pluginKey = plugin != null ? plugin.getKey() : ""; return "Resource: " + pluginKey + " " + getLocation() + " (" + getContentType() + ")"; }