Class PrefixingPathContext

java.lang.Object
com.foreach.across.modules.web.context.PrefixingPathContext
All Implemented Interfaces:
WebAppPathResolver
Direct Known Subclasses:
WebJarsPathContext

public class PrefixingPathContext extends Object implements WebAppPathResolver
Helper class for relative urls that need a prefix. Any path passed to this instance will be prefixed unless an exception is defined. Possible exceptions are:
  • path starts with !: only exclamation mark will be removed, no prefixing will be done (supress prefixing)
  • path starts with ~: will not be modified
  • path contains ://: considered absolute url - will not be modified
  • path starts with @prefixer:: will be re-routed to the prefixer with that name if present
The helper also supports redirect: and forward: urls.
Optionally an additional map of named prefixers can be added setNamedPrefixMap(java.util.Map). Urls containing one of these names in the correct format (eg: @somePrefixer:/myPath) will be prefixed by that prefixer instead of the current one.
See Also:
  • Field Details

  • Constructor Details

    • PrefixingPathContext

      public PrefixingPathContext(@NonNull @NonNull String prefix)
  • Method Details

    • setNamedPrefixMap

      public void setNamedPrefixMap(@NonNull @NonNull Map<String,PrefixingPathContext> namedPrefixers)
      Sets a collection of prefixing contexts with a name. Any paths starting with {NAME} will find re-routed to the named prefixer instead of handled by the current prefixing context.
      Parameters:
      namedPrefixers - Map of namedPrefixers, should not be null.
    • getRoot

      public String getRoot()
      Returns:
      Root of the prefixed context (no sub path).
    • getPathPrefix

      public String getPathPrefix()
    • path

      public String path(String path)
      Description copied from interface: WebAppPathResolver
      Resolves the requested path in the relative context of the web application. Note that this does not take the actual web application context of the container into account.
      Specified by:
      path in interface WebAppPathResolver
      Parameters:
      path - Original path to be resolved.
      Returns:
      Resolved path - might be modified.
    • redirect

      public String redirect(String path)
      Description copied from interface: WebAppPathResolver
      Creates a Spring MVC redirect for the requested path. This will usually apply the regular path resolving and prepend redirect: if necessary.
      Specified by:
      redirect in interface WebAppPathResolver
      Parameters:
      path - Original path for which to create a redirect.
      Returns:
      Redirect path.
    • applyPrefixToPath

      protected String applyPrefixToPath(String prefix, String path)