/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/am/ed/importcontacts/VcardImporter.java

  • Committer: edam
  • Date: 2012-12-20 17:16:08 UTC
  • Revision ID: tim@ed.am-20121220171608-vx41zykf4krel9xf
slightly improved the efficiency of the cache identifier factory function

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * VCFImporter.java
3
3
 *
4
 
 * Copyright (C) 2009 to 2011 Tim Marston <edam@waxworlds.org>
 
4
 * Copyright (C) 2009 to 2011 Tim Marston <tim@ed.am>
5
5
 *
6
6
 * This file is part of the Import Contacts program (hereafter referred
7
7
 * to as "this program"). For more information, see
8
 
 * http://www.waxworlds.org/edam/software/android/import-contacts
 
8
 * http://ed.am/dev/android/import-contacts
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
11
11
 * it under the terms of the GNU General Public License as published by
21
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
22
 */
23
23
 
24
 
package org.waxworlds.edam.importcontacts;
 
24
package am.ed.importcontacts;
25
25
 
26
26
import java.io.BufferedReader;
27
27
import java.io.File;
38
38
import java.util.HashSet;
39
39
import java.util.Iterator;
40
40
import java.util.List;
 
41
import java.util.Locale;
41
42
import java.util.NoSuchElementException;
42
43
import java.util.Set;
43
44
import java.util.Vector;
44
45
import java.util.regex.Matcher;
45
46
import java.util.regex.Pattern;
46
47
 
 
48
import android.annotation.SuppressLint;
47
49
import android.content.SharedPreferences;
48
 
import android.provider.Contacts;
49
 
import android.provider.Contacts.PhonesColumns;
50
50
 
51
51
public class VcardImporter extends Importer
52
52
{
58
58
                super( doit );
59
59
        }
60
60
 
 
61
        @SuppressLint( "SdCardPath" )
61
62
        @Override
62
63
        protected void onImport() throws AbortImportException
63
64
        {
82
83
                                // get files
83
84
                                class VCardFilter implements FilenameFilter {
84
85
                                        public boolean accept( File dir, String name ) {
85
 
                                                return name.toLowerCase().endsWith( ".vcf" );
 
86
                                                return name.toLowerCase( Locale.US ).endsWith( ".vcf" );
86
87
                                        }
87
88
                                }
88
89
                                files = file.listFiles( new VCardFilter() );
116
117
                setProgress( 0 );
117
118
                for( int i = 0; i < files.length; i++ )
118
119
                        importVCardFile( files[ i ] );
 
120
                setProgress( _vcard_count );
119
121
        }
120
122
 
121
123
        private void countVCardFile( File file ) throws AbortImportException
168
170
                        FileInputStream istream = new FileInputStream( file );
169
171
                        byte[] content = new byte[ (int)file.length() ];
170
172
                        istream.read( content );
 
173
                        istream = null;
171
174
 
172
175
                        // import
173
176
                        importVCardFileContent( content, file.getName() );
