/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-05-10 12:16:15 UTC
  • Revision ID: tim@ed.am-20130510121615-g8qhsu0h3t0ymrt6
Tags: 1.3.2
fix spacing in NEWS

Show diffs side-by-side

added added

removed removed

1
1
/*
2
2
 * VCFImporter.java
3
3
 *
4
 
 * Copyright (C) 2009 to 2013 Tim Marston <tim@ed.am>
 
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
273
273
                                                        finish( ACTION_ABORT );
274
274
                                                }
275
275
 
276
 
                                                // Although we're continuing, we still need to abort
277
 
                                                // 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
278
278
                                                // get to another BEGIN:VCARD line.
279
279
                                                vcard = null;
280
280
                                        }
281
281
                                        catch( Vcard.SkipImportException e ) {
282
282
                                                skipContact();
283
 
                                                // Abort this vCard.  Further lines will be ignored until
 
283
                                                // abort this vCard. Further lines will be ignored until
284
284
                                                // we get to another BEGIN:VCARD line.
285
285
                                                vcard = null;
286
286
                                        }
471
471
                private String extractCollonPartFromLine( ContentLine content_line,
472
472
                        boolean former )
473
473
                {
 
474
                        String ret = null;
 
475
 
474
476
                        // split line into name and value parts and check to make sure we
475
477
                        // only got 2 parts and that the first part is not zero in length
476
478
                        String[] parts = content_line.getUsAsciiLine().split( ":", 2 );
477
479
                        if( parts.length == 2 && parts[ 0 ].length() > 0 )
478
 
                                return parts[ former? 0 : 1 ].trim();
 
480
                                ret = parts[ former? 0 : 1 ];
479
481
 
480
 
                        return null;
 
482
                        return ret;
481
483
                }
482
484
 
483
485
                private String extractNameAndParamsFromLine( ContentLine content_line )
484
486
                {
485
 
                        return extractCollonPartFromLine( content_line, true );
 
487
                        return extractCollonPartFromLine( content_line, true ).trim();
486
488
                }
487
489
 
488
490
                private String extractValueFromLine( ContentLine content_line )
506
508
                                        name_and_params.equalsIgnoreCase( "VERSION" ) )
507
509
                                {
508
510
                                        // yes, get it!
509
 
                                        String value = extractValueFromLine( content_line );
510
 
                                        if( value == null || (
511
 
                                                !value.equals( "2.1" ) && !value.equals( "3.0" ) ) )
512
 
                                        {
 
511
                                        String value = extractValueFromLine( content_line ).trim();
 
512
                                        if( !value.equals( "2.1" ) && !value.equals( "3.0" ) )
513
513
                                                throw new ParseException( R.string.error_vcf_version );
514
 
                                        }
515
514
                                        _version = value;
516
515
 
517
516
                                        // parse any buffers we've been accumulating while we waited
724
723
                                        parseLABEL( name_param_parts, complete_value );
725
724
                                else if( name_param_parts[ 0 ].equalsIgnoreCase( "NOTE" ) )
726
725
                                        parseNOTE( name_param_parts, complete_value );
727
 
                                else if( name_param_parts[ 0 ].equalsIgnoreCase( "BDAY" ) )
728
 
                                        parseBDAY( name_param_parts, complete_value );
729
726
                        }
730
727
                }
731
728
 
755
752
                        {
756
753
                                String str = parts.get( a );
757
754
 
758
 
                                // Look for parts that end in an escape character, but ignore
759
 
                                // 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
760
757
                                // end of the final part in parseLine() and handled multi-lines
761
758
                                // accordingly.
762
759
                                if( a < parts.size() - 1 &&
1032
1029
                        addNote( unescapeValue( value ) );
1033
1030
                }
1034
1031
 
1035
 
                private void parseBDAY( String[] params, String value )
1036
 
                {
1037
 
                        setBirthday( value );
1038
 
                }
1039
 
 
1040
1032
                public void finaliseVcard()
1041
1033
                        throws ParseException, ContactNotIdentifiableException
1042
1034
                {
1050
1042
 
1051
1043
                /**
1052
1044
                 * Amongst the params, find the value of the first, only, of any with
1053
 
                 * the specified name.
1054
 
                 *
 
1045
                 * the specified name
1055
1046
                 * @param params
1056
1047
                 * @param name
1057
1048
                 * @return a value, or null
1063
1054
                }
1064
1055
 
1065
1056
                /**
1066
 
                 * Amongst the params, find the values of any with the specified name.
1067
 
                 *
 
1057
                 * Amongst the params, find the values of any with the specified name
1068
1058
                 * @param params
1069
1059
                 * @param name
1070
1060
                 * @return an array of values, or null
1086
1076
                }
1087
1077
 
1088
1078
                /**
1089
 
                 * Amongst the params, return any type values present.  For v2.1 vCards,
1090
 
                 * those types are just parameters.  For v3.0, they are prefixed with
1091
 
                 * "TYPE=".  There may also be multiple type parameters.
1092
 
                 *
 
1079
                 * Amongst the params, return any type values present. For v2.1 vCards,
 
1080
                 * those types are just parameters. For v3.0, they are prefixed with
 
1081
                 * "TYPE=". There may also be multiple type parameters.
1093
1082
                 * @param params an array of params to look for types in
1094
1083
                 * @param valid_types an list of upper-case type values to look for
1095
1084
                 * @return a set of present type values
1147
1136
                                else if( ch == '=' && i == in.limit() - 1 )
1148
1137
                                {
1149
1138
                                        // we found a '=' at the end of a line signifying a multi-
1150
 
                                        // line string, so we don't add it
 
1139
                                        // line string, so we don't add it.
1151
1140
                                        another = true;
1152
1141
                                        continue;
1153
1142
                                }