/android/import-contacts

To get this branch, use:
bzr branch http://bzr.ed.am/android/import-contacts

« back to all changes in this revision

Viewing changes to src/org/waxworlds/edam/importcontacts/VCFImporter.java

  • Committer: edam
  • Date: 2011-05-02 18:28:24 UTC
  • Revision ID: edam@waxworlds.org-20110502182824-acgdi3qfxfzqgely
- fixed logic for vcard field types (home, work, cell, etc) so it works
- updated NEWS and TODO
- rewrote most of ContactsCache, including a new ContactIdentifier class to identify contacts in the cache and new cache building code
- contacts now identified in the same way that Andoid displays them (by name, or organisation, or number, or email, in that order)
- propper handling and support for organisations and titles
- validation of imported contact now done by Importer, not VcfImporter
- separated sanitisation and normalisation (for cache lookups)
- generacised PhoneData, EmailData and AddressData classes
- ContactData is now aware of primary numbers, emails and organisations (defaults to the first prefrred one seen, or the first one seen where none is preferred)

Show diffs side-by-side

added added

removed removed

44
44
import java.util.regex.Matcher;
45
45
import java.util.regex.Pattern;
46
46
 
 
47
import org.waxworlds.edam.importcontacts.Importer.ContactData.ExtraDetail;
 
48
 
47
49
import android.content.SharedPreferences;
48
50
import android.provider.Contacts;
49
51
import android.provider.Contacts.PhonesColumns;
50
52
 
51
 
public class VcardImporter extends Importer
 
53
public class VCFImporter extends Importer
52
54
{
53
 
        private int _vcard_count = 0;
 
55
        private int _vCardCount = 0;
54
56
        private int _progress = 0;
55
57
 
56
 
        public VcardImporter( Doit doit )
 
58
        public VCFImporter( Doit doit )
57
59
        {
58
60
                super( doit );
59
61
        }
110
112
                        countVCardFile( files[ i ] );
111
113
                        setTmpProgress( i );
112
114
                }
113
 
                setProgressMax( _vcard_count ); // will also update tmp progress
 
115
                setProgressMax( _vCardCount );  // will also update tmp progress
114
116
 
115
117
                // import them
116
118
                setProgress( 0 );
117
119
                for( int i = 0; i < files.length; i++ )
118
120
                        importVCardFile( files[ i ] );
119
 
                setProgress( _vcard_count );
120
121
        }
121
122
 
122
123
        private void countVCardFile( File file ) throws AbortImportException
129
130
 
130
131
                        // read
131
132
                        String line;
132
 
                        boolean in_vcard = false;
 
133
                        boolean inVCard = false;
133
134
                        while( ( line = reader.readLine() ) != null )
134
135
                        {
135
 
                                if( !in_vcard ) {
 
136
                                if( !inVCard ) {
136
137
                                        // look for vcard beginning
137
138
                                        if( line.matches( "^BEGIN:VCARD" ) ) {
138
 
                                                in_vcard = true;
139
 
                                                _vcard_count++;
 
139
                                                inVCard = true;
 
140
                                                _vCardCount++;
140
141
                                        }
141
142
                                }
142
143
                                else if( line.matches( "^END:VCARD" ) )
143
 
                                        in_vcard = false;
 
144
                                        inVCard = false;
144
145
                        }
145
146
 
146
147
                }
169
170
                        FileInputStream istream = new FileInputStream( file );
170
171
                        byte[] content = new byte[ (int)file.length() ];
171
172
                        istream.read( content );
172
 
                        istream = null;
173
173
 
174
174
                        // import
175
175
                        importVCardFileContent( content, file.getName() );
187
187
                throws AbortImportException
