Class PathLocaliser

java.lang.Object
de.gustavblass.fsu.fmi.roombooking.service.PathLocaliser

public class PathLocaliser extends Object
Translates URIs based on a localisedPathSource.
Implementation Note:
Not a record, because the localised path source shall not be public.
  • Field Details

    • localisedPathSource

      @NonNull private final @NonNull org.springframework.context.MessageSource localisedPathSource
      Used to resolve the given path codes to translated path strings.
  • Constructor Details

    • PathLocaliser

      public PathLocaliser(@NonNull @NonNull org.springframework.context.MessageSource localisedPathSource)
      Constructs a new PathLocaliser.
      Parameters:
      localisedPathSource - The localisedPathSource.
  • Method Details

    • resolve

      @NonNull public @NonNull URI resolve(@NonNull @NonNull String path, @NonNull @NonNull Locale locale, @Nullable @Nullable Object... arguments) throws IllegalStateException
      Retrieves the given path code from the localisedPathSource and converts it to a URI.
      Parameters:
      path - The code of the path that shall be localised.
      locale - The language into which the path shall be translated.
      arguments - Parameters which determine the formatting of the path. Necessary for some paths, but not all.
      Returns:
      The path from the MessageSource, as a URI translated into the given language.
      Throws:
      IllegalStateException - If no path with the given code was found in the MessageSource or if the path is not a valid URI.
    • resolveAsString

      @NonNull public @NonNull String resolveAsString(@NonNull @NonNull String path, @NonNull @NonNull Locale locale, @Nullable @Nullable Object... arguments) throws IllegalStateException
      Retrieves the given path code from the localisedPathSource and first converts it to a URI and then to an ASCII string.
      Parameters:
      path - The code of the path that shall be localised.
      locale - The language into which the path shall be translated.
      arguments - Parameters which determine the formatting of the path. Necessary for some paths, but not all.
      Returns:
      The path from the MessageSource, as a URI translated into the given language.
      Throws:
      IllegalStateException - If no path with the given code was found in the MessageSource or if the path is not a valid URI.