Class LocalizationHelper


  • @Component
    public class LocalizationHelper
    extends java.lang.Object
    Component to work with string resources . Current realization use only one source file but can be extended with Locale options and new files with messages-{locale}.properties files.
    Since:
    1.1
    Author:
    Martynenko Anton
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Optional<java.lang.String> extract​(java.lang.String extractFrom, MessageCode messageCode)
      Get regex pattern string as resource by provided code, then extract value from provided text fragment .
      java.lang.String getMessage​(MessageCode messageCode)
      Get string resource by provided code.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LocalizationHelper

        public LocalizationHelper()
    • Method Detail

      • getMessage

        @NotNull
        public java.lang.String getMessage​(@NotNull
                                           MessageCode messageCode)
                                    throws org.springframework.context.NoSuchMessageException
        Get string resource by provided code.
        Parameters:
        messageCode - MessageCode enumeration
        Returns:
        String resource
        Throws:
        org.springframework.context.NoSuchMessageException - if no resource with provided code
      • extract

        @NotNull
        public java.util.Optional<java.lang.String> extract​(@NotNull
                                                            java.lang.String extractFrom,
                                                            @NotNull
                                                            MessageCode messageCode)
                                                     throws java.util.NoSuchElementException
        Get regex pattern string as resource by provided code, then extract value from provided text fragment .
        Parameters:
        extractFrom - string fragment, containing value which could be extracted using pattern
        messageCode - MessageCode enumeration
        Returns:
        String value or null
        Throws:
        java.util.NoSuchElementException