/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-09-16 20:15:38 UTC
  • Revision ID: tim@ed.am-20130916201538-w2s54x86ml6kvjft
prevent NPE

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 <tim@ed.am>
 
4
 * Copyright (C) 2009 to 2013 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
471
471
                private String extractCollonPartFromLine( ContentLine content_line,
472
472
                        boolean former )
473
473
                {
474
 
                        String ret = null;
475
 
 
476
474
                        // split line into name and value parts and check to make sure we
477
475
                        // only got 2 parts and that the first part is not zero in length
478
476
                        String[] parts = content_line.getUsAsciiLine().split( ":", 2 );
479
477
                        if( parts.length == 2 && parts[ 0 ].length() > 0 )
480
 
                                ret = parts[ former? 0 : 1 ];
 
478
                                return parts[ former? 0 : 1 ].trim();
481
479
 
482
 
                        return ret;
 
480
                        return null;
483
481
                }
484
482
 
485
483
                private String extractNameAndParamsFromLine( ContentLine content_line )
486
484
                {
487
 
                        return extractCollonPartFromLine( content_line, true ).trim();
 
485
                        return extractCollonPartFromLine( content_line, true );
488
486
                }
489
487
 
490
488
                private String extractValueFromLine( ContentLine content_line )
508
506
                                        name_and_params.equalsIgnoreCase( "VERSION" ) )
509
507
                                {
510
508
                                        // yes, get it!
511
 
                                        String value = extractValueFromLine( content_line ).trim();
512
 
                                        if( !value.equals( "2.1" ) && !value.equals( "3.0" ) )
 
509
                                        String value = extractValueFromLine( content_line );
 
510
                                        if( value == null || (
 
511
                                                !value.equals( "2.1" ) && !value.equals( "3.0" ) ) )
 
512
                                        {
513
513
                                                throw new ParseException( R.string.error_vcf_version );
 
514
                                        }
514
515
                                        _version = value;
515
516
 
516
517
                                        // parse any buffers we've been accumulating while we waited
723
724
                                        parseLABEL( name_param_parts, complete_value );
724
725
                                else if( name_param_parts[ 0 ].equalsIgnoreCase( "NOTE" ) )
725
726
                                        parseNOTE( name_param_parts, complete_value );
 
727
                                else if( name_param_parts[ 0 ].equalsIgnoreCase( "BDAY" ) )
 
728
                                        parseBDAY( name_param_parts, complete_value );
726
729
                        }
727
730
                }
728
731
 
1029
1032
                        addNote( unescapeValue( value ) );
1030
1033
                }
1031
1034
 
 
1035
                private void parseBDAY( String[] params, String value )
 
1036
                {
 
1037
                        setBirthday( value );
 
1038
                }
 
1039
 
1032
1040
                public void finaliseVcard()
1033
1041
                        throws ParseException, ContactNotIdentifiableException
1034
1042
                {