@Override public Set<String> getResourcePaths(final String path) { final Resource resource; try { resource = deploymentInfo.getResourceManager().getResource(path); } catch (IOException e) { return null; } if (resource == null || !resource.isDirectory()) { return null; } final Set<String> resources = new HashSet<String>(); for (Resource res : resource.list()) { File file = res.getFile(); if (file != null) { File base = res.getResourceManagerRoot(); String filePath = file.getAbsolutePath().substring(base.getAbsolutePath().length()); filePath = filePath.replace('\\', '/'); // for windows systems if (file.isDirectory()) { filePath = filePath + "/"; } resources.add(filePath); } } return resources; }
@Override public URL getResource(final String path) throws MalformedURLException { if (!path.startsWith("/")) { throw UndertowServletMessages.MESSAGES.pathMustStartWithSlash(path); } Resource resource = null; try { resource = deploymentInfo.getResourceManager().getResource(path); } catch (IOException e) { return null; } if (resource == null) { return null; } return resource.getUrl(); }
@Override public String getRealPath(final String path) { if (path == null) { return null; } Resource resource = null; try { resource = deploymentInfo.getResourceManager().getResource(path); } catch (IOException e) { return null; } if (resource == null) { return null; } File file = resource.getFile(); if (file == null) { return null; } return file.getAbsolutePath(); }
@Override public InputStream getResourceAsStream(final String path) { Resource resource = null; try { resource = deploymentInfo.getResourceManager().getResource(path); } catch (IOException e) { return null; } if (resource == null) { return null; } try { if (resource.getFile() != null) { return new BufferedInputStream(new FileInputStream(resource.getFile())); } else { return new BufferedInputStream(resource.getUrl().openStream()); } } catch (FileNotFoundException e) { // should never happen, as the resource loader should return null in this case return null; } catch (IOException e) { return null; } }