/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: Tim Marston
  • Date: 2013-06-22 17:29:31 UTC
  • Revision ID: tim@ed.am-20130622172931-ujydoni23t3a543b
minor style tweaks

Show diffs side-by-side

added added

removed removed

4
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
 
 * to as "this program"). For more information, see
 
7
 * to as "this program").  For more information, see
8
8
 * http://ed.am/dev/android/import-contacts
9
9
 *
10
10
 * This program is free software: you can redistribute it and/or modify
133
133
                        boolean in_vcard = false;
134
134
                        while( ( line = reader.readLine() ) != null )
135
135
                        {
136
 
                                if( !in_vcard ) {
 
136
                                if( !in_vcard )
 
137
                                {
137
138
                                        // look for vcard beginning
138
 
                                        if( line.matches( "^BEGIN:VCARD" ) ) {
 
139
                                        if( line.matches( "(?i)BEGIN[ \t]*:[ \t]*VCARD.*" ) ) {
139
140
                                                in_vcard = true;
140
141
                                                _vcard_count++;
141
142
                                        }
 
143
                                        // check for vMsg files
 
144
                                        else if( line.matches( "(?i)BEGIN[ \t]*:[ \t]*VMSG.*" ) ) {
 
145
                                                showError( getText( R.string.error_vcf_vmsgfile )
 
146
                                                        + file.getName() );
 
147
                                        }
142
148
                                }
143
 
                                else if( line.matches( "^END:VCARD" ) )
 
149
                                else if( line.matches( "(?i)END[ \t]*:[ \t]*VCARD.*" ) )
144
150
                                        in_vcard = false;
145
151
                        }
146
152
 
203
209
 
204
210
                        if( vcard == null ) {
205
211
                                // look for vcard beginning
206
 
                                if( line.matches( "^BEGIN[ \t]*:[ \t]*VCARD" ) ) {
 
212
                                if( line.matches( "(?i)BEGIN[ \t]*:[ \t]*VCARD.*" ) ) {
207
213
                                        setProgress( _progress++ );
208
214
                                        vcard = new Vcard();
209
215
                                        vcard_start_line = cli.getLineNumber();
211
217
                        }
212
218
                        else {
213
219
                                // look for vcard content or ending
214
 
                                if( line.matches( "^END[ \t]*:[ \t]*VCARD" ) )
 
220
                                if( line.matches( "(?i)END[ \t]*:[ \t]*VCARD.*" ) )
215
221
                                {
216
222
                                        // finalise the vcard/contact
217
223
                                        try {
267
273
                                                        finish( ACTION_ABORT );
268
274
                                                }
269
275
 
270
 
                                                // although we're continuing, we still need to abort
271
 
                                                // this vCard. Further lines will be ignored until we
 
276
                                                // Although we're continuing, we still need to abort
 
277
                                                // this vCard.  Further lines will be ignored until we
272
278
                                                // get to another BEGIN:VCARD line.
273
279
                                                vcard = null;
274
280
                                        }
275
281
                                        catch( Vcard.SkipImportException e ) {
276
282
                                                skipContact();
277
 
                                                // abort this vCard. Further lines will be ignored until
 
283
                                                // Abort this vCard.  Further lines will be ignored until
278
284
                                                // we get to another BEGIN:VCARD line.
279
285
                                                vcard = null;
280
286
                                        }
478
484
 
479
485
                private String extractNameAndParamsFromLine( ContentLine content_line )
480
486
                {
481
 
                        return extractCollonPartFromLine( content_line, true );
 
487
                        return extractCollonPartFromLine( content_line, true ).trim();
482
488
                }
483
489
 
484
490
                private String extractValueFromLine( ContentLine content_line )
502
508
                                        name_and_params.equalsIgnoreCase( "VERSION" ) )
503
509
                                {
504
510
                                        // yes, get it!
505
 
                                        String value = extractValueFromLine( content_line );
 
511
                                        String value = extractValueFromLine( content_line ).trim();
506
512
                                        if( !value.equals( "2.1" ) && !value.equals( "3.0" ) )
507
513
                                                throw new ParseException( R.string.error_vcf_version );
508
514
                                        _version = value;
746
752
                        {
747
753
                                String str = parts.get( a );
748
754
 
749
 
                                // look for parts that end in an escape character, but ignore
750
 
                                // the final part. We've already detected escape chars at the
 
755
                                // Look for parts that end in an escape character, but ignore
 
756
                                // the final part.  We've already detected escape chars at the
751
757
                                // end of the final part in parseLine() and handled multi-lines
752
758
                                // accordingly.
753
759
                                if( a < parts.size() - 1 &&
1036
1042
 
1037
1043
                /**
1038
1044
                 * Amongst the params, find the value of the first, only, of any with
1039
 
                 * the specified name
 
1045
                 * the specified name.
 
1046
                 *
1040
1047
                 * @param params
1041
1048
                 * @param name
1042
1049
                 * @return a value, or null
1048
1055
                }
1049
1056
 
1050
1057
                /**
1051
 
                 * Amongst the params, find the values of any with the specified name
 
1058
                 * Amongst the params, find the values of any with the specified name.
 
1059
                 *
1052
1060
                 * @param params
1053
1061
                 * @param name
1054
1062
                 * @return an array of values, or null
1070
1078
                }
1071
1079
 
1072
1080
                /**
1073
 
                 * Amongst the params, return any type values present. For v2.1 vCards,
1074
 
                 * those types are just parameters. For v3.0, they are prefixed with
1075
 
                 * "TYPE=". There may also be multiple type parameters.
 
1081
                 * Amongst the params, return any type values present.  For v2.1 vCards,
 
1082
                 * those types are just parameters.  For v3.0, they are prefixed with
 
1083
                 * "TYPE=".  There may also be multiple type parameters.
 
1084
                 *
1076
1085
                 * @param params an array of params to look for types in
1077
1086
                 * @param valid_types an list of upper-case type values to look for
1078
1087
                 * @return a set of present type values
1130
1139
                                else if( ch == '=' && i == in.limit() - 1 )
1131
1140
                                {
1132
1141
                                        // we found a '=' at the end of a line signifying a multi-
1133
 
                                        // line string, so we don't add it.
 
1142
                                        // line string, so we don't add it
1134
1143
                                        another = true;
1135
1144
                                        continue;
1136
1145
                                }