public static Vector extractLocales ( Vector languages , boolean secure ) { init ( ) ; Enumeration e = languages . elements ( ) ; Vector l = new Vector ( ) ; while ( e . hasMoreElements ( ) ) { Vector langVector = ( Vector ) e . nextElement ( ) ; Enumeration enumeration = langVector . elements ( ) ; while ( enumeration . hasMoreElements ( ) ) { String language = ( String ) enumeration . nextElement ( ) ; String country = "" ; String variant = "" ; int countryIndex = language . indexOf ( "-" ) ; if ( countryIndex > - 1 ) { country = language . substring ( countryIndex + 1 ) . trim ( ) ; language = language . substring ( 0 , countryIndex ) . trim ( ) ; int variantIndex = country . indexOf ( "-" ) ; if ( variantIndex > - 1 ) { variant = country . substring ( variantIndex + 1 ) . trim ( ) ; country = country . substring ( 0 , variantIndex ) . trim ( ) ; } } if ( secure ) { if ( ( country . trim ( ) . length ( ) != 0 && ! isValueAlphaNumeric ( country , "country" ) ) || ( language . trim ( ) . length ( ) != 0 && ! isValueAlphaNumeric ( language , "language" ) ) ) { language = Locale . getDefault ( ) . getLanguage ( ) ; country = Locale . getDefault ( ) . getCountry ( ) ; variant = "" ; } if ( variant . trim ( ) . length ( ) != 0 && ! isValueAlphaNumeric ( variant , "variant" ) ) { variant = "" ; } } l . addElement ( new Locale ( language , country , variant ) ) ; } } return l ; }
This method will validate the values .