Java Code Examples for org.springframework.util.StringUtils.getFilenameExtension()

The following are Jave code examples for showing how to use getFilenameExtension() of the org.springframework.util.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: artifactory-resource   File: MavenCoordinates.java   Source Code and License Vote up 6 votes
public static MavenCoordinates fromPath(String path) {
	if (path.startsWith("/")) {
		path = path.substring(1);
	}
	Matcher folderMatcher = FOLDER_PATTERN.matcher(path);
	Assert.state(folderMatcher.matches(), "Unable to parse " + path);
	String groupId = folderMatcher.group(1).replace('/', '.');
	String artifactId = folderMatcher.group(2);
	String version = folderMatcher.group(3);
	String rootVersion = (version.endsWith(SNAPSHOT_SUFFIX)
			? version.substring(0, version.length() - SNAPSHOT_SUFFIX.length())
			: version);
	String name = folderMatcher.group(4);
	String snapshotVersionAndClassifier = name.substring(artifactId.length() + 1);
	String extension = StringUtils.getFilenameExtension(snapshotVersionAndClassifier);
	snapshotVersionAndClassifier = snapshotVersionAndClassifier.substring(0,
			snapshotVersionAndClassifier.length() - extension.length() - 1);
	String classifier = snapshotVersionAndClassifier;
	if (classifier.startsWith(rootVersion)) {
		classifier = classifier.substring(rootVersion.length());
		classifier = stripDash(classifier);
	}
	Matcher versionMatcher = VERSION_FILE_PATTERN.matcher(classifier);
	if (versionMatcher.matches()) {
		classifier = versionMatcher.group(3);
		classifier = stripDash(classifier);
	}
	if (classifier.startsWith(SNAPSHOT)) {
		classifier = classifier.substring(SNAPSHOT.length());
		classifier = stripDash(classifier);
	}
	String snapshotVersion = (classifier.isEmpty() ? snapshotVersionAndClassifier
			: snapshotVersionAndClassifier.substring(0,
					snapshotVersionAndClassifier.length() - classifier.length() - 1));
	return new MavenCoordinates(groupId, artifactId, version, classifier, extension,
			snapshotVersion);
}
 
Example 2
Project: lams   File: PathExtensionContentNegotiationStrategy.java   Source Code and License Vote up 5 votes
@Override
protected String getMediaTypeKey(NativeWebRequest webRequest) {
	HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class);
	if (servletRequest == null) {
		logger.warn("An HttpServletRequest is required to determine the media type key");
		return null;
	}
	String path = urlPathHelper.getLookupPathForRequest(servletRequest);
	String filename = WebUtils.extractFullFilenameFromUrlPath(path);
	String extension = StringUtils.getFilenameExtension(filename);
	return (StringUtils.hasText(extension)) ? extension.toLowerCase(Locale.ENGLISH) : null;
}
 
Example 3
Project: artifactory-resource   File: MavenMetadataGenerator.java   Source Code and License Vote up 5 votes
private void generate(Directory root, File pomFile) {
	String name = StringUtils.getFilename(pomFile.getName());
	String extension = StringUtils.getFilenameExtension(pomFile.getName());
	String prefix = name.substring(0, name.length() - extension.length() - 1);
	File[] files = pomFile.getParentFile().listFiles((f) -> include(f, prefix));
	MultiValueMap<File, MavenCoordinates> coordinates = new LinkedMultiValueMap<>();
	for (File file : files) {
		String rootPath = StringUtils.cleanPath(root.getFile().getPath());
		String relativePath = StringUtils.cleanPath(file.getPath())
				.substring(rootPath.length() + 1);
		coordinates.add(file.getParentFile(),
				MavenCoordinates.fromPath(relativePath));
	}
	coordinates.forEach(this::writeMetadata);
}
 
Example 4
Project: artifactory-resource   File: MavenMetadataGenerator.java   Source Code and License Vote up 5 votes
private boolean include(File file, String prefix) {
	String extension = StringUtils.getFilenameExtension(file.getName());
	if (IGNORED_EXTENSIONS.contains(extension.toLowerCase())) {
		return false;
	}
	return file.exists() && file.isFile()
			&& StringUtils.getFilename(file.getName()).startsWith(prefix);
}
 
Example 5
Project: nordvisa_calendar   File: AppConfig.java   Source Code and License Vote up 4 votes
private boolean isHandled(String path) {
  String extension = StringUtils.getFilenameExtension(path);
  return handledExtensions.stream().anyMatch(ext -> ext.equals(extension));
}
 
Example 6
Project: artifactory-resource   File: FileComparator.java   Source Code and License Vote up 4 votes
private String getFileExtension(File file) {
	return StringUtils.getFilenameExtension(file.getName());
}
 
Example 7
Project: artifactory-resource   File: FileComparator.java   Source Code and License Vote up 4 votes
private static String getNameWithoutExtension(File file) {
	String name = file.getName();
	String extension = StringUtils.getFilenameExtension(name);
	return (extension == null ? name
			: name.substring(0, name.length() - extension.length() - 1));
}
 
Example 8
Project: ReBoot   File: SinglePageAppConfig.java   Source Code and License Vote up 4 votes
private boolean isHandled(String path) {
  String extension = StringUtils.getFilenameExtension(path);
  return handledExtensions.stream().anyMatch(ext -> ext.equals(extension));
}
 
Example 9
Project: Your-Microservice   File: YourServletUriComponentsBuilder.java   Source Code and License Vote up 3 votes
/**
 * Removes 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
 *
 *  YourServletUriComponentsBuilder builder = YourServletUriComponentsBuilder.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.servletRequestURI != null) {
        String filename = WebUtils.extractFullFilenameFromUrlPath(this.servletRequestURI);
        extension = StringUtils.getFilenameExtension(filename);
        if (!StringUtils.isEmpty(extension)) {
            int end = this.servletRequestURI.length() - extension.length() + 1;
            replacePath(this.servletRequestURI.substring(0, end));
        }
        this.servletRequestURI = null;
    }
    return extension;
}