/** * Gets a resource in the given servlet context. */ public static ServletResource getResource(ServletContext sc,String path){ return new SimpleServletResource(sc,path); }
/** * This implementation delegates to {@code ServletContext.getResourceAsStream}, * but throws a FileNotFoundException if no resource found. * @see javax.servlet.ServletContext#getResourceAsStream(String) */ public InputStream getInputStream() throws IOException { InputStream is = this.servletContext.getResourceAsStream(this.path); if (is == null) { throw new FileNotFoundException("Could not open " + getDescription()); } return is; }
public static ServletResource getResource(ServletContext sc,String path, Locale locale) { String[] paths = Locales.getLocaleFilePaths(locale, path); for (String p : paths) { try { if (null != sc.getResource(p)) { return new SimpleServletResource(sc, p); } } catch (MalformedURLException ex) { } } return null; }
/** * This implementation delegates to {@code ServletContext.getResource}, * but throws a FileNotFoundException if no resource found. * @see javax.servlet.ServletContext#getResource(String) */ @Override public URL getURL() throws IOException { URL url = this.servletContext.getResource(this.path); if (url == null) { throw new FileNotFoundException( getDescription() + " cannot be resolved to URL because it does not exist"); } return url; }
/** * This implementation creates a ServletContextResource, applying the given path * relative to the path of the underlying file of this resource descriptor. * @see org.springframework.util.StringUtils#applyRelativePath(String, String) */ @Override public SimpleServletResource createRelative(String relativePath) { String pathToUse = Paths.applyRelative(this.path, relativePath); return new SimpleServletResource(this.servletContext, pathToUse); }
@Override @SuppressWarnings("unchecked") public ServletResource[] scan(String subPattern) { Args.notEmpty(subPattern,"subPattern"); Set<String> subPaths = this.servletContext.getResourcePaths(this.path); List<SimpleServletResource> resources = new ArrayList<>(); PathMatcher matcher = Resources.getPathMatcher(); for(String subPath : subPaths){ if(matcher.match(subPattern, subPath)){ resources.add(new SimpleServletResource(servletContext, subPath)); } } return resources.toArray(new SimpleServletResource[resources.size()]); }
private void loadServletContextResource(ServletContext sc, String path, String pathPrefix) { ServletResource resource = new SimpleServletResource(sc, path); if(!resource.isDirectory()) { add(resource, Strings.removeStart(path, pathPrefix)); }else{ loadServletContextResources(sc, path, pathPrefix); } }