/** * This implementation creates a ClassPathResource, applying the given path * relative to the path of the underlying resource of this descriptor. * @see org.springframework.util.StringUtils#applyRelativePath(String, String) */ @Override public Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return (this.clazz != null ? new ClassPathResource(pathToUse, this.clazz) : new ClassPathResource(pathToUse, this.classLoader)); }
/** * This implementation creates a FileSystemResource, 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 Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return (this.file != null ? new FileSystemResource(pathToUse) : new FileSystemResource(this.filePath.getFileSystem(), pathToUse)); }
/** * 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 Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return new ServletContextResource(this.servletContext, pathToUse); }
/** * This implementation creates a ClassPathResource, applying the given path * relative to the path of the underlying resource of this descriptor. * @see org.springframework.util.StringUtils#applyRelativePath(String, String) */ @Override public Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return (this.clazz != null ? new ClassPathResource(pathToUse, this.clazz) : new ClassPathResource(pathToUse, this.classLoader)); }
/** * This implementation creates a FileSystemResource, 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 Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return (this.file != null ? new FileSystemResource(pathToUse) : new FileSystemResource(this.filePath.getFileSystem(), pathToUse)); }
@Override public String toString() { if (StringUtils.hasLength(this.file)) { return this.file; } String path = this.path; if (!path.endsWith("/")) { path = path + "/"; } return StringUtils.applyRelativePath(path, "spring.log"); }
/** * Prepare for rendering, and determine the request dispatcher path * to forward to (or to include). * <p>This implementation simply returns the configured URL. * Subclasses can override this to determine a resource to render, * typically interpreting the URL in a different manner. * @param request current HTTP request * @param response current HTTP response * @return the request dispatcher path to use * @throws Exception if preparations failed * @see #getUrl() */ protected String prepareForRendering(HttpServletRequest request, HttpServletResponse response) throws Exception { String path = getUrl(); Assert.state(path != null, "'url' not set"); if (this.preventDispatchLoop) { String uri = request.getRequestURI(); if (path.startsWith("/") ? uri.equals(path) : uri.equals(StringUtils.applyRelativePath(uri, path))) { throw new ServletException("Circular view path [" + path + "]: would dispatch back " + "to the current handler URL [" + uri + "] again. Check your ViewResolver setup! " + "(Hint: This may be the result of an unspecified view, due to default view name generation.)"); } } return path; }
@Override public Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath); return new ClassRelativeContextResource(pathToUse, this.clazz); } }
/** * 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 Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return new ServletContextResource(this.servletContext, pathToUse); }
/** * Transform the given relative request path to an absolute path, * taking the path of the given request as a point of reference. * The resulting path is also cleaned from sequences like "path/..". * * @param path the relative path to transform * @param exchange the current exchange * @return the absolute request path for the given resource path */ protected String toAbsolutePath(String path, ServerWebExchange exchange) { String requestPath = exchange.getRequest().getURI().getPath(); String absolutePath = (path.startsWith("/") ? path : StringUtils.applyRelativePath(requestPath, path)); return StringUtils.cleanPath(absolutePath); }
@Override public Resource createRelative(String relativePath) throws IOException { String pathToUse = StringUtils.applyRelativePath(this.path, relativePath); return new FilteredReactiveWebContextResource(pathToUse); }
/** * Return a context-aware URl for the given relative URL. * @param relativeUrl the relative URL part * @return a URL that points back to the current web application with an * absolute path also URL-encoded accordingly */ public String getContextUrl(String relativeUrl) { String url = StringUtils.applyRelativePath(getContextPath() + "/", relativeUrl); return getExchange().transformUrl(url); }
@Override public Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath); return new ClassPathContextResource(pathToUse, getClassLoader()); } }
/** * Transform the given relative request path to an absolute path, * taking the path of the given request as a point of reference. * The resulting path is also cleaned from sequences like "path/..". * @param path the relative path to transform * @param request the referer request * @return the absolute request path for the given resource path */ protected String toAbsolutePath(String path, HttpServletRequest request) { String absolutePath = path; if (!path.startsWith("/")) { ResourceUrlProvider urlProvider = findResourceUrlProvider(request); Assert.state(urlProvider != null, "No ResourceUrlProvider"); String requestPath = urlProvider.getUrlPathHelper().getRequestUri(request); absolutePath = StringUtils.applyRelativePath(requestPath, path); } return StringUtils.cleanPath(absolutePath); }
@Override public Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath); return new ClassRelativeContextResource(pathToUse, this.clazz); } }
/** * Return a context-aware URl for the given relative URL with placeholders -- * named keys with braces {@code {}}. For example, send in a relative URL * {@code foo/{bar}?spam={spam}} and a parameter map {@code {bar=baz,spam=nuts}} * and the result will be {@code [contextpath]/foo/baz?spam=nuts}. * @param relativeUrl the relative URL part * @param params a map of parameters to insert as placeholders in the url * @return a URL that points back to the current web application with an * absolute path also URL-encoded accordingly */ public String getContextUrl(String relativeUrl, Map<String, ?> params) { String url = StringUtils.applyRelativePath(getContextPath() + "/", relativeUrl); UriTemplate template = new UriTemplate(url); url = template.expand(params).toASCIIString(); return getExchange().transformUrl(url); }
@Override public Resource createRelative(String relativePath) { String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath); return new ClassPathContextResource(pathToUse, getClassLoader()); } }
/** * Transform the given relative request path to an absolute path, * taking the path of the given request as a point of reference. * The resulting path is also cleaned from sequences like "path/..". * @param path the relative path to transform * @param request the referer request * @return the absolute request path for the given resource path */ protected String toAbsolutePath(String path, HttpServletRequest request) { String absolutePath = path; if (!path.startsWith("/")) { ResourceUrlProvider urlProvider = findResourceUrlProvider(request); Assert.state(urlProvider != null, "No ResourceUrlProvider"); String requestPath = urlProvider.getUrlPathHelper().getRequestUri(request); absolutePath = StringUtils.applyRelativePath(requestPath, path); } return StringUtils.cleanPath(absolutePath); }
@Override public void sendRedirect(String location) throws IOException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(location); UriComponents uriComponents = builder.build(); // Absolute location if (uriComponents.getScheme() != null) { super.sendRedirect(location); return; } // Network-path reference if (location.startsWith("//")) { String scheme = this.request.getScheme(); super.sendRedirect(builder.scheme(scheme).toUriString()); return; } String path = uriComponents.getPath(); if (path != null) { // Relative to Servlet container root or to current request path = (path.startsWith(FOLDER_SEPARATOR) ? path : StringUtils.applyRelativePath(this.request.getRequestURI(), path)); } String result = UriComponentsBuilder .fromHttpRequest(new ServletServerHttpRequest(this.request)) .replacePath(path) .replaceQuery(uriComponents.getQuery()) .fragment(uriComponents.getFragment()) .build().normalize().toUriString(); super.sendRedirect(result); } }
String baseLocation = getReaderContext().getResource().getURL().toString(); importCount = getReaderContext().getReader().loadBeanDefinitions( StringUtils.applyRelativePath(baseLocation, location), actualResources);