public static LocaleFacet createFor ( final String localeString , final Log log ) throws MojoExecutionException { // Check sanity Validate . notNull ( log , "log" ) ; Validate . notEmpty ( localeString , "localeString" ) ; final StringTokenizer tok = new StringTokenizer ( localeString , "," , false ) ; final int numTokens = tok . countTokens ( ) ; if ( numTokens > 3 || numTokens == 0 ) { throw new MojoExecutionException ( "A localeString must consist of up to 3 comma-separated parts on the " + "form <language>[,<country>[,<variant>]]. Received incorrect value '" + localeString + "'" ) ; } // Extract the locale configuration data. final String language = tok . nextToken ( ) . trim ( ) ; final String country = numTokens > 1 ? tok . nextToken ( ) . trim ( ) : null ; final String variant = numTokens > 2 ? tok . nextToken ( ) . trim ( ) : null ; // All done. return new LocaleFacet ( log , findOptimumLocale ( language , country , variant ) ) ; }
Helper method used to parse a locale configuration string into a Locale instance .