/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/org/waxworlds/edam/importcontacts/VcardImporter.java

  • Committer: edam
  • Date: 2011-05-30 15:33:01 UTC
  • Revision ID: edam@waxworlds.org-20110530153301-oor6ci9b3hf9clul
- refactored some code to do with how contacts are imported
- Vcards (and ContactData) instances now generate a CacheIdentifier when they are finalised so that ContactData instances that do not have enough information to identify them can be discovered then
- importContact() now calls the private method checkForDuplicate(), renamed from isImportRequired(), and return if it is not
- importContact() and checkForDuplicate() now use the ContactData's generated CacheIdentifier

Show diffs side-by-side

added added

removed removed

213
213
                                // look for vcard content or ending
214
214
                                if( line.matches( "^END:VCARD" ) )
215
215
                                {
216
 
                                        // store vcard and do away with it
 
216
                                        // finalise the vcard/contact
217
217
                                        try {
218
 
                                                vcard.finaliseParsing();
219
 
                                                importContact( vcard );
 
218
                                                vcard.finaliseVcard();
220
219
                                        }
221
220
                                        catch( Vcard.ParseException e ) {
222
221
                                                skipContact();
227
226
                                                        finish( ACTION_ABORT );
228
227
                                                }
229
228
                                        }
230
 
                                        catch( Vcard.SkipContactException e ) {
231
 
                                                skipContact();
232
 
                                                // do nothing
233
 
                                        }
 
229
 
 
230
                                        // pass the finalised contact to the importer
 
231
                                        importContact( vcard );
 
232
 
 
233
                                        // and discard it
234
234
                                        vcard = null;
235
235
                                }
236
236
                                else
254
254
                                                // get to another BEGIN:VCARD line.
255
255
                                                vcard = null;
256
256
                                        }
257
 
                                        catch( Vcard.SkipContactException e ) {
 
257
                                        catch( Vcard.SkipImportException e ) {
258
258
                                                skipContact();
259
259
                                                // abort this vCard. Further lines will be ignored until
260
260
                                                // we get to another BEGIN:VCARD line.
387
387
                }
388
388
 
389
389
                @SuppressWarnings("serial")
390
 
                protected class SkipContactException extends Exception { }
 
390
                protected class SkipImportException extends Exception { }
391
391
 
392
392
                private String extractCollonPartFromLine( ByteBuffer buffer,
393
393
                        String line, boolean former )
429
429
 
430
430
                public void parseLine( ByteBuffer buffer, String line,
431
431
                        boolean next_line_looks_folded )
432
 
                        throws ParseException, SkipContactException,
 
432
                        throws ParseException, SkipImportException,
433
433
                        AbortImportException
434
434
                {
435
435
                        // do we have a version yet?
834
834
                        addAddress( value, type );
835
835
                }
836
836
 
837
 
                public void finaliseParsing()
838
 
                        throws ParseException, SkipContactException,
839
 
                        AbortImportException
 
837
                public void finaliseVcard()
 
838
                        throws ParseException
840
839
                {
841
840
                        // missing version (and data is present)
842
841
                        if( _version == null && _buffers != null )
843
842
                                throw new ParseException( R.string.error_vcf_malformed );
844
843
 
845
 
                        // check if we should import this contact
 
844
                        // finalise the parent class
846
845
                        try {
847
 
                                if( !isImportRequired( this ) )
848
 
                                        throw new SkipContactException();
 
846
                                finalise();
849
847
                        }
850
 
                        catch( ContactNeedsMoreInfoException e ) {
 
848
                        catch( ContactNotIdentifiableException e ) {
851
849
                                throw new ParseException( R.string.error_vcf_notenoughinfo );
852
850
                        }
853
851
                }