186
189
        {
187
190
                // go through lines
188
191
                Vcard vcard = null;
 
192
                int vcard_start_line = 0;
189
193
                ContentLineIterator cli = new ContentLineIterator( content );
190
194
                while( cli.hasNext() )
191
195
                {
205
209
                        if( vcard == null ) {
206
210
                                // look for vcard beginning
207
211
                                if( line.matches( "^BEGIN:VCARD" ) ) {
208
 
                                        setProgress( ++_progress );
 
212
                                        setProgress( _progress++ );
209
213
                                        vcard = new Vcard();
 
214
                                        vcard_start_line = cli.getLineNumber();
210
215
                                }
211
216
                        }
212
217
                        else {
216
221
                                        // finalise the vcard/contact
217
222
                                        try {
218
223
                                                vcard.finaliseVcard();
 
224
 
 
225
                                                // pass the finalised contact to the importer
 
226
                                                importContact( vcard );
219
227
                                        }
220
228
                                        catch( Vcard.ParseException e ) {
221
 
                                                skipContact();
222
 
                                                if( !showContinue(
223
 
                                                        getText( R.string.error_vcf_parse ).toString()
224
 
                                                        + fileName + "\n" + e.getMessage() ) )
225
 
                                                {
226
 
                                                        finish( ACTION_ABORT );
227
 
                                                }
228
 
                                        }
229
 
 
230
 
                                        // pass the finalised contact to the importer
231
 
                                        importContact( vcard );
232
 
 
233
 
                                        // and discard it
 
229
                                                if( !showContinue(
 
230
                                                        getText( R.string.error_vcf_parse ).toString()
 
231
                                                        + fileName +
 
232
                                                        getText( R.string.error_vcf_parse_line ).toString()
 
233
                                                        + cli.getLineNumber() + ":\n" + e.getMessage() ) )
 
234
                                                {
 
235
                                                        finish( ACTION_ABORT );
 
236
                                                }
 
237
                                                else
 
238
                                                        skipContact();
 
239
                                        }
 
240
                                        catch( ContactData.ContactNotIdentifiableException e ) {
 
241
                                                if( !showContinue(
 
242
                                                        getText( R.string.error_vcf_parse ).toString()
 
243
                                                        + fileName +
 
244
                                                        getText( R.string.error_vcf_parse_line ).toString()
 
245
                                                        + vcard_start_line + ":\n" + getText(
 
246
                                                                R.string.error_vcf_notenoughinfo ).toString()
 
247
                                                ) )
 
248
                                                {
 
249
                                                        finish( ACTION_ABORT );
 
250
                                                }
 
251
                                                else
 
252
                                                        skipContact();
 
253
                                        }
 
254
 
 
255
                                        // discard this vcard
234
256
                                        vcard = null;
235
257
                                }
236
258
                                else
244
266
                                                skipContact();
245
267
                                                if( !showContinue(
246
268
                                                        getText( R.string.error_vcf_parse ).toString()
247
 
                                                        + fileName + "\n" + e.getMessage() ) )
 
269
                                                        + fileName +
 
270
                                                        getText( R.string.error_vcf_parse_line ).toString()
 
271
                                                        + cli.getLineNumber() + "\n" + e.getMessage() ) )
248
272
                                                {
249
273
                                                        finish( ACTION_ABORT );
250
274
                                                }
269
293
        {
270
294
                protected byte[] _content = null;
271
295
                protected int _pos = 0;
 
296
                protected int _line = 0;
272
297
 
273
298
                public ContentLineIterator( byte[] content )
274
299
                {
294
319
                                        int to = ( _pos > 0 && _content[ _pos - 1 ] == '\r' &&
295
320
                                                _pos > initial_pos )? _pos - 1 : _pos;
296
321
                                        _pos++;
 
322
                                        _line++;
297
323
                                        return ByteBuffer.wrap( _content, initial_pos,
298
324
                                                to - initial_pos );
299
325
                                }
302
328
                        if( _pos != initial_pos ) {
303
329
                                int to = _pos;
304
330
                                _pos++;
 
331
                                _line++;
305
332
                                return ByteBuffer.wrap( _content, initial_pos,
306
333
                                        to - initial_pos );
307
334
                        }
326
353
                        return _pos > 0 && _pos < _content.length &&
327
354
                                _content[ _pos - 1 ] == '\n' && _content[ _pos ] == ' ';
328
355
                }
 
356
 
 
357
                public int getLineNumber()
 
358
                {
 
359
                        return _line;
 
360
                }
329
361
        }
330
362
 
331
363
        private class Vcard extends ContactData
