Java Code Examples for org.springframework.util.StringUtils#applyRelativePath()

The following examples show how to use org.springframework.util.StringUtils#applyRelativePath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WxMediaStore.java    From FastBootWeixin with Apache License 2.0 6 votes vote down vote up
/**
 * 保存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;
}
 
Example 2
Source File: ForwardedHeaderFilter.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
}
 
Example 3
Source File: FileSystemResource.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * 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));
}
 
Example 4
Source File: WxMediaResource.java    From FastBootWeixin with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: FileSystemResource.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * 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));
}
 
Example 6
Source File: ForwardedHeaderFilter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 7
Source File: WxMediaResource.java    From FastBootWeixin with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: ClassRelativeResourceLoader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassRelativeContextResource(pathToUse, this.clazz);
}
 
Example 9
Source File: ClassRelativeResourceLoader.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassRelativeContextResource(pathToUse, this.clazz);
}
 
Example 10
Source File: ClassRelativeResourceLoader.java    From HotswapAgent with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Resource createRelative(String relativePath) {
    String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
    return new ClassRelativeContextResource(pathToUse, this.clazz);
}
 
Example 11
Source File: DefaultResourceLoader.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassPathContextResource(pathToUse, getClassLoader());
}
 
Example 12
Source File: ClassPathResource.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 13
Source File: ServletContextResource.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * 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);
}
 
Example 14
Source File: PortletContextResource.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
	return new PortletContextResource(this.portletContext, pathToUse);
}
 
Example 15
Source File: FileSystemResource.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 16
Source File: DefaultResourceLoader.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassPathContextResource(pathToUse, getClassLoader());
}
 
Example 17
Source File: ClassRelativeResourceLoader.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassRelativeContextResource(pathToUse, this.clazz);
}
 
Example 18
Source File: DefaultResourceLoader.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassPathContextResource(pathToUse, getClassLoader());
}
 
Example 19
Source File: RequestContext.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: RequestContext.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * 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);
}