@Override @Nullable public InputStream getResourceAsStream(String path) { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); if (!resource.exists()) { return null; } try { return resource.getInputStream(); } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not open InputStream for " + resource, ex); } return null; } }
@Override @Nullable public String getRealPath(String path) { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); try { return resource.getFile().getAbsolutePath(); } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not determine real path of resource " + resource, ex); } return null; } }
@Override @Nullable public URL getResource(String path) throws MalformedURLException { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); if (!resource.exists()) { return null; } try { return resource.getURL(); } catch (MalformedURLException ex) { throw ex; } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not get URL for " + resource, ex); } return null; } }
@Override @Nullable public Set<String> getResourcePaths(String path) { String actualPath = (path.endsWith("/") ? path : path + "/"); Resource resource = this.resourceLoader.getResource(getResourceLocation(actualPath)); try { File file = resource.getFile(); String[] fileList = file.list(); if (ObjectUtils.isEmpty(fileList)) { return null; } Set<String> resourcePaths = new LinkedHashSet<>(fileList.length); for (String fileEntry : fileList) { String resultPath = actualPath + fileEntry; if (resource.createRelative(fileEntry).getFile().isDirectory()) { resultPath += "/"; } resourcePaths.add(resultPath); } return resourcePaths; } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not get resource paths for " + resource, ex); } return null; } }
protected final String getResourceBasePathLocation(String path) { return super.getResourceLocation(path); }
@Override public String getRealPath(String path) { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); try { return resource.getFile().getAbsolutePath(); } catch (IOException ex) { logger.warn("Couldn't determine real path of resource " + resource, ex); return null; } }
@Override public InputStream getResourceAsStream(String path) { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); if (!resource.exists()) { return null; } try { return resource.getInputStream(); } catch (IOException ex) { logger.warn("Couldn't open InputStream for " + resource, ex); return null; } }
@Override @Nullable public String getRealPath(String path) { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); try { return resource.getFile().getAbsolutePath(); } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not determine real path of resource " + resource, ex); } return null; } }
@Override public URL getResource(String path) throws MalformedURLException { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); if (!resource.exists()) { return null; } try { return resource.getURL(); } catch (MalformedURLException ex) { throw ex; } catch (IOException ex) { logger.warn("Couldn't get URL for " + resource, ex); return null; } }
@Override @Nullable public InputStream getResourceAsStream(String path) { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); if (!resource.exists()) { return null; } try { return resource.getInputStream(); } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not open InputStream for " + resource, ex); } return null; } }
@Override @Nullable public URL getResource(String path) throws MalformedURLException { Resource resource = this.resourceLoader.getResource(getResourceLocation(path)); if (!resource.exists()) { return null; } try { return resource.getURL(); } catch (MalformedURLException ex) { throw ex; } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not get URL for " + resource, ex); } return null; } }
@Override public Set<String> getResourcePaths(String path) { String actualPath = (path.endsWith("/") ? path : path + "/"); Resource resource = this.resourceLoader.getResource(getResourceLocation(actualPath)); try { File file = resource.getFile(); String[] fileList = file.list(); if (ObjectUtils.isEmpty(fileList)) { return null; } Set<String> resourcePaths = new LinkedHashSet<String>(fileList.length); for (String fileEntry : fileList) { String resultPath = actualPath + fileEntry; if (resource.createRelative(fileEntry).getFile().isDirectory()) { resultPath += "/"; } resourcePaths.add(resultPath); } return resourcePaths; } catch (IOException ex) { logger.warn("Couldn't get resource paths for " + resource, ex); return null; } }
@Override @Nullable public Set<String> getResourcePaths(String path) { String actualPath = (path.endsWith("/") ? path : path + "/"); Resource resource = this.resourceLoader.getResource(getResourceLocation(actualPath)); try { File file = resource.getFile(); String[] fileList = file.list(); if (ObjectUtils.isEmpty(fileList)) { return null; } Set<String> resourcePaths = new LinkedHashSet<>(fileList.length); for (String fileEntry : fileList) { String resultPath = actualPath + fileEntry; if (resource.createRelative(fileEntry).getFile().isDirectory()) { resultPath += "/"; } resourcePaths.add(resultPath); } return resourcePaths; } catch (IOException ex) { if (logger.isWarnEnabled()) { logger.warn("Could not get resource paths for " + resource, ex); } return null; } }
@Override protected String getResourceLocation(String path) { if (path.startsWith("/~./")) { path = "/web" + path.substring(3); } return super.getResourceLocation(path); } }
@Override protected String getResourceLocation(String path) { if (!path.startsWith("/")) { path = "/" + path; } String resourceLocation = getResourceBasePathLocation(path); if (exists(resourceLocation)) { return resourceLocation; } for (String prefix : SPRING_BOOT_RESOURCE_LOCATIONS) { resourceLocation = prefix + path; if (exists(resourceLocation)) { return resourceLocation; } } return super.getResourceLocation(path); }