/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: 2014-03-02 10:58:35 UTC
  • Revision ID: tim@ed.am-20140302105835-szgzmrvr7pa5kljw
updated NEWS

Show diffs side-by-side

added added

removed removed

90
90
                                // get files
91
91
                                class VCardFilter implements FilenameFilter {
92
92
                                        public boolean accept( File dir, String name ) {
93
 
                                                return name.toLowerCase( Locale.ENGLISH )
94
 
                                                        .endsWith( ".vcf" );
 
93
                                                return name.toLowerCase( Locale.US ).endsWith( ".vcf" );
95
94
                                        }
96
95
                                }
97
96
                                files = file.listFiles( new VCardFilter() );
236
235
                                                importContact( vcard );
237
236
                                        }
238
237
                                        catch( Vcard.ParseException e ) {
239
 
                                                showContinueOrAbort(
 
238
                                                if( !showContinue(
240
239
                                                        getText( R.string.error_vcf_parse ).toString()
241
240
                                                        + fileName +
242
241
                                                        getText( R.string.error_vcf_parse_line ).toString()
243
 
                                                        + cli.getLineNumber() + ":\n" + e.getMessage() );
244
 
                                                skipContact();
 
242
                                                        + cli.getLineNumber() + ":\n" + e.getMessage() ) )
 
243
                                                {
 
244
                                                        finish( ACTION_ABORT );
 
245
                                                }
 
246
                                                else
 
247
                                                        skipContact();
245
248
                                        }
246
249
                                        catch( ContactData.ContactNotIdentifiableException e ) {
247
 
                                                showContinueOrAbort(
 
250
                                                if( !showContinue(
248
251
                                                        getText( R.string.error_vcf_parse ).toString()
249
252
                                                        + fileName +
250
253
                                                        getText( R.string.error_vcf_parse_line ).toString()
251
254
                                                        + vcard_start_line + ":\n" + getText(
252
 
                                                                R.string.error_vcf_notenoughinfo ).toString() );
253
 
                                                skipContact();
254
 
                                        }
255
 
                                        catch( Vcard.SkipImportException e ) {
256
 
                                                skipContact();
 
255
                                                                R.string.error_vcf_notenoughinfo ).toString()
 
256
                                                ) )
 
257
                                                {
 
258
                                                        finish( ACTION_ABORT );
 
259
                                                }
 
260
                                                else
 
261
                                                        skipContact();
257
262
                                        }
258
263
 
259
264
                                        // discard this vcard
267
272
                                        }
268
273
                                        catch( Vcard.ParseException e ) {
269
274
                                                skipContact();
270
 
                                                showContinueOrAbort(
 
275
                                                if( !showContinue(
271
276
                                                        getText( R.string.error_vcf_parse ).toString()
272
277
                                                        + fileName +
273
278
                                                        getText( R.string.error_vcf_parse_line ).toString()
274
 
                                                        + cli.getLineNumber() + "\n" + e.getMessage() );
 
279
                                                        + cli.getLineNumber() + "\n" + e.getMessage() ) )
 
280
                                                {
 
281
                                                        finish( ACTION_ABORT );
 
282
                                                }
275
283
 
276
284
                                                // Although we're continuing, we still need to abort
277
285
                                                // this vCard.  Further lines will be ignored until we
608
616
                                ) );
609
617
                                boolean is_interesting_field =
610
618
                                        interesting_fields.contains(
611
 
                                                name_param_parts[ 0 ].toUpperCase( Locale.ENGLISH ) );
 
619
                                                name_param_parts[ 0 ].toUpperCase( Locale.US ) );
612
620
 
613
621
                                // parse encoding parameter
614
622
                                String encoding = checkParam( name_param_parts, "ENCODING" );
615
623
                                if( encoding != null )
616
 
                                        encoding = encoding.toUpperCase( Locale.ENGLISH );
 
624
                                        encoding = encoding.toUpperCase( Locale.US );
617
625
                                if( is_interesting_field && encoding != null &&
618
626
                                        !encoding.equalsIgnoreCase( "8BIT" ) &&
619
627
                                        !encoding.equalsIgnoreCase( "QUOTED-PRINTABLE" ) )
625
633
                                // parse charset parameter
626
634
                                String charset = checkParam( name_param_parts, "CHARSET" );
627
635
                                if( charset != null )
628
 
                                        charset = charset.toUpperCase( Locale.ENGLISH );
 
636
                                        charset = charset.toUpperCase( Locale.US );
629
637
                                if( charset != null &&
630
638
                                        !charset.equalsIgnoreCase( "US-ASCII" ) &&
631
639
                                        !charset.equalsIgnoreCase( "ASCII" ) &&
1038
1046
                }
1039
1047
 
1040
1048
                public void finaliseVcard()
1041
 
                        throws ParseException, ContactNotIdentifiableException,
1042
 
                                SkipImportException, AbortImportException
 
1049
                        throws ParseException, ContactNotIdentifiableException
1043
1050
                {
1044
 
                        // if there was content present, but no version line, then it must
1045
 
                        // be a version 2.1 vCard; process that content now
1046
 
                        if( _version == null && _content_lines != null ) {
1047
 
                                _version = "2.1";
1048
 
                                for( int i = 0; i < _content_lines.size(); i++ )
1049
 
                                        parseLine( _content_lines.get( i ) );
1050
 
                                _content_lines = null;
1051
 
                        }
 
1051
                        // missing version (and data is present)
 
1052
                        if( _version == null && _content_lines != null )
 
1053
                                throw new ParseException( R.string.error_vcf_malformed );
1052
1054
 
1053
1055
                        // finalise the parent class
1054
1056
                        finalise();
1113
1115
                                // this is in the specs!)
1114
1116
                                String[] parts = type_params[ a ].split( "," );
1115
1117
                                for( int i = 0; i < parts.length; i++ ) {
1116
 
                                        String ucpart = parts[ i ].toUpperCase( Locale.ENGLISH );
 
1118
                                        String ucpart = parts[ i ].toUpperCase( Locale.US );
1117
1119
                                        if( valid_types.contains( ucpart ) )
1118
1120
                                                types.add( ucpart );
1119
1121
                                }
1122
1124
                        // get 2.1-style type param
1123
1125
                        if( _version.equals( "2.1" ) ) {
1124
1126
                                for( int i = 1; i < params.length; i++ ) {
1125
 
                                        String ucparam = params[ i ].toUpperCase( Locale.ENGLISH );
 
1127
                                        String ucparam = params[ i ].toUpperCase( Locale.US );
1126
1128
                                        if( valid_types.contains( ucparam ) )
1127
1129
                                                types.add( ucparam );
1128
1130
                                }