/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/VCFImporter.java

  • Committer: edam
  • Date: 2010-07-13 19:13:38 UTC
  • Revision ID: edam@waxworlds.org-20100713191338-e23wre83uellvtt4
Tags: 1.0
- updated NEWS, TODO and manifest

Show diffs side-by-side

added added

removed removed

1
 
package org.waxworlds.importcontacts;
 
1
/*
 
2
 * VCFImporter.java
 
3
 *
 
4
 * Copyright (C) 2009 Tim Marston <edam@waxworlds.org>
 
5
 *
 
6
 * This file is part of the Import Contacts program (hereafter referred
 
7
 * to as "this program"). For more information, see
 
8
 * http://www.waxworlds.org/edam/software/android/import-contacts
 
9
 *
 
10
 * This program is free software: you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation, either version 3 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
 */
 
23
 
 
24
package org.waxworlds.edam.importcontacts;
2
25
 
3
26
import java.io.BufferedReader;
4
27
import java.io.File;
15
38
import java.util.regex.Matcher;
16
39
import java.util.regex.Pattern;
17
40
 
18
 
import org.waxworlds.importcontacts.Importer.AbortImportException;
19
 
 
20
41
import android.content.SharedPreferences;
21
42
import android.provider.Contacts;
22
43
import android.provider.Contacts.PhonesColumns;
46
67
                        // open directory
47
68
                        String location = prefs.getString( "location", "" );
48
69
                        File dir = new File( location );
49
 
                        if( !dir.exists() || !dir.isDirectory() )
 
70
                        if( !dir.exists() )
50
71
                                showError( R.string.error_locationnotfound );
51
72
 
52
 
                        // get files
53
 
                        class VCardFilter implements FilenameFilter {
54
 
                            public boolean accept( File dir, String name ) {
55
 
                                return name.toLowerCase().endsWith( ".vcf" );
56
 
                            }
57
 
                        }
58
 
                        files = dir.listFiles( new VCardFilter() );
 
73
                        // directory, or file?
 
74
                        if( dir.isDirectory() )
 
75
                        {
 
76
                                // get files
 
77
                                class VCardFilter implements FilenameFilter {
 
78
                                        public boolean accept( File dir, String name ) {
 
79
                                                return name.toLowerCase().endsWith( ".vcf" );
 
80
                                        }
 
81
                                }
 
82
                                files = dir.listFiles( new VCardFilter() );
 
83
                        }
 
84
                        else
 
85
                        {
 
86
                                // use just this file
 
87
                                files = new File[ 1 ];
 
88
                                files[ 0 ] = dir;
 
89
                        }
59
90
                }
60
91
                catch( SecurityException e ) {
61
92
                        showError( R.string.error_locationpermissions );
223
254
                private Vector< String > _lines = null;
224
255
                private int _nameLevel = NAMELEVEL_NONE;
225
256
 
 
257
                @SuppressWarnings("serial")
226
258
                protected class ParseException extends Exception
227
259
                {
 
260
                        @SuppressWarnings("unused")
228
261
                        public ParseException( String error )
229
262
                        {
230
263
                                super( error );
236
269
                        }
237
270
                }
238
271
 
 
272
                @SuppressWarnings("serial")
239
273
                protected class SkipContactException extends Exception { }
240
274
 
241
275
                public void parseLine( String line )
427
461
                                        !charset.equals( "UTF-8" ) && !charset.equals( "UTF-16" ) )
428
462
                                throw new ParseException( R.string.error_vcf_charset );
429
463
                        if( ( encoding = checkParam( params, "ENCODING" ) ) != null &&
430
 
                                        !encoding.equals( "QUOTED-PRINTABLE" ) )
 
464
                                        !encoding.equals( "QUOTED-PRINTABLE" ) &&
 
465
                                        !encoding.equals( "8BIT" ) ) //&& !encoding.equals( "BASE64" ) )
431
466
                                throw new ParseException( R.string.error_vcf_encoding );
432
467
 
433
468
                        // do decoding?
434
469
                        if( encoding != null && encoding.equals( "QUOTED-PRINTABLE" ) )
435
470
                                return unencodeQuotedPrintable( value, charset );
 
471
//                      if( encoding != null && encoding.equals( "BASE64" ) )
 
472
//                              return unencodeBase64( value, charset );
436
473
 
437
474
                        // nothing to do!
438
475
                        return value;