188
188
        {
189
189
                // go through lines
190
 
                Vcard vcard = null;
191
 
                int vcard_start_line = 0;
 
190
                VCard vCard = null;
192
191
                ContentLineIterator cli = new ContentLineIterator( content );
193
192
                while( cli.hasNext() )
194
193
                {
205
204
                                line = "";
206
205
                        }
207
206
 
208
 
                        if( vcard == null ) {
 
207
                        if( vCard == null ) {
209
208
                                // look for vcard beginning
210
209
                                if( line.matches( "^BEGIN:VCARD" ) ) {
211
 
                                        setProgress( _progress++ );
212
 
                                        vcard = new Vcard();
213
 
                                        vcard_start_line = cli.getLineNumber();
 
210
                                        setProgress( ++_progress );
 
211
                                        vCard = new VCard();
214
212
                                }
215
213
                        }
216
214
                        else {
217
215
                                // look for vcard content or ending
218
216
                                if( line.matches( "^END:VCARD" ) )
219
217
                                {
220
 
                                        // finalise the vcard/contact
 
218
                                        // store vcard and do away with it
221
219
                                        try {
222
 
                                                vcard.finaliseVcard();
223
 
 
224
 
                                                // pass the finalised contact to the importer
225
 
                                                importContact( vcard );
226
 
                                        }
227
 
                                        catch( Vcard.ParseException e ) {
228
 
                                                if( !showContinue(
229
 
                                                        getText( R.string.error_vcf_parse ).toString()
230
 
                                                        + fileName +
231
 
                                                        getText( R.string.error_vcf_parse_line ).toString()
232
 
                                                        + cli.getLineNumber() + ":\n" + e.getMessage() ) )
233
 
                                                {
234
 
                                                        finish( ACTION_ABORT );
235
 
                                                }
236
 
                                                else
237
 
                                                        skipContact();
238
 
                                        }
239
 
                                        catch( ContactData.ContactNotIdentifiableException e ) {
240
 
                                                if( !showContinue(
241
 
                                                        getText( R.string.error_vcf_parse ).toString()
242
 
                                                        + fileName +
243
 
                                                        getText( R.string.error_vcf_parse_line ).toString()
244
 
                                                        + vcard_start_line + ":\n" + getText(
245
 
                                                                R.string.error_vcf_notenoughinfo ).toString()
246
 
                                                ) )
247
 
                                                {
248
 
                                                        finish( ACTION_ABORT );
249
 
                                                }
250
 
                                                else
251
 
                                                        skipContact();
252
 
                                        }
253
 
 
254
 
                                        // discard this vcard
255
 
                                        vcard = null;
 
220
                                                vCard.finaliseParsing();
 
221
                                                importContact( vCard );
 
222
                                        }
 
223
                                        catch( VCard.ParseException e ) {
 
224
                                                skipContact();
 
225
                                                if( !showContinue(
 
226
                                                        getText( R.string.error_vcf_parse ).toString()
 
227
                                                        + fileName + "\n" + e.getMessage() ) )
 
228
                                                {
 
229
                                                        finish( ACTION_ABORT );
 
230
                                                }
 
231
                                        }
 
232
                                        catch( VCard.SkipContactException e ) {
 
233
                                                skipContact();
 
234
                                                // do nothing
 
235
                                        }
 
236
                                        vCard = null;
256
237
                                }
257
238
                                else
258
239
                                {
259
240
                                        // try giving the line to the vcard
260
241
                                        try {
261
 
                                                vcard.parseLine( buffer, line,
 
242
                                                vCard.parseLine( buffer, line,
262
243
                                                        cli.doesNextLineLookFolded() );
263
244
                                        }
264
 
                                        catch( Vcard.ParseException e ) {
 
245
                                        catch( VCard.ParseException e ) {
265
246
                                                skipContact();
266
247
                                                if( !showContinue(
267
248
                                                        getText( R.string.error_vcf_parse ).toString()
268
 
                                                        + fileName +
269
 
                                                        getText( R.string.error_vcf_parse_line ).toString()
270
 
                                                        + cli.getLineNumber() + "\n" + e.getMessage() ) )
 
249
                                                        + fileName + "\n" + e.getMessage() ) )
271
250
                                                {
272
251
                                                        finish( ACTION_ABORT );
273
252
                                                }
275
254
                                                // although we're continuing, we still need to abort
276
255
                                                // this vCard. Further lines will be ignored until we
277
256
                                                // get to another BEGIN:VCARD line.
278
 
                                                vcard = null;
 
257
                                                vCard = null;
279
258
                                        }
280
 
                                        catch( Vcard.SkipImportException e ) {
 
259
                                        catch( VCard.SkipContactException e ) {
281
260
                                                skipContact();
282
261
                                                // abort this vCard. Further lines will be ignored until
283
262
                                                // we get to another BEGIN:VCARD line.
284
 
                                                vcard = null;
 
263
                                                vCard = null;
285
264
                                        }
286
265
                                }
287
266
                        }
292
271
        {
293
272
                protected byte[] _content = null;
294
273
                protected int _pos = 0;
295
 
                protected int _line = 0;
296
274
 
297
275
                public ContentLineIterator( byte[] content )
298
276
                {
318
296
                                        int to = ( _pos > 0 && _content[ _pos - 1 ] == '\r' &&
319
297
                                                _pos > initial_pos )? _pos - 1 : _pos;
320
298
                                        _pos++;
321
 
                                        _line++;
322
299
                                        return ByteBuffer.wrap( _content, initial_pos,
323
300
                                                to - initial_pos );
324
301
                                }
327
304
                        if( _pos != initial_pos ) {
328
305
                                int to = _pos;
329
306
                                _pos++;
330
 
                                _line++;
331
307
                                return ByteBuffer.wrap( _content, initial_pos,
332
308
                                        to - initial_pos );
333
309
                        }
352
328
                        return _pos > 0 && _pos < _content.length &&
353
329
                                _content[ _pos - 1 ] == '\n' && _content[ _pos ] == ' ';
354
330
                }
355
 
 
356
 
                public int getLineNumber()
357
 
                {
358
 
                        return _line;
359
 
                }
360
331
        }
361
332
 
362
 
        private class Vcard extends ContactData
 
333
        private class VCard extends ContactData
363
334
        {
364
335
                private final static int NAMELEVEL_NONE = 0;
365
 
                private final static int NAMELEVEL_N = 1;
366
 
                private final static int NAMELEVEL_FN = 2;
 
336
                private final static int NAMELEVEL_FN = 1;
 
337
                private final static int NAMELEVEL_N = 2;
367
338
 
368
339
                private final static int MULTILINE_NONE = 0;
369
340
                private final static int MULTILINE_ENCODED = 1; // v2.1 quoted-printable
413
384
 
414
385
                        public ParseException( int res )
415
386
                        {
416
 
                                super( VcardImporter.this.getText( res ).toString() );
 
387
                                super( VCFImporter.this.getText( res ).toString() );
417
388
                        }
418
389
                }
419
390
 
420
391
                @SuppressWarnings("serial")
421
 
                protected class SkipImportException extends Exception { }
 
392
                protected class SkipContactException extends Exception { }
422
393
 
423
394
                private String extractCollonPartFromLine( ByteBuffer buffer,
424
395
                        String line, boolean former )
460
431
 
461
432
                public void parseLine( ByteBuffer buffer, String line,
462
433
                        boolean next_line_looks_folded )
463
 
                        throws ParseException, SkipImportException,
 
434
                        throws ParseException, SkipContactException,
464
435
                        AbortImportException
465
436
                {
466
437
                        // do we have a version yet?
566
537
                                for( int i = 0; i < name_param_parts.length; i++ )
567
538
                                        name_param_parts[ i ] = name_param_parts[ i ].trim();
568
539
 
569
 
                                // determine whether we care about this entry
570
 
                                final HashSet< String > interesting_fields =
571
 
                                        new HashSet< String >( Arrays.asList( new String[]
572
 
                                                { "N", "FN", "ORG", "TITLE", "TEL", "EMAIL", "ADR" }
573
 
                                ) );
574
 
                                boolean is_interesting_field =
575
 
                                        interesting_fields.contains( name_param_parts[ 0 ] );
576
 
 
577
540
                                // parse encoding parameter
578
541
                                String encoding = checkParam( name_param_parts, "ENCODING" );
579
542
                                if( encoding != null ) encoding = encoding.toUpperCase();
580
 
                                if( is_interesting_field && encoding != null &&
581
 
                                        !encoding.equals( "8BIT" ) &&
 
543
                                if( encoding != null && !encoding.equals( "8BIT" ) &&
582
544
                                        !encoding.equals( "QUOTED-PRINTABLE" ) )
583
545
                                        //&& !encoding.equals( "BASE64" ) )
584
546
                                {
588
550
                                // parse charset parameter
589
551
                                String charset = checkParam( name_param_parts, "CHARSET" );
590
552
                                if( charset != null ) charset = charset.toUpperCase();
591
 
                                if( charset != null &&
592
 
                                        !charset.equals( "US-ASCII" ) &&
 
553
                                if( charset != null && !charset.equals( "US-ASCII" ) &&
593
554
                                        !charset.equals( "ASCII" ) &&
594
555
                                        !charset.equals( "UTF-8" ) )
595
556
                                {
609
570
                                                _parser_multiline_state = MULTILINE_ENCODED;
610
571
                                }
611
572
 
612
 
                                // convert 8-bit US-ASCII charset to UTF-8 (where no charset is
613
 
                                // specified for a v2.1 vcard entry, we assume it's US-ASCII)
614
 
                                if( ( charset == null && _version.equals( "2.1" ) ) ||
615
 
                                        ( charset != null && (
616
 
                                                charset.equals( "ASCII" ) ||
617
 
                                                charset.equals( "US-ASCII" ) ) ) )
618
 
                                {
 
573
                                // convert 8-bit ASCII charset to US-ASCII
 
574
                                if( charset == null || charset.equals( "ASCII" ) ) {
619
575
                                        value = transcodeAsciiToUtf8( value );
 
576
                                        charset = "UTF-8";
620
577
                                }
621
578
 
622
 
                                // process charset (value is now in UTF-8)
 
579
                                // process charset
623
580
                                String string_value;
624
581
                                try {
625
582
                                        string_value = new String( value.array(), value.position(),
626
 
                                                value.limit() - value.position(), "UTF-8" );
 
583
                                                value.limit() - value.position(), charset );
627
584
                                } catch( UnsupportedEncodingException e ) {
628
585
                                        throw new ParseException( R.string.error_vcf_charset );
629
586
                                }
694
651
                        return ( count & 1 ) == 1;
695
652
                }
696
653
 
697
 
                private String[] splitValueByCharacter( String value, char character )
 
654
                private String[] splitValueBySemicolon( String value )
698
655
                {
699
 
                        // split string in to parts by specified character
 
656
                        // split string in to parts by semicolon
700
657
                        ArrayList< String > parts = new ArrayList< String >(
701
 
                                Arrays.asList( value.split( "" + character ) ) );
 
658
                                Arrays.asList( value.split(  ";" ) ) );
702
659
 
703
660
                        // go through parts
704
661
                        for( int a = 0; a < parts.size(); a++ )
712
669
                                if( a < parts.size() - 1 &&
713
670
                                        doesStringEndInAnEscapeChar( str ) )
714
671
                                {
715
 
                                        // append the escaped character, join the next part to this
716
 
                                        // part and remove the next part
 
672
                                        // join the next part to this part and remove the next part
717
673
                                        parts.set( a, str.substring( 0, str.length() - 1 ) +
718
 
                                                character + parts.get( a + 1 ) );
 
674
                                                ';' + parts.get( a + 1 ) );
719
675
                                        parts.remove( a + 1 );
720
676
 
721
677
                                        // re-visit this part
732
688
                        return parts.toArray( ret );
733
689
                }
734
690
 
735
 
                private String unescapeValue( String value )
736
 
                {
737
 
                        StringBuilder ret = new StringBuilder( value.length() );
738
 
                        boolean in_escape = false;
739
 
                        for( int a = 0; a < value.length(); a++ )
740
 
                        {
741
 
                                int c = value.codePointAt( a );
742
 
 
743
 
                                // process a normal character
744
 
                                if( !in_escape ) {
745
 
                                        if( c == '\\' )
746
 
                                                in_escape = true;
747
 
                                        else
748
 
                                                ret.append( Character.toChars( c ) );
749
 
                                        continue;
750
 
                                }
751
 
 
752
 
                                // process an escape sequence
753
 
                                in_escape = false;
754
 
                                switch( c )
755
 
                                {
756
 
                                case 'N':
757
 
                                case 'n':
758
 
                                        // add newline
759
 
                                        ret.append( '\n' );
760
 
                                        break;
761
 
                                case '\\':
762
 
                                case ',':
763
 
                                case ';':
764
 
                                        // add escaped character
765
 
                                        ret.append( Character.toChars( c ) );
766
 
                                        break;
767
 
                                default:
768
 
                                        // unknown escape sequence, so add it unescaped
769
 
                                        ret.append( "\\" );
770
 
                                        ret.append( Character.toChars( c ) );
771
 
                                        break;
772
 
                                }
773
 
                        }
774
 
 
775
 
                        return ret.toString();
776
 
                }
777
 
 
778
691
                private void parseN( String[] params, String value )
779
692
                {
780
693
                        // already got a better name?
781
694
                        if( _name_level >= NAMELEVEL_N ) return;
782
695
 
783
696
                        // get name parts
784
 
                        String[] name_parts = splitValueByCharacter( value, ';' );
 
697
                        String[] name_parts = splitValueBySemicolon( value );
785
698
 
786
699
                        // build name
787
700
                        value = "";
788
 
                        final int[] part_order = { 3, 1, 2, 0, 4 };
789
 
                        for( int a = 0; a < part_order.length; a++ )
790
 
                                if( name_parts.length > part_order[ a ] &&
791
 
                                        name_parts[ part_order[ a ] ].length() > 0 )
792
 
                                {
793
 
                                        // split this part in to it's comma-separated bits
794
 
                                        String[] name_part_parts = splitValueByCharacter(
795
 
                                                name_parts[ part_order[ a ] ], ',' );
796
 
                                        for( int b = 0; b < name_part_parts.length; b++ )
797
 
                                                if( name_part_parts[ b ].length() > 0 )
798
 
                                                {
799
 
                                                        if( value.length() == 0 ) value += " ";
800
 
                                                        value += name_part_parts[ b ];
801
 
                                                }
802
 
                                }
 
701
                        if( name_parts.length > 1 && name_parts[ 1 ].length() > 0 )
 
702
                                value += name_parts[ 1 ];
 
703
                        if( name_parts.length > 0 && name_parts[ 0 ].length() > 0 )
 
704
                                value += ( value.length() == 0? "" : " " ) + name_parts[ 0 ];
803
705
 
804
706
                        // set name
805
 
                        setName( unescapeValue( value ) );
 
707
                        setName( value );
806
708
                        _name_level = NAMELEVEL_N;
807
709
                }
808
710
 
812
714
                        if( _name_level >= NAMELEVEL_FN ) return;
813
715
 
814
716
                        // set name
815
 
                        setName( unescapeValue( value ) );
 
717
                        setName( value );
816
718
                        _name_level = NAMELEVEL_FN;
817
719
                }
818
720
 
819
721
                private void parseORG( String[] params, String value )
820
722
                {
821
723
                        // get org parts
822
 
                        String[] org_parts = splitValueByCharacter( value, ';' );
 
724
                        String[] org_parts = splitValueBySemicolon( value );
823
725
                        if( org_parts == null || org_parts.length < 1 ) return;
824
726
 
825
727
                        // build organisation name
827
729
                                String.valueOf( org_parts[ 0 ] ) );
828
730
                        for( int a = 1; a < org_parts.length; a++ )
829
731
                                builder.append( ", " ).append( org_parts[ a ] );
830
 
                        String organisation = unescapeValue( builder.toString() );
 
732
                        String organisation = builder.toString();
831
733
 
832
734
                        // set organisation name (using a title we've previously found)
833
735
                        addOrganisation( organisation, _cached_title, true );
844
746
 
845
747
                private void parseTITLE( String[] params, String value )
846
748
                {
847
 
                        value = unescapeValue( value );
848
 
 
849
749
                        // if we previously had an organisation, look it up and append this
850
750
                        // title to it
851
751
                        if( _cached_organisation != null && hasOrganisations() ) {
873
773
                                "PAGER", "BBS", "MODEM", "CAR", "ISDN", "VIDEO" ) );
874
774
 
875
775
                        // here's the logic...
876
 
                        boolean is_preferred = types.contains( "PREF" );
 
776
                        boolean preferred = types.contains( "PREF" );
877
777
                        int type;
878
778
                        if( types.contains( "FAX" ) )
879
779
                                if( types.contains( "HOME" ) )
890
790
                                type = PhonesColumns.TYPE_HOME;
891
791
 
892
792
                        // add phone number
893
 
                        addNumber( value, type, is_preferred );
 
793
                        addNumber( value, type, preferred );
894
794
                }
895
795
 
896
796
                public void parseEMAIL( String[] params, String value )
901
801
                                "PREF", "WORK", "HOME", "INTERNET" ) );
