569
569
// determine whether we care about this entry
570
570
final HashSet< String > interesting_fields =
571
new HashSet< String >( Arrays.asList( new String[] { "N",
572
"FN", "ORG", "TITLE", "TEL", "EMAIL", "ADR", "LABEL" }
571
new HashSet< String >( Arrays.asList( new String[]
572
{ "N", "FN", "ORG", "TITLE", "TEL", "EMAIL", "ADR" }
574
574
boolean is_interesting_field =
575
575
interesting_fields.contains( name_param_parts[ 0 ] );
676
676
parseEMAIL( name_param_parts, complete_value );
677
677
else if( name_param_parts[ 0 ].equals( "ADR" ) )
678
678
parseADR( name_param_parts, complete_value );
679
else if( name_param_parts[ 0 ].equals( "LABEL" ) )
680
parseLABEL( name_param_parts, complete_value );
937
935
Set< String > types = extractTypes( params, Arrays.asList(
938
"PREF", "WORK", "HOME" ) );
942
if( types.contains( "WORK" ) )
943
type = Contacts.ContactMethods.TYPE_WORK;
945
type = Contacts.ContactMethods.TYPE_HOME;
947
addAddress( unescapeValue( value ), type );
950
private void parseLABEL( String[] params, String value )
952
Set< String > types = extractTypes( params, Arrays.asList(
953
"PREF", "WORK", "HOME" ) );
936
"PREF", "WORK", "HOME", "INTERNET" ) );
977
* Amongst the params, find the value of the first, only, of any with
981
* @return a value, or null
983
959
private String checkParam( String[] params, String name )
985
String[] res = checkParams( params, name );
986
return res.length > 0? res[ 0 ] : null;
990
* Amongst the params, find the values of any with the specified name
993
* @return an array of values, or null
995
private String[] checkParams( String[] params, String name )
997
HashSet< String > ret = new HashSet< String >();
999
961
Pattern p = Pattern.compile(
1000
962
"^" + name + "[ \\t]*=[ \\t]*(\"?)(.*)\\1$" );
1001
963
for( int i = 0; i < params.length; i++ ) {
1002
964
Matcher m = p.matcher( params[ i ] );
1003
965
if( m.matches() )
1004
ret.add( m.group( 2 ) );
1007
return (String[]) ret.toArray( new String[ ret.size() ] );
1011
* Amongst the params, return any type values present. For v2.1 vCards,
1012
* those types are just parameters. For v3.0, they are prefixed with
1013
* "TYPE=". There may also be multiple type parameters.
1015
* @param a list of type values to look for
1016
* @return a set of present type values
1018
971
private Set< String > extractTypes( String[] params,
1019
972
List< String > valid_types )
1021
974
HashSet< String > types = new HashSet< String >();
1023
976
// get 3.0-style TYPE= param
1024
String type_params[] = checkParams( params, "TYPE" );
1025
for( int a = 0; a < type_params.length; a++ )
1027
// check for a comma-separated list of types (why? this isn't in
1029
String[] parts = type_params[ a ].split( "," );
978
if( ( type_param = checkParam( params, "TYPE" ) ) != null ) {
979
String[] parts = type_param.split( "," );
1030
980
for( int i = 0; i < parts.length; i++ )
1031
981
if( valid_types.contains( parts[ i ] ) )
1032
982
types.add( parts[ i ] );