java.lang.Object
org.omnifaces.util.ResourcePaths
Utility class for working with (Servlet) resource paths, providing methods to handle their prefixes, slashes, extensions etc.
This class is not listed in showcase! Should I use it?
This class is indeed intented for internal usage only. We won't add methods here on user request. We only add methods here once we encounter non-DRY code in OmniFaces codebase. The methods may be renamed/changed without notice.
We don't stop you from using it if you found it in the Javadoc and you think you find it useful, but you have to accept the risk that the method signatures can be changed without notice. This utility class exists because OmniFaces intends to be free of 3rd party dependencies.
- Since:
- 1.4
- Author:
- Arjan Tijms
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringaddLeadingSlashIfNecessary(String resourcePath) Add leading slash to given resource path if necessary.static StringaddTrailingSlashIfNecessary(String resourcePath) Add trailing slash to given resource path if necessary.static StringConcat given resource paths with the path separator.filterExtension(Set<String> resourcePaths) Filters away every resource path in the given set that has an extension.static StringgetExtension(String resourcePath) Gets the extension of given resource path if any.static booleanisDirectory(String resourcePath) Checks if the given resource path obtained fromServletContext.getResourcePaths(String)represents a directory.static booleanisExtensionless(String resourcePath) Checks if given resource path is extensionless.static booleanChecks if the given resource path represents the root.static StringstripExtension(String resourcePath) Strips the extension from the given resource path if any.static StringstripPrefixPath(String prefix, String resourcePath) Strips the given prefix from the given resource path if any.static StringstripTrailingSlash(String resourcePath) Strips the trailing slash(es) from the given resource path if any.
-
Field Details
-
PATH_SEPARATOR
The path separator, a forward slash/.- See Also:
-
EXTENSION_SEPARATOR
The extension separator, a period..- See Also:
-
-
Method Details
-
isDirectory
Checks if the given resource path obtained fromServletContext.getResourcePaths(String)represents a directory. That is, if it ends with "/".- Parameters:
resourcePath- The resource path to check.- Returns:
trueif the resource path represents a directory, false otherwise.
-
stripPrefixPath
Strips the given prefix from the given resource path if any.- Parameters:
prefix- The prefix to be stripped.resourcePath- The resource path to strip the prefix from.- Returns:
- The resource without the prefix path, or as-is if it didn't start with this prefix.
-
stripTrailingSlash
Strips the trailing slash(es) from the given resource path if any.- Parameters:
resourcePath- The resource path to strip the trailing slash from.- Returns:
- The resource without the trailing slash, or as-is if it didn't have a trailing slash.
- Since:
- 2.6
-
stripExtension
Strips the extension from the given resource path if any. This extension is defined as everything after the last occurrence of a period, including the period itself. E.g. input "index.xhtml" will return "index".- Parameters:
resourcePath- The resource path to strip the extension from.- Returns:
- The resource path without its extension, of as-is if it doesn't have an extension.
-
getExtension
Gets the extension of given resource path if any. This extension is defined as everything after the last occurrence of a period, including the period itself. E.g. input "index.xhtml" will return ".xhtml'.- Parameters:
resourcePath- The resource path to get the extension from.- Returns:
- the extension of the resource path, or null if it doesn't have an extension.
-
isExtensionless
Checks if given resource path is extensionless.- Parameters:
resourcePath- The resource path to check.- Returns:
trueif the resource path is extensionless, false otherwise.
-
filterExtension
Filters away every resource path in the given set that has an extension.- Parameters:
resourcePaths- A set of resource paths to be filtered- Returns:
- A set where no resource path has an extension. May be empty, but never null.
-
isRoot
Checks if the given resource path represents the root. That is, if it equals "/".- Parameters:
resourcePath- The resource path to check.- Returns:
trueif the resource path represents the root, false otherwise.- Since:
- 3.0
-
addLeadingSlashIfNecessary
Add leading slash to given resource path if necessary.- Parameters:
resourcePath- The resource paths to add leading slash to.- Returns:
- Resource path with leading slash.
- Since:
- 3.0
-
addTrailingSlashIfNecessary
Add trailing slash to given resource path if necessary.- Parameters:
resourcePath- The resource paths to add trailing slash to.- Returns:
- Resource path with trailing slash.
- Since:
- 3.0
-
concat
Concat given resource paths with the path separator.- Parameters:
resourcePaths- The resource paths to concat.- Returns:
- Concatenated resource paths.
- Since:
- 3.0
-