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

  • Committer: edam
  • Date: 2009-01-11 16:47:01 UTC
  • Revision ID: edam@waxworlds.org-20090111164701-tvnnv5axo6jd7ck0
- added GPL header comments to all files
- added GPLv3 to project as COPYING

Show diffs side-by-side

added added

removed removed

21
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
22
 */
23
23
 
24
 
package org.waxworlds.edam.importcontacts;
 
24
package org.waxworlds.importcontacts;
25
25
 
26
26
import java.io.BufferedReader;
27
27
import java.io.File;
38
38
import java.util.regex.Matcher;
39
39
import java.util.regex.Pattern;
40
40
 
 
41
import org.waxworlds.importcontacts.Importer.AbortImportException;
 
42
 
41
43
import android.content.SharedPreferences;
42
44
import android.provider.Contacts;
43
45
import android.provider.Contacts.PhonesColumns;
67
69
                        // open directory
68
70
                        String location = prefs.getString( "location", "" );
69
71
                        File dir = new File( location );
70
 
                        if( !dir.exists() )
 
72
                        if( !dir.exists() || !dir.isDirectory() )
71
73
                                showError( R.string.error_locationnotfound );
72
74
 
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
 
                        }
 
75
                        // get files
 
76
                        class VCardFilter implements FilenameFilter {
 
77
                            public boolean accept( File dir, String name ) {
 
78
                                return name.toLowerCase().endsWith( ".vcf" );
 
79
                            }
 
80
                        }
 
81
                        files = dir.listFiles( new VCardFilter() );
90
82
                }
91
83
                catch( SecurityException e ) {
92
84
                        showError( R.string.error_locationpermissions );
254
246
                private Vector< String > _lines = null;
255
247
                private int _nameLevel = NAMELEVEL_NONE;
256
248
 
257
 
                @SuppressWarnings("serial")
258
249
                protected class ParseException extends Exception
259
250
                {
260
 
                        @SuppressWarnings("unused")
261
251
                        public ParseException( String error )
262
252
                        {
263
253
                                super( error );
269
259
                        }
270
260
                }
271
261
 
272
 
                @SuppressWarnings("serial")
273
262
                protected class SkipContactException extends Exception { }
274
263
 
275
264
                public void parseLine( String line )
461
450
                                        !charset.equals( "UTF-8" ) && !charset.equals( "UTF-16" ) )
462
451
                                throw new ParseException( R.string.error_vcf_charset );
463
452
                        if( ( encoding = checkParam( params, "ENCODING" ) ) != null &&
464
 
                                        !encoding.equals( "QUOTED-PRINTABLE" ) &&
465
 
                                        !encoding.equals( "8BIT" ) ) //&& !encoding.equals( "BASE64" ) )
 
453
                                        !encoding.equals( "QUOTED-PRINTABLE" ) )
466
454
                                throw new ParseException( R.string.error_vcf_encoding );
467
455
 
468
456
                        // do decoding?
469
457
                        if( encoding != null && encoding.equals( "QUOTED-PRINTABLE" ) )
470
458
                                return unencodeQuotedPrintable( value, charset );
471
 
//                      if( encoding != null && encoding.equals( "BASE64" ) )
472
 
//                              return unencodeBase64( value, charset );
473
459
 
474
460
                        // nothing to do!
475
461
                        return value;