902
802
 
903
803
                        // add email address
904
 
                        boolean is_preferred = types.contains( "PREF" );
 
804
                        boolean preferred = types.contains( "PREF" );
905
805
                        int type;
906
806
                        if( types.contains( "WORK" ) )
907
807
                                type = Contacts.ContactMethods.TYPE_WORK;
908
808
                        else
909
809
                                type = Contacts.ContactMethods.TYPE_HOME;
910
810
 
911
 
                        addEmail( unescapeValue( value ), type, is_preferred );
 
811
                        addEmail( value, type, preferred );
912
812
                }
913
813
 
914
814
                private void parseADR( String[] params, String value )
915
815
                {
916
816
                        // get address parts
917
 
                        String[] adr_parts = splitValueByCharacter( value, ';' );
 
817
                        String[] adr_parts = splitValueBySemicolon( value );
918
818
 
919
819
                        // build address
920
820
                        value = "";
921
 
                        for( int a = 0; a < adr_parts.length; a++ )
922
 
                                if( adr_parts[ a ].length() > 0 )
923
 
                                {
924
 
                                        // split this part in to it's comma-separated bits
925
 
                                        String[] adr_part_parts =
926
 
                                                splitValueByCharacter( adr_parts[ a ], ',' );
927
 
                                        for( int b = 0; b < adr_part_parts.length; b++ )
928
 
                                                if( adr_part_parts[ b ].length() > 0 )
929
 
                                                {
930
 
                                                        if( value.length() > 0 ) value += "\n";
931
 
                                                        value += adr_part_parts[ b ];
932
 
                                                }
933
 
                                }
 
821
                        for( int a = 0; a < adr_parts.length; a++ ) {
 
822
                                if( value.length() > 0 ) value += "\n";
 
823
                                value += adr_parts[ a ].trim();
 
824
                        }
934
825
 
935
826
                        Set< String > types = extractTypes( params, Arrays.asList(
936
827
                                "PREF", "WORK", "HOME", "INTERNET" ) );
942
833
                        else
943
834
                                type = Contacts.ContactMethods.TYPE_HOME;
944
835
 
945
 
                        addAddress( unescapeValue( value ), type );
 
836
                        addAddress( value, type );
946
837
                }
