Java Code Examples for org.springframework.web.util.UriUtils#extractFileExtension()

The following examples show how to use org.springframework.web.util.UriUtils#extractFileExtension() . 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: PathExtensionContentNegotiationStrategy.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
@Nullable
protected String getMediaTypeKey(NativeWebRequest webRequest) {
	HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
	if (request == null) {
		return null;
	}
	// Ignore LOOKUP_PATH attribute, use our own "fixed" UrlPathHelper with decoding off
	String path = this.urlPathHelper.getLookupPathForRequest(request);
	String extension = UriUtils.extractFileExtension(path);
	return (StringUtils.hasText(extension) ? extension.toLowerCase(Locale.ENGLISH) : null);
}
 
Example 2
Source File: PathExtensionContentNegotiationStrategy.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
@Nullable
protected String getMediaTypeKey(NativeWebRequest webRequest) {
	HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
	if (request == null) {
		return null;
	}
	String path = this.urlPathHelper.getLookupPathForRequest(request);
	String extension = UriUtils.extractFileExtension(path);
	return (StringUtils.hasText(extension) ? extension.toLowerCase(Locale.ENGLISH) : null);
}
 
Example 3
Source File: PathExtensionContentNegotiationStrategy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected String getMediaTypeKey(NativeWebRequest webRequest) {
	HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
	if (request == null) {
		logger.warn("An HttpServletRequest is required to determine the media type key");
		return null;
	}
	String path = this.urlPathHelper.getLookupPathForRequest(request);
	String extension = UriUtils.extractFileExtension(path);
	return (StringUtils.hasText(extension) ? extension.toLowerCase(Locale.ENGLISH) : null);
}
 
Example 4
Source File: RequestUtils.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public static String getRequestExtension(HttpServletRequest request) {
		String requestUri = getUrlPathHelper().getLookupPathForRequest(request);
//		String reqUri = WebUtils.extractFullFilenameFromUrlPath(requestUri);
//		String extension = FileUtils.getExtendName(reqUri);
		String extension = UriUtils.extractFileExtension(requestUri);
		return extension;
	}
 
Example 5
Source File: RequestPredicates.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public boolean test(ServerRequest request) {
	String pathExtension = UriUtils.extractFileExtension(request.path());
	return this.extensionPredicate.test(pathExtension);
}
 
Example 6
Source File: RequestPredicates.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public boolean test(ServerRequest request) {
	String pathExtension = UriUtils.extractFileExtension(request.path());
	return this.extensionPredicate.test(pathExtension);
}
 
Example 7
Source File: RequestPredicates.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public boolean test(ServerRequest request) {
	String pathExtension = UriUtils.extractFileExtension(request.path());
	return this.extensionPredicate.test(pathExtension);
}
 
Example 8
Source File: ServletUriComponentsBuilder.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Remove any path extension from the {@link HttpServletRequest#getRequestURI()
 * requestURI}. This method must be invoked before any calls to {@link #path(String)}
 * or {@link #pathSegment(String...)}.
 * <pre>
 * GET http://www.foo.com/rest/books/6.json
 *
 * ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequestUri(this.request);
 * String ext = builder.removePathExtension();
 * String uri = builder.path("/pages/1.{ext}").buildAndExpand(ext).toUriString();
 * assertEquals("http://www.foo.com/rest/books/6/pages/1.json", result);
 * </pre>
 * @return the removed path extension for possible re-use, or {@code null}
 * @since 4.0
 */
@Nullable
public String removePathExtension() {
	String extension = null;
	if (this.originalPath != null) {
		extension = UriUtils.extractFileExtension(this.originalPath);
		if (StringUtils.hasLength(extension)) {
			int end = this.originalPath.length() - (extension.length() + 1);
			replacePath(this.originalPath.substring(0, end));
		}
		this.originalPath = null;
	}
	return extension;
}
 
Example 9
Source File: ServletUriComponentsBuilder.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Remove any path extension from the {@link HttpServletRequest#getRequestURI()
 * requestURI}. This method must be invoked before any calls to {@link #path(String)}
 * or {@link #pathSegment(String...)}.
 * <pre>
 * GET http://foo.com/rest/books/6.json
 *
 * ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequestUri(this.request);
 * String ext = builder.removePathExtension();
 * String uri = builder.path("/pages/1.{ext}").buildAndExpand(ext).toUriString();
 * assertEquals("http://foo.com/rest/books/6/pages/1.json", result);
 * </pre>
 * @return the removed path extension for possible re-use, or {@code null}
 * @since 4.0
 */
@Nullable
public String removePathExtension() {
	String extension = null;
	if (this.originalPath != null) {
		extension = UriUtils.extractFileExtension(this.originalPath);
		if (!StringUtils.isEmpty(extension)) {
			int end = this.originalPath.length() - (extension.length() + 1);
			replacePath(this.originalPath.substring(0, end));
		}
		this.originalPath = null;
	}
	return extension;
}
 
Example 10
Source File: ServletUriComponentsBuilder.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Remove any path extension from the {@link HttpServletRequest#getRequestURI()
 * requestURI}. This method must be invoked before any calls to {@link #path(String)}
 * or {@link #pathSegment(String...)}.
 * <pre>
 * GET http://foo.com/rest/books/6.json
 *
 * ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequestUri(this.request);
 * String ext = builder.removePathExtension();
 * String uri = builder.path("/pages/1.{ext}").buildAndExpand(ext).toUriString();
 * assertEquals("http://foo.com/rest/books/6/pages/1.json", result);
 * </pre>
 * @return the removed path extension for possible re-use, or {@code null}
 * @since 4.0
 */
public String removePathExtension() {
	String extension = null;
	if (this.originalPath != null) {
		extension = UriUtils.extractFileExtension(this.originalPath);
		if (!StringUtils.isEmpty(extension)) {
			int end = this.originalPath.length() - (extension.length() + 1);
			replacePath(this.originalPath.substring(0, end));
		}
		this.originalPath = null;
	}
	return extension;
}