Class ResourcePaths

java.lang.Object
org.omnifaces.util.ResourcePaths

public final class ResourcePaths extends Object
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 Details

  • Method Details

    • isDirectory

      public static boolean isDirectory(String resourcePath)
      Checks if the given resource path obtained from ServletContext.getResourcePaths(String) represents a directory. That is, if it ends with "/".
      Parameters:
      resourcePath - The resource path to check.
      Returns:
      true if the resource path represents a directory, false otherwise.
    • stripPrefixPath

      public static String stripPrefixPath(String prefix, String resourcePath)
      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

      public static String stripTrailingSlash(String resourcePath)
      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

      public static String stripExtension(String resourcePath)
      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

      public static String getExtension(String resourcePath)
      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

      public static boolean isExtensionless(String resourcePath)
      Checks if given resource path is extensionless.
      Parameters:
      resourcePath - The resource path to check.
      Returns:
      true if the resource path is extensionless, false otherwise.
    • filterExtension

      public static Set<String> filterExtension(Set<String> resourcePaths)
      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

      public static boolean isRoot(String resourcePath)
      Checks if the given resource path represents the root. That is, if it equals "/".
      Parameters:
      resourcePath - The resource path to check.
      Returns:
      true if the resource path represents the root, false otherwise.
      Since:
      3.0
    • addLeadingSlashIfNecessary

      public static String addLeadingSlashIfNecessary(String resourcePath)
      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

      public static String addTrailingSlashIfNecessary(String resourcePath)
      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

      public static String concat(String... resourcePaths)
      Concat given resource paths with the path separator.
      Parameters:
      resourcePaths - The resource paths to concat.
      Returns:
      Concatenated resource paths.
      Since:
      3.0