/** * Opens a stream for the given resource found in the servlet context or in * a webjar. * * @param path * the path inside servlet context, automatically translated as * needed for webjars * @return a URL for the resource or <code>null</code> if no resource was * found */ private InputStream getResourceInServletContextOrWebJarAsStream( String path) { ServletContext servletContext = getServlet().getServletContext(); InputStream stream = servletContext.getResourceAsStream(path); if (stream != null) { return stream; } Optional<String> webJarPath = getWebJarPath(path); if (webJarPath.isPresent()) { return servletContext.getResourceAsStream(webJarPath.get()); } return null; }
/** * Finds the given resource in the servlet context or in a webjar. * * @param path * the path inside servlet context, automatically translated as * needed for webjars * @return a URL for the resource or <code>null</code> if no resource was * found */ private URL getResourceInServletContextOrWebJar(String path) { ServletContext servletContext = getServlet().getServletContext(); try { URL url = servletContext.getResource(path); if (url != null) { return url; } Optional<String> webJarPath = getWebJarPath(path); if (webJarPath.isPresent()) { return servletContext.getResource(webJarPath.get()); } } catch (MalformedURLException e) { getLogger().warn("Error finding resource for '{}'", path, e); } return null; }