238
237
// try giving the line to the vcard
240
vcard.parseLine( buffer, line,
239
vCard.parseLine( buffer, line,
241
240
cli.doesNextLineLookFolded() );
243
242
catch( VCard.ParseException e ) {
252
251
// although we're continuing, we still need to abort
253
252
// this vCard. Further lines will be ignored until we
254
253
// get to another BEGIN:VCARD line.
257
256
catch( VCard.SkipContactException e ) {
259
258
// abort this vCard. Further lines will be ignored until
260
259
// we get to another BEGIN:VCARD line.
331
330
private class VCard extends ContactData
333
332
private final static int NAMELEVEL_NONE = 0;
334
private final static int NAMELEVEL_FN = 1;
335
private final static int NAMELEVEL_N = 2;
333
private final static int NAMELEVEL_ORG = 1;
334
private final static int NAMELEVEL_FN = 2;
335
private final static int NAMELEVEL_N = 3;
337
337
private final static int MULTILINE_NONE = 0;
338
338
private final static int MULTILINE_ENCODED = 1; // v2.1 quoted-printable
345
345
private int _parser_multiline_state = MULTILINE_NONE;
346
346
private String _parser_current_name_and_params = null;
347
347
private String _parser_buffered_value_so_far = "";
348
private String _cached_organisation = null;
349
private String _cached_title = null;
351
349
protected class UnencodeResult
623
621
parseFN( name_param_parts, complete_value );
624
622
else if( name_param_parts[ 0 ].equals( "ORG" ) )
625
623
parseORG( name_param_parts, complete_value );
626
else if( name_param_parts[ 0 ].equals( "TITLE" ) )
627
parseTITLE( name_param_parts, complete_value );
628
624
else if( name_param_parts[ 0 ].equals( "TEL" ) )
629
625
parseTEL( name_param_parts, complete_value );
630
626
else if( name_param_parts[ 0 ].equals( "EMAIL" ) )
705
703
setName( value );
706
704
_name_level = NAMELEVEL_N;
706
// check now to see if we need to import this contact (to avoid
707
// parsing the rest of the vCard unnecessarily)
708
if( !isImportRequired( getName() ) )
709
throw new SkipContactException();
709
712
private void parseFN( String[] params, String value )
713
throws ParseException, SkipContactException
711
715
// already got a better name?
712
716
if( _name_level >= NAMELEVEL_FN ) return;
719
723
private void parseORG( String[] params, String value )
724
throws ParseException, SkipContactException
726
// already got a better name?
727
if( _name_level >= NAMELEVEL_ORG ) return;
722
730
String[] org_parts = splitValueBySemicolon( value );
723
if( org_parts == null || org_parts.length < 1 ) return;
725
// build organisation name
726
StringBuilder builder = new StringBuilder(
727
String.valueOf( org_parts[ 0 ] ) );
728
for( int a = 1; a < org_parts.length; a++ )
729
builder.append( ", " ).append( org_parts[ a ] );
730
String organisation = builder.toString();
732
// set organisation name (using a title we've previously found)
733
addOrganisation( organisation, _cached_title, true );
735
// if we've not previously found a title, store this organisation
736
// name (we'll need it when we find a title to update the
737
// organisation, by name), else if we *have* previously found a
738
// title, clear it (since we just used it)
739
if( _cached_title == null )
740
_cached_organisation = organisation;
742
_cached_title = null;
745
private void parseTITLE( String[] params, String value )
747
// if we previously had an organisation, look it up and append this
749
if( _cached_organisation != null && hasOrganisations() ) {
750
HashMap< String, ExtraDetail > datas = getOrganisations();
751
ExtraDetail detail = datas.get( _cached_organisation );
753
detail.setExtra( value );
756
// same as when handling organisation, if we've not previously found
757
// an organisation we store this title, else we clear it (since we
758
// just appended this title to it)
759
if( _cached_organisation == null )
760
_cached_title = value;
762
_cached_organisation = null;
733
if( org_parts.length > 1 && org_parts[ 0 ].length() == 0 )
734
value = org_parts[ 1 ];
735
else if( org_parts.length > 1 && org_parts[ 1 ].length() > 0 )
736
value = org_parts[ 0 ] + ", " + org_parts[ 1 ];
738
value = org_parts[ 0 ];
742
_name_level = NAMELEVEL_ORG;
765
745
private void parseTEL( String[] params, String value )
746
throws ParseException
767
748
if( value.length() == 0 ) return;
771
752
"PAGER", "BBS", "MODEM", "CAR", "ISDN", "VIDEO" ) );
773
754
// here's the logic...
774
boolean is_preferred = types.contains( "PREF" );
755
boolean preferred = types.contains( "PREF" );
756
int type = PhonesColumns.TYPE_MOBILE;
757
if( types.contains( "VOICE" ) )
758
if( types.contains( "WORK" ) )
759
type = PhonesColumns.TYPE_WORK;
761
type = PhonesColumns.TYPE_HOME;
762
else if( types.contains( "CELL" ) || types.contains( "VIDEO" ) )
763
type = PhonesColumns.TYPE_MOBILE;
776
764
if( types.contains( "FAX" ) )
777
765
if( types.contains( "HOME" ) )
778
766
type = PhonesColumns.TYPE_FAX_HOME;
780
768
type = PhonesColumns.TYPE_FAX_WORK;
781
else if( types.contains( "CELL" ) || types.contains( "VIDEO" ) )
782
type = PhonesColumns.TYPE_MOBILE;
783
else if( types.contains( "PAGER" ) )
769
if( types.contains( "PAGER" ) )
784
770
type = PhonesColumns.TYPE_PAGER;
785
else if( types.contains( "WORK" ) )
786
type = PhonesColumns.TYPE_WORK;
788
type = PhonesColumns.TYPE_HOME;
790
772
// add phone number
791
addNumber( value, type, is_preferred );
773
addPhone( value, type, preferred );
794
776
public void parseEMAIL( String[] params, String value )
777
throws ParseException
796
779
if( value.length() == 0 ) return;
799
782
"PREF", "WORK", "HOME", "INTERNET" ) );
801
784
// add email address
802
boolean is_preferred = types.contains( "PREF" );
785
boolean preferred = types.contains( "PREF" );
804
786
if( types.contains( "WORK" ) )
805
type = Contacts.ContactMethods.TYPE_WORK;
787
addEmail( value, Contacts.ContactMethods.TYPE_WORK, preferred );
807
type = Contacts.ContactMethods.TYPE_HOME;
809
addEmail( value, type, is_preferred );
789
addEmail( value, Contacts.ContactMethods.TYPE_HOME, preferred );
812
792
private void parseADR( String[] params, String value )
793
throws ParseException, SkipContactException
814
795
// get address parts
815
796
String[] adr_parts = splitValueBySemicolon( value );
825
806
"PREF", "WORK", "HOME", "INTERNET" ) );
829
809
if( types.contains( "WORK" ) )
830
type = Contacts.ContactMethods.TYPE_WORK;
810
addAddress( value, Contacts.ContactMethods.TYPE_WORK );
832
type = Contacts.ContactMethods.TYPE_HOME;
834
addAddress( value, type );
812
addAddress( value, Contacts.ContactMethods.TYPE_HOME);
837
815
public void finaliseParsing()
842
820
if( _version == null && _buffers != null )
843
821
throw new ParseException( R.string.error_vcf_malformed );
845
// check if we should import this contact
847
if( !isImportRequired( this ) )
848
throw new SkipContactException();
850
catch( ContactNeedsMoreInfoException e ) {
851
throw new ParseException( R.string.error_vcf_notenoughinfo );
823
// missing name properties?
824
if( _name_level == NAMELEVEL_NONE )
825
throw new ParseException( R.string.error_vcf_noname );
827
// check if we should import this one? If we've already got an 'N'-
828
// type name, this will already have been done by parseN() so we
829
// mustn't do this here (or it could prompt twice!)
830
if( _name_level < NAMELEVEL_N && !isImportRequired( getName() ) )
831
throw new SkipContactException();
855
834
private String checkParam( String[] params, String name )