/** * Gets a resource in the given servlet context. */ public static ServletResource getResource(ServletContext sc,String path){ return new SimpleServletResource(sc,path); }
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 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); } }