947
838
 
948
 
                public void finaliseVcard()
949
 
                        throws ParseException, ContactNotIdentifiableException
 
839
                public void finaliseParsing()
 
840
                        throws ParseException, SkipContactException,
 
841
                        AbortImportException
950
842
                {
951
843
                        // missing version (and data is present)
952
844
                        if( _version == null && _buffers != null )
953
845
                                throw new ParseException( R.string.error_vcf_malformed );
954
846
 
955
 
                        // finalise the parent class
956
 
                        finalise();
 
847
                        // check if we should import this contact
 
848
                        try {
 
849
                                if( !isImportRequired( this ) )
 
850
                                        throw new SkipContactException();
 
851
                        }
 
852
                        catch( ContactNeedsMoreInfoException e ) {
 
853
                                throw new ParseException( R.string.error_vcf_notenoughinfo );
 
854
                        }
957
855
                }
958
856
 
959
 
                /**
960
 
                 * Amongst the params, find the value of the first, only, of any with
961
 
                 * the specified name
962
 
                 * @param params
963
 
                 * @param name
964
 
                 * @return a value, or null
965
 
                 */
966
857
                private String checkParam( String[] params, String name )
967
858
                {
968
 
                        String[] res = checkParams( params, name );
969
 
                        return res.length > 0? res[ 0 ] : null;
970
 
                }
