@Override public String getMimeType(String resourceName) { return getServlet().getServletContext().getMimeType(resourceName); }
@Override public URL getStaticResource(String path) { try { return getServlet().getServletContext().getResource(path); } catch (MalformedURLException e) { getLogger().warn("Error finding resource for '{}'", path, e); } return null; }
/** * 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; }
@Override protected RouteRegistry getRouteRegistry() { return ApplicationRouteRegistry.getInstance(getServlet().getServletContext()); }
private static RouteRegistry getApplicationRegistry() { VaadinService service = VaadinService.getCurrent(); if (service instanceof VaadinServletService) { return ApplicationRouteRegistry .getInstance(((VaadinServletService) service).getServlet() .getServletContext()); } else { // TODO Once we have PortletService, this will explode // we will need route registry for portlet context throw new IllegalStateException("Cannot access " + ApplicationRouteRegistry.class.getName() + ", because no " + "VaadinServletService available for " + "fetching ServletContext"); } }
/** * 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; }