org.springframework.util.StringUtils#applyRelativePath ( )源码实例Demo

下面列出了org.springframework.util.StringUtils#applyRelativePath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FastBootWeixin   文件: WxMediaStore.java
/**
 * 保存tempMedia到File
 *
 * @param mediaId
 * @return File
 */
public File storeTempMediaToFile(String mediaId, Resource resource) throws IOException {
    WxMediaResource wxMediaResource = (WxMediaResource) resource;
    if (wxMediaResource.isUrlMedia()) {
        return null;
    }
    String fileName = resource.getFilename();
    if (fileName == null) {
        fileName = mediaId;
    }
    File file = new File(StringUtils.applyRelativePath(defaultTempFilePath, fileName));
    if (file.exists()) {
        return file;
    }
    StoreEntity storeEntity = storeFile(file, mediaId, resource);
    tempMediaFileDb.put(file.getAbsolutePath(), storeEntity);
    tempMediaIdDb.put(mediaId, file.getAbsolutePath());
    db.commit();
    return file;
}
 
源代码2 项目: spring-analysis-note   文件: FileSystemResource.java
/**
 * 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));
}
 
源代码3 项目: FastBootWeixin   文件: WxMediaResource.java
public synchronized File getFile(String path) throws IOException {
    if (this.file == null) {
        // 拿到临时文件路径
        String pathToUse = StringUtils.applyRelativePath(path, this.filename);
        this.file = new File(pathToUse);
        if (!this.file.exists()) {
            this.file.getParentFile().mkdirs();
            this.file.createNewFile();
        }
        FileCopyUtils.copy(this.getBody(), file);
    }
    return this.file;
}
 
源代码4 项目: lams   文件: ForwardedHeaderFilter.java
@Override
public void sendRedirect(String location) throws IOException {
	UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(location);

	// Absolute location
	if (builder.build().getScheme() != null) {
		super.sendRedirect(location);
		return;
	}

	// Network-path reference
	if (location.startsWith("//")) {
		String scheme = this.request.getScheme();
		super.sendRedirect(builder.scheme(scheme).toUriString());
		return;
	}

	// Relative to Servlet container root or to current request
	String path = (location.startsWith(FOLDER_SEPARATOR) ? location :
			StringUtils.applyRelativePath(this.request.getRequestURI(), location));

	String result = UriComponentsBuilder
			.fromHttpRequest(new ServletServerHttpRequest(this.request))
			.replacePath(path)
			.build().normalize().toUriString();

	super.sendRedirect(result);
}
 
源代码5 项目: FastBootWeixin   文件: WxMediaResource.java
@Override
public Resource createRelative(String mediaId) throws IOException {
    if (isFileResource) {
        String pathToUse = StringUtils.applyRelativePath(StringUtils.cleanPath(file.getPath()), mediaId);
        return new WxMediaResource(new File(pathToUse));
    }
    return WxContextUtils.getBean(WxApiService.class).getTempMedia(mediaId);
}
 
/**
 * 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 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);
}
 
源代码8 项目: lams   文件: DefaultResourceLoader.java
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassPathContextResource(pathToUse, getClassLoader());
}
 
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassRelativeContextResource(pathToUse, this.clazz);
}
 
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassPathContextResource(pathToUse, getClassLoader());
}
 
源代码11 项目: lams   文件: FileSystemResource.java
/**
 * 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 new FileSystemResource(pathToUse);
}
 
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
	return new PortletContextResource(this.portletContext, 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);
}
 
源代码14 项目: lams   文件: ClassRelativeResourceLoader.java
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassRelativeContextResource(pathToUse, this.clazz);
}
 
源代码15 项目: spring4-understanding   文件: ClassPathResource.java
/**
 * 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 new ClassPathResource(pathToUse, this.classLoader, this.clazz);
}
 
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassPathContextResource(pathToUse, getClassLoader());
}
 
源代码17 项目: HotswapAgent   文件: ClassRelativeResourceLoader.java
@Override
public Resource createRelative(String relativePath) {
    String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
    return new ClassRelativeContextResource(pathToUse, this.clazz);
}
 
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassRelativeContextResource(pathToUse, this.clazz);
}
 
源代码19 项目: java-technology-stack   文件: RequestContext.java
/**
 * 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);
}
 
源代码20 项目: spring-analysis-note   文件: RequestContext.java
/**
 * 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);
}