public static Format getFormatter ( @ Nonnull final Locale locale , @ Nonnull final String format , @ Nullable final Class < ? > ... type ) { Format formatter = null ; Pattern TEXT_FORMAT_STRING = Pattern . compile ( "^\\{([^}]+)}(.+)$" ) ; Matcher matcher = TEXT_FORMAT_STRING . matcher ( format ) ; if ( matcher . matches ( ) ) { switch ( matcher . group ( 1 ) ) { case "Message" : formatter = new MessageFormat ( matcher . group ( 2 ) , locale ) ; break ; case "Date" : formatter = new SimpleDateFormat ( matcher . group ( 2 ) , locale ) ; break ; case "String" : formatter = new FormatterFormat ( matcher . group ( 2 ) , locale ) ; break ; default : case "Log" : formatter = new LoggerFormat ( matcher . group ( 2 ) ) ; break ; } } else { if ( type != null && type . length == 1 && type [ 0 ] != null && ( Calendar . class . isAssignableFrom ( type [ 0 ] ) || Date . class . isAssignableFrom ( type [ 0 ] ) ) ) { formatter = new SimpleDateFormat ( format , locale ) ; } else { formatter = new LoggerFormat ( format ) ; } } return formatter ; }
Creates the formatter for a describing string rule