971
 
 
972
 
                /**
973
 
                 * Amongst the params, find the values of any with the specified name
974
 
                 * @param params
975
 
                 * @param name
976
 
                 * @return an array of values, or null
977
 
                 */
978
 
                private String[] checkParams( String[] params, String name )
979
 
                {
980
 
                        HashSet< String > ret = new HashSet< String >();
981
 
 
982
859
                        Pattern p = Pattern.compile(
983
860
                                "^" + name + "[ \\t]*=[ \\t]*(\"?)(.*)\\1$" );
984
861
                        for( int i = 0; i < params.length; i++ ) {
985
862
                                Matcher m = p.matcher( params[ i ] );
986
863
                                if( m.matches() )
987
 
                                        ret.add( m.group( 2 ) );
 
864
                                        return m.group( 2 );
988
865
                        }
989
 
 
990
 
                        return (String[]) ret.toArray( new String[ ret.size() ] );
 
866
                        return null;
991
867
                }
992
868
 
993
 
                /**
994
 
                 * Amongst the params, return any type values present. For v2.1 vCards,
995
 
                 * those types are just parameters. For v3.0, they are prefixed with
996
 
                 * "TYPE=". There may also be multiple type parameters.
997
 
                 * @param params
998
 
                 * @param a list of type values to look for
999
 
                 * @return a set of present type values
1000
 
                 */
1001
869
                private Set< String > extractTypes( String[] params,
1002
870
                        List< String > valid_types )
1003
871
                {
1004
872
                        HashSet< String > types = new HashSet< String >();
1005
873
 
1006
874
                        // get 3.0-style TYPE= param
1007
 
                        String type_params[] = checkParams( params, "TYPE" );
1008
 
                        for( int a = 0; a < type_params.length; a++ )
1009
 
                        {
1010
 
                                // check for a comma-separated list of types (why? this isn't in
1011
 
                                // the specs!)
1012
 
                                String[] parts = type_params[ a ].split( "," );
 
875
                        String type_param;
 
876
                        if( ( type_param = checkParam( params, "TYPE" ) ) != null ) {
 
877
                                String[] parts = type_param.split( "," );
1013
878
                                for( int i = 0; i < parts.length; i++ )
1014
879
                                        if( valid_types.contains( parts[ i ] ) )
1015
880
                                                types.add( parts[ i ] );