332
364
        {
333
365
                private final static int NAMELEVEL_NONE = 0;
334
 
                private final static int NAMELEVEL_FN = 1;
335
 
                private final static int NAMELEVEL_N = 2;
 
366
                private final static int NAMELEVEL_N = 1;
 
367
                private final static int NAMELEVEL_FN = 2;
336
368
 
337
369
                private final static int MULTILINE_NONE = 0;
338
370
                private final static int MULTILINE_ENCODED = 1; // v2.1 quoted-printable
535
567
                                for( int i = 0; i < name_param_parts.length; i++ )
536
568
                                        name_param_parts[ i ] = name_param_parts[ i ].trim();
537
569
 
 
570
                                // determine whether we care about this entry
 
571
                                final HashSet< String > interesting_fields =
 
572
                                        new HashSet< String >( Arrays.asList( new String[] { "N",
 
573
                                                "FN", "ORG", "TITLE", "TEL", "EMAIL", "ADR", "LABEL" }
 
574
                                ) );
 
575
                                boolean is_interesting_field =
 
576
                                        interesting_fields.contains( name_param_parts[ 0 ] );
 
577
 
538
578
                                // parse encoding parameter
539
579
                                String encoding = checkParam( name_param_parts, "ENCODING" );
540
 
                                if( encoding != null ) encoding = encoding.toUpperCase();
541
 
                                if( encoding != null && !encoding.equals( "8BIT" ) &&
 
580
                                if( encoding != null )
 
581
                                        encoding = encoding.toUpperCase( Locale.US );
 
582
                                if( is_interesting_field && encoding != null &&
 
583
                                        !encoding.equals( "8BIT" ) &&
542
584
                                        !encoding.equals( "QUOTED-PRINTABLE" ) )
543
585
                                        //&& !encoding.equals( "BASE64" ) )
544
586
                                {
547
589
 
548
590
                                // parse charset parameter
549
591
                                String charset = checkParam( name_param_parts, "CHARSET" );
550
 
                                if( charset != null ) charset = charset.toUpperCase();
551
 
                                if( charset != null && !charset.equals( "US-ASCII" ) &&
 
592
                                if( charset != null )
 
593
                                        charset = charset.toUpperCase( Locale.US );
 
594
                                if( charset != null &&
 
595
                                        !charset.equals( "US-ASCII" ) &&
552
596
                                        !charset.equals( "ASCII" ) &&
553
597
                                        !charset.equals( "UTF-8" ) )
554
598
                                {
568
612
                                                _parser_multiline_state = MULTILINE_ENCODED;
569
613
                                }
570
614
 
571
 
                                // convert 8-bit ASCII charset to US-ASCII
572
 
                                if( charset == null || charset.equals( "ASCII" ) ) {
 
615
                                // convert 8-bit US-ASCII charset to UTF-8 (where no charset is
 
616
                                // specified for a v2.1 vcard entry, we assume it's US-ASCII)
 
617
                                if( ( charset == null && _version.equals( "2.1" ) ) ||
 
618
                                        ( charset != null && (
 
619
                                                charset.equals( "ASCII" ) ||
 
620
                                                charset.equals( "US-ASCII" ) ) ) )
 
621
                                {
573
622
                                        value = transcodeAsciiToUtf8( value );
574
 
                                        charset = "UTF-8";
575
623
                                }
576
624
 
577
 
                                // process charset
 
625
                                // process charset (value is now in UTF-8)
578
626
                                String string_value;
579
627
                                try {
580
628
                                        string_value = new String( value.array(), value.position(),
581
 
                                                value.limit() - value.position(), charset );
 
629
                                                value.limit() - value.position(), "UTF-8" );
582
630
                                } catch( UnsupportedEncodingException e ) {
583
631
                                        throw new ParseException( R.string.error_vcf_charset );
584
632
                                }
631
679
                                        parseEMAIL( name_param_parts, complete_value );
632
680
                                else if( name_param_parts[ 0 ].equals( "ADR" ) )
633
681
                                        parseADR( name_param_parts, complete_value );
 
682
                                else if( name_param_parts[ 0 ].equals( "LABEL" ) )
 
683
                                        parseLABEL( name_param_parts, complete_value );
 
684
                                else if( name_param_parts[ 0 ].equals( "NOTE" ) )
 
685
                                        parseNOTE( name_param_parts, complete_value );
634
686
                        }
635
687
                }
636
688
 
649
701
                        return ( count & 1 ) == 1;
650
702
                }
651
703
 
652
 
                private String[] splitValueBySemicolon( String value )
 
704
                private String[] splitValueByCharacter( String value, char character )
653
705
                {
654
 
                        // split string in to parts by semicolon
 
706
                        // split string in to parts by specified character
655
707
                        ArrayList< String > parts = new ArrayList< String >(
656
 
                                Arrays.asList( value.split(  ";" ) ) );
 
708
                                Arrays.asList( value.split( "" + character ) ) );
657
709
 
658
710
                        // go through parts
659
711
                        for( int a = 0; a < parts.size(); a++ )
667
719
                                if( a < parts.size() - 1 &&
668
720
                                        doesStringEndInAnEscapeChar( str ) )
669
721
                                {
670
 
                                        // join the next part to this part and remove the next part
 
722
                                        // append the escaped character, join the next part to this
 
723
                                        // part and remove the next part
671
724
                                        parts.set( a, str.substring( 0, str.length() - 1 ) +
672
 
                                                ';' + parts.get( a + 1 ) );
 
725
                                                character + parts.get( a + 1 ) );
673
726
                                        parts.remove( a + 1 );
674
727
 
675
728
                                        // re-visit this part
686
739
                        return parts.toArray( ret );
687
740
                }
