Class PathLocaliser
java.lang.Object
de.gustavblass.fsu.fmi.roombooking.service.PathLocaliser
Translates
URIs based on a localisedPathSource.- Implementation Note:
- Not a record, because the localised path source shall not be public.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @NonNull org.springframework.context.MessageSourceUsed to resolve the given path codes to translated path strings. -
Constructor Summary
ConstructorsConstructorDescriptionPathLocaliser(@NonNull org.springframework.context.MessageSource localisedPathSource) Constructs a newPathLocaliser. -
Method Summary
Modifier and TypeMethodDescription@NonNull URIRetrieves the given path code from thelocalisedPathSourceand converts it to aURI.@NonNull StringresolveAsString(@NonNull String path, @NonNull Locale locale, @Nullable Object... arguments) Retrieves the given path code from thelocalisedPathSourceand first converts it to aURIand then to an ASCII string.
-
Field Details
-
localisedPathSource
@NonNull private final @NonNull org.springframework.context.MessageSource localisedPathSourceUsed to resolve the given path codes to translated path strings.
-
-
Constructor Details
-
PathLocaliser
public PathLocaliser(@NonNull @NonNull org.springframework.context.MessageSource localisedPathSource) Constructs a newPathLocaliser.- Parameters:
localisedPathSource- ThelocalisedPathSource.
-
-
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 thelocalisedPathSourceand converts it to aURI.- 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 theMessageSourceor 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 thelocalisedPathSourceand first converts it to aURIand 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 theMessageSourceor if the path is not a valid URI.
-