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

The following examples show how to use org.springframework.util.StringUtils#applyRelativePath() . These examples are extracted from open source projects. 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 Project: FastBootWeixin   File: WxMediaStore.java    License: 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
/**
 * 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 3
Source Project: FastBootWeixin   File: WxMediaResource.java    License: 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 4
@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 5
Source Project: FastBootWeixin   File: WxMediaResource.java    License: 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 6
/**
 * 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 7
@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 8
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassPathContextResource(pathToUse, getClassLoader());
}
 
Example 9
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassRelativeContextResource(pathToUse, this.clazz);
}
 
Example 10
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassPathContextResource(pathToUse, getClassLoader());
}
 
Example 11
/**
 * 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 12
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
	return new PortletContextResource(this.portletContext, pathToUse);
}
 
Example 13
/**
 * 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
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassRelativeContextResource(pathToUse, this.clazz);
}
 
Example 15
/**
 * 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 16
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassPathContextResource(pathToUse, getClassLoader());
}
 
Example 17
@Override
public Resource createRelative(String relativePath) {
    String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
    return new ClassRelativeContextResource(pathToUse, this.clazz);
}
 
Example 18
@Override
public Resource createRelative(String relativePath) {
	String pathToUse = StringUtils.applyRelativePath(getPath(), relativePath);
	return new ClassRelativeContextResource(pathToUse, this.clazz);
}
 
Example 19
Source Project: java-technology-stack   File: RequestContext.java    License: 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 Project: spring-analysis-note   File: RequestContext.java    License: 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);
}