688
741
 
 
742
                private String unescapeValue( String value )
 
743
                {
 
744
                        StringBuilder ret = new StringBuilder( value.length() );
 
745
                        boolean in_escape = false;
 
746
                        for( int a = 0; a < value.length(); a++ )
 
747
                        {
 
748
                                int c = value.codePointAt( a );
 
749
 
 
750
                                // process a normal character
 
751
                                if( !in_escape ) {
 
752
                                        if( c == '\\' )
 
753
                                                in_escape = true;
 
754
                                        else
 
755
                                                ret.append( Character.toChars( c ) );
 
756
                                        continue;
 
757
                                }
 
758
 
 
759
                                // process an escape sequence
 
760
                                in_escape = false;
 
761
                                switch( c )
 
762
                                {
 
763
                                case 'T':
 
764
                                case 't':
 
765
                                        // add tab (invalid/non-standard, but accepted)
 
766
                                        ret.append( '\t' );
 
767
                                        break;
 
768
                                case 'N':
 
769
                                case 'n':
 
770
                                        // add newline
 
771
                                        ret.append( '\n' );
 
772
                                        break;
 
773
                                case '\\':
 
774
                                case ',':
 
775
                                case ';':
 
776
                                        // add escaped character
 
777
                                        ret.append( Character.toChars( c ) );
 
778
                                        break;
 
779
                                default:
 
780
                                        // unknown escape sequence, so add it unescaped
 
781
                                        // (invalid/non-standard, but accepted)
 
782
                                        ret.append( "\\" );
 
783
                                        ret.append( Character.toChars( c ) );
 
784
                                        break;
 
785
                                }
 
786
                        }
 
787
 
 
788
                        return ret.toString();
 
789
                }
 
790
 
689
791
                private void parseN( String[] params, String value )
690
792
                {
691
793
                        // already got a better name?
692
794
                        if( _name_level >= NAMELEVEL_N ) return;
693
795
 
694
796
                        // get name parts
695
 
                        String[] name_parts = splitValueBySemicolon( value );
 
797
                        String[] name_parts = splitValueByCharacter( value, ';' );
696
798
 
697
799
                        // build name
698
800
                        value = "";
699
 
                        if( name_parts.length > 1 && name_parts[ 1 ].length() > 0 )
700
 
                                value += name_parts[ 1 ];
701
 
                        if( name_parts.length > 0 && name_parts[ 0 ].length() > 0 )
702
 
                                value += ( value.length() == 0? "" : " " ) + name_parts[ 0 ];
 
801
                        final int[] part_order = { 3, 1, 2, 0, 4 };
 
802
                        for( int a = 0; a < part_order.length; a++ )
 
803
                                if( name_parts.length > part_order[ a ] &&
 
804
                                        name_parts[ part_order[ a ] ].length() > 0 )
 
805
                                {
 
806
                                        // split this part in to it's comma-separated bits
 
807
                                        String[] name_part_parts = splitValueByCharacter(
 
808
                                                name_parts[ part_order[ a ] ], ',' );
 
809
                                        for( int b = 0; b < name_part_parts.length; b++ )
 
810
                                                if( name_part_parts[ b ].length() > 0 )
 
811
                                                {
 
812
                                                        if( value.length() == 0 ) value += " ";
 
813
                                                        value += name_part_parts[ b ];
 
814
                                                }
 
815
                                }
703
816
 
704
817
                        // set name
705
 
                        setName( value );
 
818
                        setName( unescapeValue( value ) );
706
819
                        _name_level = NAMELEVEL_N;
707
820
                }
708
821
 
712
825
                        if( _name_level >= NAMELEVEL_FN ) return;
713
826
 
714
827
                        // set name
715
 
                        setName( value );
 
828
                        setName( unescapeValue( value ) );
716
829
                        _name_level = NAMELEVEL_FN;
717
830
                }
718
831
 
719
832
                private void parseORG( String[] params, String value )
720
833
                {
721
834
                        // get org parts
722
 
                        String[] org_parts = splitValueBySemicolon( value );
 
835
                        String[] org_parts = splitValueByCharacter( value, ';' );
723
836
                        if( org_parts == null || org_parts.length < 1 ) return;
724
837
 
725
838
                        // build organisation name
727
840
                                String.valueOf( org_parts[ 0 ] ) );
728
841
                        for( int a = 1; a < org_parts.length; a++ )
729
842
                                builder.append( ", " ).append( org_parts[ a ] );
