@Override public Resource getResource(String path) { if (!once[0]) { once[0] = true; Object attr = request.getRequest().getAttribute("**"); File file; if (attr != null) { file = new File(PHttpResourceHandler.this.file, "/" + attr); } else { file = new File(PHttpResourceHandler.this.file); } if (file.exists()) { return new PathResource(file.getAbsoluteFile()); } else { return null; } } else { return null; } } };
/** * Construct a new PathResource from a Path object. * * @param path the path to use */ public PathResource(Path path) { this.path = path.toAbsolutePath(); assertValidPath(path); this.uri = this.path.toUri(); this.alias = checkAliasPath(); }
return new PathResource(url).getFile().getParentFile().getParentFile().getCanonicalFile();
@Override public boolean check(String uri, Resource resource) { // Only support PathResource alias checking if (!(resource instanceof PathResource)) return false; PathResource pathResource = (PathResource) resource; try { Path path = pathResource.getPath(); Path alias = pathResource.getAliasPath(); if (path.equals(alias)) return false; // Unknown why this is an alias if (hasSymbolicLink(path) && Files.isSameFile(path, alias)) { if (LOG.isDebugEnabled()) LOG.debug("Allow symlink {} --> {}", resource, pathResource.getAliasPath()); return true; } } catch (Exception e) { LOG.ignore(e); } return false; }
/** * Construct a new PathResource from a parent PathResource * and child sub path * * @param parent the parent path resource * @param childPath the child sub path */ private PathResource(PathResource parent, String childPath) { // Calculate the URI and the path separately, so that any aliasing done by // FileSystem.getPath(path,childPath) is visible as a difference to the URI // obtained via URIUtil.addDecodedPath(uri,childPath) this.path = parent.path.getFileSystem().getPath(parent.path.toString(), childPath); if (isDirectory() && !childPath.endsWith("/")) childPath += "/"; this.uri = URIUtil.addPath(parent.uri, childPath); this.alias = checkAliasPath(); }
/** * Set the Config Path from a String reference to a file * * @param config the config file */ public void setConfig(String config) { if (config == null) { _configPath = null; return; } try { Resource configResource = Resource.newResource(config); if (configResource instanceof JarFileResource) _configPath = extractPackedFile((JarFileResource)configResource); else if (configResource instanceof PathResource) _configPath = ((PathResource)configResource).getPath(); else if (configResource.getFile() != null) setConfigFile(configResource.getFile()); else throw new IllegalArgumentException(config); } catch (Exception e) { _configPath = null; throw new IllegalStateException(e); } }
public PathResource(Path path) { this.path = path; assertValidPath(path); this.uri = this.path.toUri(); }
this.alias = checkAliasPath();
Path path = pathResource.getPath(); Path alias = pathResource.getAliasPath(); LOG.debug("Allow symlink {} --> {}",resource,pathResource.getAliasPath()); return true; if (pathResource.getAliasPath().equals(target))
/** * Construct a new PathResource from a parent PathResource * and child sub path * * @param parent the parent path resource * @param childPath the child sub path */ private PathResource(PathResource parent, String childPath) { // Calculate the URI and the path separately, so that any aliasing done by // FileSystem.getPath(path,childPath) is visible as a difference to the URI // obtained via URIUtil.addDecodedPath(uri,childPath) this.path = parent.path.getFileSystem().getPath(parent.path.toString(), childPath); if (isDirectory() && !childPath.endsWith("/")) childPath += "/"; this.uri = URIUtil.addPath(parent.uri, childPath); this.alias = checkAliasPath(); }
_configPath = extractPackedFile((JarFileResource)configResource); else if (configResource instanceof PathResource) _configPath = ((PathResource)configResource).getPath(); else if (configResource.getFile() != null) setConfigFile(configResource.getFile());
this.alias = checkAliasPath();
new PathResource(new File("./src/main/resources").toPath().toRealPath())); context.addServlet(DefaultServlet.class, "/"); server.start();
/** * Construct a new PathResource from a Path object. * * @param path the path to use */ public PathResource(Path path) { this.path = path.toAbsolutePath(); assertValidPath(path); this.uri = this.path.toUri(); this.alias = checkAliasPath(); }
new PathResource(new File("./src/main/resources").toPath().toRealPath())); context.addServlet(DefaultServlet.class, "/"); server.start();
/** * Construct a Resource from provided path * * @param path the path * @return the Resource for the provided path * @since 9.4.10 */ public static Resource newResource(Path path) { return new PathResource(path); }
/** * @return the resource associated with the configured properties file, creating it if necessary */ public Resource getConfigResource() { if (_configPath == null) return null; return new PathResource(_configPath); }
public static Resource newResource(File file) { return new PathResource(file.toPath()); }