730
 
                        String organisation = builder.toString();
 
843
                        String organisation = unescapeValue( builder.toString() );
731
844
 
732
845
                        // set organisation name (using a title we've previously found)
733
846
                        addOrganisation( organisation, _cached_title, true );
744
857
 
745
858
                private void parseTITLE( String[] params, String value )
746
859
                {
 
860
                        value = unescapeValue( value );
 
861
 
747
862
                        // if we previously had an organisation, look it up and append this
748
863
                        // title to it
749
864
                        if( _cached_organisation != null && hasOrganisations() ) {
775
890
                        int type;
776
891
                        if( types.contains( "FAX" ) )
777
892
                                if( types.contains( "HOME" ) )
778
 
                                        type = PhonesColumns.TYPE_FAX_HOME;
 
893
                                        type = TYPE_FAX_HOME;
779
894
                                else
780
 
                                        type = PhonesColumns.TYPE_FAX_WORK;
 
895
                                        type = TYPE_FAX_WORK;
781
896
                        else if( types.contains( "CELL" ) || types.contains( "VIDEO" ) )
782
 
                                type = PhonesColumns.TYPE_MOBILE;
 
897
                                type = TYPE_MOBILE;
783
898
                        else if( types.contains( "PAGER" ) )
784
 
                                type = PhonesColumns.TYPE_PAGER;
 
899
                                type = TYPE_PAGER;
785
900
                        else if( types.contains( "WORK" ) )
786
 
                                type = PhonesColumns.TYPE_WORK;
 
901
                                type = TYPE_WORK;
787
902
                        else
788
 
                                type = PhonesColumns.TYPE_HOME;
 
903
                                type = TYPE_HOME;
789
904
 
790
905
                        // add phone number
791
906
                        addNumber( value, type, is_preferred );
802
917
                        boolean is_preferred = types.contains( "PREF" );
803
918
                        int type;
804
919
                        if( types.contains( "WORK" ) )
805
 
                                type = Contacts.ContactMethods.TYPE_WORK;
 
920
                                type = TYPE_WORK;
806
921
                        else
807
 
                                type = Contacts.ContactMethods.TYPE_HOME;
 
922
                                type = TYPE_HOME;
808
923
 
809
 
                        addEmail( value, type, is_preferred );
 
924
                        addEmail( unescapeValue( value ), type, is_preferred );
810
925
                }
811
926
 
812
927
                private void parseADR( String[] params, String value )
813
928
                {
814
929
                        // get address parts
815
 
                        String[] adr_parts = splitValueBySemicolon( value );
 
930
                        String[] adr_parts = splitValueByCharacter( value, ';' );
816
931
 
817
932
                        // build address
818
933
                        value = "";
819
 
                        for( int a = 0; a < adr_parts.length; a++ ) {
820
 
                                if( value.length() > 0 ) value += "\n";
821
 
                                value += adr_parts[ a ].trim();
822
 
                        }
823
 
 
824
 
                        Set< String > types = extractTypes( params, Arrays.asList(
825
 
                                "PREF", "WORK", "HOME", "INTERNET" ) );
826
 
 
827
 
                        // add address
828
 
                        int type;
829
 
                        if( types.contains( "WORK" ) )
830
 
                                type = Contacts.ContactMethods.TYPE_WORK;
831
 
                        else
832
 
                                type = Contacts.ContactMethods.TYPE_HOME;
833
 
 
834
 
                        addAddress( value, type );
 
934
                        for( int a = 0; a < adr_parts.length; a++ )
 
935
                                if( adr_parts[ a ].length() > 0 )
 
936
                                {
 
937
                                        // split this part in to it's comma-separated bits
 
938
                                        String[] adr_part_parts =
 
939
                                                splitValueByCharacter( adr_parts[ a ], ',' );
 
940
                                        for( int b = 0; b < adr_part_parts.length; b++ )
 
941
                                                if( adr_part_parts[ b ].length() > 0 )
 
942
                                                {
 
943
                                                        if( value.length() > 0 ) value += "\n";
 
944
                                                        value += adr_part_parts[ b ];
 
945
                                                }
 
946
                                }
 
947
 
 
948
                        Set< String > types = extractTypes( params, Arrays.asList(
 
949
                                "PREF", "WORK", "HOME" ) );
 
950
 
 
951
                        // add address
 
952
                        int type;
 
953
                        if( types.contains( "WORK" ) )
 
954
                                type = TYPE_WORK;
 
955
                        else
 
956
                                type = TYPE_HOME;
 
957
 
 
958
                        addAddress( unescapeValue( value ), type );
 
959
                }
 
960
 
 
961
                private void parseLABEL( String[] params, String value )
 
962
                {
 
963
                        Set< String > types = extractTypes( params, Arrays.asList(
 
964
                                "PREF", "WORK", "HOME" ) );
 
965
 
 
966
                        // add address
 
967
                        int type;
 
968
                        if( types.contains( "WORK" ) )
 
969
                                type = TYPE_WORK;
 
970
                        else
 
971
                                type = TYPE_HOME;
 
972
 
 
973
                        addAddress( unescapeValue( value ), type );
 
974
                }
 
975
 
 
976
                private void parseNOTE( String[] params, String value )
 
977
                {
 
978
                        addNote( unescapeValue( value ) );
835
979
                }
836
980
 
837
981
                public void finaliseVcard()
838
 
                        throws ParseException
 
982
                        throws ParseException, ContactNotIdentifiableException
839
983
                {
840
984
                        // missing version (and data is present)
841
985
                        if( _version == null && _buffers != null )
842
986
                                throw new ParseException( R.string.error_vcf_malformed );
843
987
 
844
988
                        // finalise the parent class
845
 
                        try {
846
 
                                finalise();
847
 
                        }
848
 
                        catch( ContactNotIdentifiableException e ) {
849
 
                                throw new ParseException( R.string.error_vcf_notenoughinfo );
850
 
                        }
 
989
                        finalise();
851
990
                }
852
991
 
 
992
                /**
 
993
                 * Amongst the params, find the value of the first, only, of any with
 
994
                 * the specified name
 
995
                 * @param params
 
996
                 * @param name
 
997
                 * @return a value, or null
 
998
                 */
853
999
                private String checkParam( String[] params, String name )
854
1000
                {
 
1001
                        String[] res = checkParams( params, name );
 
1002
                        return res.length > 0? res[ 0 ] : null;
 
1003
                }
 
1004
 
 
1005
                /**
 
1006
                 * Amongst the params, find the values of any with the specified name
 
1007
                 * @param params
 
1008
                 * @param name
 
1009
                 * @return an array of values, or null
 
1010
                 */
 
1011
                private String[] checkParams( String[] params, String name )
 
1012
                {
 
1013
                        HashSet< String > ret = new HashSet< String >();
 
1014
 
855
1015
                        Pattern p = Pattern.compile(
856
1016
                                "^" + name + "[ \\t]*=[ \\t]*(\"?)(.*)\\1$" );
857
1017
                        for( int i = 0; i < params.length; i++ ) {
858
1018
                                Matcher m = p.matcher( params[ i ] );
859
1019
                                if( m.matches() )
860
 
                                        return m.group( 2 );
 
1020
                                        ret.add( m.group( 2 ) );
861
1021
                        }
862
 
                        return null;
 
1022
 
 
1023
                        return (String[]) ret.toArray( new String[ ret.size() ] );
863
1024
                }
864
1025
 
 
1026
                /**
 
1027
                 * Amongst the params, return any type values present. For v2.1 vCards,
 
1028
                 * those types are just parameters. For v3.0, they are prefixed with
 
1029
                 * "TYPE=". There may also be multiple type parameters.
 
1030
                 * @param params
 
1031
                 * @param a list of type values to look for
 
1032
                 * @return a set of present type values
 
1033
                 */
865
1034
                private Set< String > extractTypes( String[] params,
866
1035
                        List< String > valid_types )
867
1036
                {
868
1037
                        HashSet< String > types = new HashSet< String >();
869
1038
 
870
1039
                        // get 3.0-style TYPE= param
871
 
                        String type_param;
872
 
                        if( ( type_param = checkParam( params, "TYPE" ) ) != null ) {
873
 
                                String[] parts = type_param.split( "," );
 
1040
                        String type_params[] = checkParams( params, "TYPE" );
 
1041
                        for( int a = 0; a < type_params.length; a++ )
 
1042
                        {
 
1043
                                // check for a comma-separated list of types (why? this isn't in
 
1044
                                // the specs!)
 
1045
                                String[] parts = type_params[ a ].split( "," );
874
1046
                                for( int i = 0; i < parts.length; i++ )
875
1047
                                        if( valid_types.contains( parts[ i ] ) )
876
1048
                                                types.add( parts[ i ] );