KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdic > filetypes > internal > GnomeAppAssociationWriter


1 /*
2  * Copyright (C) 2004 Sun Microsystems, Inc. All rights reserved. Use is
3  * subject to license terms.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the Lesser GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  */

20
21 package org.jdesktop.jdic.filetypes.internal;
22
23 import java.io.BufferedReader JavaDoc;
24 import java.io.BufferedWriter JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.FileReader JavaDoc;
27 import java.io.FileWriter JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import org.jdesktop.jdic.filetypes.Action;
32 import org.jdesktop.jdic.filetypes.Association;
33 import org.jdesktop.jdic.filetypes.RegisterFailedException;
34
35
36 /**
37  * Concrete implementation of the AppAssociationWriter class for Gnome.
38  */

39 public class GnomeAppAssociationWriter implements AppAssociationWriter {
40     // Gnome system MIME database dir on Linux.
41
// First check the environment variable GNOMEDIR. If it's not set,
42
// use the default/hard-coded /usr/share as top-level dir of the mime-info subdirectory.
43
static String JavaDoc GNOMEDIR_VALUE = GnomeAssociationUtil.getEnv("GNOMEDIR");
44     static String JavaDoc GNOME_LINUX_SYSTEM_SHARE_DIR =
45        (GNOMEDIR_VALUE == null) ? "/usr/share/" : (GNOMEDIR_VALUE + "/share/");
46     static String JavaDoc GNOME_SOLARIS_SYSTEM_SHARE_DIR = "/usr/share/gnome/";
47
48     // System mime-info directory.
49
static String JavaDoc GNOME_LINUX_SYSTEM_MIME_INFO_DIR = GNOME_LINUX_SYSTEM_SHARE_DIR + "mime-info/";
50     static String JavaDoc GNOME_SOLARIS_SYSTEM_MIME_INFO_DIR = GNOME_SOLARIS_SYSTEM_SHARE_DIR + "mime-info/";
51     
52     // System application-registry directory.
53
static String JavaDoc GNOME_LINUX_SYSTEM_APPLICATION_REGISTRY_DIR = GNOME_LINUX_SYSTEM_SHARE_DIR
54         + "application-registry/";
55     static String JavaDoc GNOME_SOLARIS_SYSTEM_APPLICATION_REGISTRY_DIR = GNOME_SOLARIS_SYSTEM_SHARE_DIR
56         + "application-registry/";
57
58     // Current system mime-info and application-registry directory.
59
static String JavaDoc OSNAME = System.getProperty("os.name").toLowerCase();
60     static String JavaDoc GNOME_SYSTEM_MIME_INFO_DIR =
61         OSNAME.equals("linux") ? GNOME_LINUX_SYSTEM_MIME_INFO_DIR : GNOME_SOLARIS_SYSTEM_MIME_INFO_DIR;
62     static String JavaDoc GNOME_SYSTEM_APPLICATION_REGISTRY_DIR =
63         OSNAME.equals("linux") ?
64             GNOME_LINUX_SYSTEM_APPLICATION_REGISTRY_DIR : GNOME_SOLARIS_SYSTEM_APPLICATION_REGISTRY_DIR;
65
66     // User mime-info and application-info directory.
67
static String JavaDoc GNOME_USER_MIME_INFO_DIR = System.getProperty("user.home") + "/.gnome/mime-info/";
68     static String JavaDoc GNOME_USER_APPLICATION_INFO_DIR = System.getProperty("user.home") + "/.gnome/application-info/";
69
70     // Suffixes for the generated .mime, .keys and .applications files.
71
static String JavaDoc MIME_SUFFIX = ".mime";
72     static String JavaDoc KEYS_SUFFIX = ".keys";
73     static String JavaDoc APPLICATIONS_SUFFIX = ".applications";
74
75     // Generated default application ID and command from the given open action, which will be written into .keys and .applications files.
76
private String JavaDoc defaultAppID = null;
77     private String JavaDoc defaultAppCommand = null;
78     
79     /**
80      * Converts the specified file extension list to a file extension string.
81      * <P>
82      * Notice: Since all the given file extensions have a leading '.' character,
83      * remove this '.' before write it to .mime file.
84      *
85      * @see madhatter.association.Association#addFileExtension
86      */

87     private String JavaDoc fileExtListToString(List JavaDoc fileExtList) {
88         String JavaDoc fileExtListString = "";
89         Iterator JavaDoc fileExtIter = fileExtList.iterator();
90         String JavaDoc temFileExt;
91
92         if (fileExtIter != null) {
93             while (fileExtIter.hasNext()) {
94                 temFileExt = (String JavaDoc) fileExtIter.next();
95                 
96                 if (temFileExt != null) {
97                     // Remove the leading '.' character if exists.
98
temFileExt = AppUtility.removeDotFromFileExtension(temFileExt);
99                     
100                     if (fileExtListString.length() == 0) {
101                         fileExtListString = fileExtListString.concat(temFileExt);
102                     } else {
103                         fileExtListString = fileExtListString.concat(' ' + temFileExt);
104                     }
105                 }
106             }
107         } else {
108             fileExtListString = null;
109         }
110     
111         return fileExtListString;
112     }
113
114     /**
115      * Returns the absolute system .mime file path by the name field of the specified association.
116      */

117     private String JavaDoc getSystemDotMimeFilePath(Association assoc) {
118         return GNOME_SYSTEM_MIME_INFO_DIR + assoc.getName() + MIME_SUFFIX;
119     }
120     
121     /**
122      * Returns the absolute system .keys file path by the name field of the specified association.
123      */

124     private String JavaDoc getSystemDotKeysFilePath(Association assoc) {
125         return GNOME_SYSTEM_MIME_INFO_DIR + assoc.getName() + KEYS_SUFFIX;
126     }
127
128     /**
129      * Returns the absolute system .applications file path by the name field of the specified association.
130      */

131     private String JavaDoc getSystemDotApplicationsFilePath(Association assoc) {
132         return GNOME_SYSTEM_APPLICATION_REGISTRY_DIR + assoc.getName() + APPLICATIONS_SUFFIX;
133     }
134
135     /**
136      * Returns the absolute user .mime file path by the name field of the specified association.
137      */

138     private String JavaDoc getUserDotMimeFilePath(Association assoc) {
139         return GNOME_USER_MIME_INFO_DIR + assoc.getName() + MIME_SUFFIX;
140     }
141     
142     /**
143      * Returns the absolute user .keys file path by the name field of the specified association.
144      */

145     private String JavaDoc getUserDotKeysFilePath(Association assoc) {
146         return GNOME_USER_MIME_INFO_DIR + assoc.getName() + KEYS_SUFFIX;
147     }
148
149     /**
150      * Returns the absolute user .applications file path by the name field of the specified association.
151      */

152     private String JavaDoc getUserDotApplicationsFilePath(Association assoc) {
153         return GNOME_USER_APPLICATION_INFO_DIR + assoc.getName() + APPLICATIONS_SUFFIX;
154     }
155
156     /**
157      * Check if the system MIME database exists and is writable, by checking
158      * the mime-info and application-registry/application-info directories. By default,
159      * these mime info directories should be installed and kept there.
160      *
161      * @throws IOException if the system MIME info directory doesn't exist, or no write
162      * permission to access.
163      */

164     private void checkSystemMIMEDatabase() throws IOException JavaDoc {
165         File JavaDoc tempFile = null;
166         
167         // Check if the system mime-info and application-registry directories exist.
168
tempFile = new File JavaDoc(GNOME_SYSTEM_MIME_INFO_DIR);
169         if (!tempFile.exists()) {
170             throw new IOException JavaDoc("The system MIME info directory doesn't exist: "
171                     + GNOME_SYSTEM_MIME_INFO_DIR
172                     + ". Make sure Gnome 2.0+ is installed and env GNOMEDIR is set properly.");
173         }
174
175         tempFile = new File JavaDoc(GNOME_SYSTEM_APPLICATION_REGISTRY_DIR);
176         if (!tempFile.exists()) {
177             throw new IOException JavaDoc("The system MIME info directory doesn't exist: "
178                     + GNOME_SYSTEM_APPLICATION_REGISTRY_DIR
179                     + ". Make sure Gnome 2.0+ is installed and env GNOMEDIR is set properly.");
180         }
181
182         // Check if the system mime-info and application-registry directories are writable.
183
tempFile = new File JavaDoc(GNOME_SYSTEM_MIME_INFO_DIR);
184         if (!tempFile.canWrite()) {
185             throw new IOException JavaDoc("No write permission to the system MIME info directory: "
186                     + GNOME_SYSTEM_MIME_INFO_DIR);
187         }
188
189         tempFile = new File JavaDoc(GNOME_SYSTEM_APPLICATION_REGISTRY_DIR);
190         if (!tempFile.canWrite()) {
191             throw new IOException JavaDoc("No write permission to the system MIME info directory: "
192                     + GNOME_SYSTEM_APPLICATION_REGISTRY_DIR);
193         }
194     }
195
196     /**
197      * Check if the user MIME database exists and is writable, by checking
198      * the mime-info and application-registry directories. By default,
199      * these directories should be installed and kept there.
200      *
201      * @throws IOException if the user MIME info directory doesn't exist, or no write
202      * permission to access.
203      */

204     private void checkUserMIMEDatabase() throws IOException JavaDoc {
205         File JavaDoc tempFile = null;
206     
207         // Check if the user mime-info and application-info directories exist.
208
tempFile = new File JavaDoc(GNOME_USER_MIME_INFO_DIR);
209         if (!tempFile.exists()) {
210             // Create the directory.
211
boolean mksucceed = tempFile.mkdirs();
212             if (mksucceed == false) {
213                 throw new IOException JavaDoc("The user MIME info directory doesn't exist, "
214                         + "and fails to be created: " + GNOME_USER_MIME_INFO_DIR);
215             }
216         }
217
218         tempFile = new File JavaDoc(GNOME_USER_APPLICATION_INFO_DIR);
219         if (!tempFile.exists()) {
220             // Create the directory.
221
boolean mksucceed = tempFile.mkdirs();
222             if (mksucceed == false) {
223                 throw new IOException JavaDoc("The user MIME info directory doesn't exist, "
224                         + "and fails to be created: " + GNOME_USER_APPLICATION_INFO_DIR);
225             }
226         }
227
228         // Check if the user mime-info and application-info directories is writable.
229
tempFile = new File JavaDoc(GNOME_USER_MIME_INFO_DIR);
230         if (!tempFile.canWrite()) {
231             throw new IOException JavaDoc("No write permission to the user MIME info directory: "
232                     + GNOME_USER_MIME_INFO_DIR);
233         }
234
235         tempFile = new File JavaDoc(GNOME_USER_APPLICATION_INFO_DIR);
236         if (!tempFile.canWrite()) {
237             throw new IOException JavaDoc("No write permission to the user MIME info directory: "
238                     + GNOME_USER_MIME_INFO_DIR);
239         }
240     }
241
242
243     /**
244      * Creates one mime file(.mime, .keys or .applications) in MIME database if not exist.
245      *
246      * @throws IOException if the given file fails to be created.
247      */

248     private void createFile(String JavaDoc mimeFilePath) throws IOException JavaDoc {
249         boolean createSucceed = false;
250         
251         File JavaDoc mimeFile = new File JavaDoc(mimeFilePath);
252         if (!mimeFile.exists()) {
253             createSucceed = mimeFile.createNewFile();
254             if (!createSucceed) {
255                 throw new IOException JavaDoc("Create MIME file: " + mimeFilePath + " failed.");
256             }
257         }
258     }
259
260     /**
261      * Here we only accept and write the "open" action and *ignore* other actions.
262      * Since other actions are not applied/used on Gnome desktop at all.
263      * The parsed application ID and application command info will be write into .keys and .application files.
264      */

265     private void parseOpenAction(Association assoc) {
266         List JavaDoc actionList = assoc.getActionList();
267         
268         if (actionList == null) {
269             return;
270         } else {
271             String JavaDoc verb = null;
272             Iterator JavaDoc actionIter = actionList.iterator();
273
274             while (actionIter.hasNext() && defaultAppCommand == null) {
275                 Action oneAction = (Action) actionIter.next();
276                 verb = oneAction.getVerb();
277                 if (verb.equalsIgnoreCase("open")) {
278                     defaultAppCommand = oneAction.getCommand().trim();
279                 }
280             }
281             
282             if (defaultAppCommand != null) {
283                 // Check the application command and application id, which will be written into .applications file.
284
int sepIndex = defaultAppCommand.lastIndexOf(File.separator);
285                 if (sepIndex == -1 || sepIndex == defaultAppCommand.length() - 1 ) {
286                     defaultAppID = defaultAppCommand;
287                 } else {
288                     defaultAppID = defaultAppCommand.substring(sepIndex + 1, defaultAppCommand.length());
289                 }
290             }
291         }
292     }
293     
294     /**
295      * Writes association fields into specified .mime file, including mime type,
296      * and extension list.
297      *
298      * @throws IOException if the given association info fails to be write to the given
299      * mime file.
300      */

301     private void writeDotMimeFile(Association assoc, String JavaDoc dotMimeFilePath) throws IOException JavaDoc {
302         // Create file first.
303
createFile(dotMimeFilePath);
304         
305         String JavaDoc mimeType = assoc.getMimeType();
306         List JavaDoc fileExtList = assoc.getFileExtList();
307
308         BufferedWriter JavaDoc mBufferWriter = null;
309         try {
310             // Appends new mime info into .mime file.
311
mBufferWriter = new BufferedWriter JavaDoc(new FileWriter JavaDoc(dotMimeFilePath, true));
312
313             mBufferWriter.write(mimeType + "\n");
314             String JavaDoc fileExtensionString = null;
315
316             if (fileExtList == null) {
317                 fileExtensionString = "";
318             } else {
319                 fileExtensionString = fileExtListToString(fileExtList);
320             }
321             mBufferWriter.write("\t" + "ext: " + fileExtensionString + "\n");
322             mBufferWriter.write("\n");
323         } catch (IOException JavaDoc e) {
324             throw new IOException JavaDoc("Write mime info to " + dotMimeFilePath + " failed.");
325         } finally {
326             // No matter what happens, always close streams already opened.
327
if (mBufferWriter != null) {
328                 try {
329                    mBufferWriter.close();
330                 } catch (IOException JavaDoc e) {
331                 }
332             }
333         }
334     }
335
336     /**
337      * Writes association fields into specified .keys file, including mime type, and icon file, and action list.
338      *
339      * @throws IOException if the given association info fails to be write to the given
340      * mime file.
341      */

342     private void writeDotKeysFile(Association assoc, String JavaDoc dotKeysFilePath)
343         throws IOException JavaDoc {
344         // Create file first.
345
createFile(dotKeysFilePath);
346
347         String JavaDoc mimeType = assoc.getMimeType();
348         String JavaDoc description = assoc.getDescription();
349         String JavaDoc iconFileName = assoc.getIconFileName();
350         
351         BufferedWriter JavaDoc kBufferWriter = null;
352         try {
353             // Appends new mime info into .keys file.
354
kBufferWriter = new BufferedWriter JavaDoc(new FileWriter JavaDoc(dotKeysFilePath, true));
355
356             kBufferWriter.write(mimeType + "\n");
357             if (description != null) {
358                 kBufferWriter.write("\t"
359                         + GnomeAssociationUtil.GNOME_VFS_MIME_KEY_DESCRIPTION
360                         + "=" + description + "\n");
361             }
362
363             if (iconFileName != null) {
364                 kBufferWriter.write("\t"
365                         + GnomeAssociationUtil.GNOME_VFS_MIME_KEY_ICON_FILENAME
366                         + "=" + iconFileName + "\n");
367             }
368
369             // Parse the given action list to get the application id and command.
370
parseOpenAction(assoc);
371             if (defaultAppID != null) {
372                     kBufferWriter.write("\t" + "default_action_type=application" + "\n");
373                     kBufferWriter.write("\t" + "default_application_id=" + defaultAppID + "\n");
374                     kBufferWriter.write("\t" + "short_list_application_user_additions=" + defaultAppID + "\n");
375             }
376             
377             kBufferWriter.write("\n");
378         } catch (IOException JavaDoc e) {
379             throw new IOException JavaDoc("Write mime info to " + dotKeysFilePath + " failed.");
380         } finally {
381             // No matter what happens, always close streams already opened.
382
if (kBufferWriter != null) {
383                 try {
384                    kBufferWriter.close();
385                 } catch (IOException JavaDoc e) {
386                 }
387             }
388         }
389     }
390
391     /**
392      * Writes association fields into specified .applications file,
393      *
394      * @throws IOException if the given association info fails to be write to the given
395      * mime file.
396      */

397     private void writeDotApplicationsFile(Association assoc, String JavaDoc dotApplicationsFilePath)
398         throws IOException JavaDoc {
399         // Create file first.
400
createFile(dotApplicationsFilePath);
401
402         BufferedWriter JavaDoc mBufferWriter = null;
403         try {
404             // Parse the given action list to get the application id and command.
405
parseOpenAction(assoc);
406             if (defaultAppID != null && defaultAppCommand != null) {
407                 // Appends new mime info into .applications file.
408
mBufferWriter = new BufferedWriter JavaDoc(new FileWriter JavaDoc(dotApplicationsFilePath, true));
409
410                 mBufferWriter.write(defaultAppID + "\n");
411                 mBufferWriter.write("\t" + "command=" + defaultAppCommand + "\n");
412                 mBufferWriter.write("\t" + "name=" + defaultAppID + "\n");
413                 mBufferWriter.write("\t" + "can_open_multiple_files=false" + "\n");
414                 mBufferWriter.write("\t" + "requires_terminal=false" + "\n");
415
416                 String JavaDoc mimeType = assoc.getMimeType();
417                 mBufferWriter.write("\t" + "mime_types=" + mimeType + "\n");
418             
419                 mBufferWriter.write("\n");
420             }
421         } catch (IOException JavaDoc e) {
422             throw new IOException JavaDoc("Write mime info to " + dotApplicationsFilePath + " failed.");
423         } finally {
424             // No matter what happens, always close streams already opened.
425
if (mBufferWriter != null) {
426                 try {
427                    mBufferWriter.close();
428                 } catch (IOException JavaDoc e) {
429                 }
430             }
431         }
432     }
433     
434     /**
435      * Checks whether the specified .mime file contains the specified mime type.
436      */

437     private boolean dotMimeFileContainsMimeType(File JavaDoc dotMimeFile, String JavaDoc mimeType) {
438         boolean isMimeTypeExist = false;
439
440         try {
441             BufferedReader JavaDoc mBufferReader = new BufferedReader JavaDoc(new FileReader JavaDoc(dotMimeFile));
442             String JavaDoc oneLine;
443     
444             while ((oneLine = mBufferReader.readLine()) != null) {
445                 if (mimeType.equals(oneLine)) {
446                     isMimeTypeExist = true;
447                     break;
448                 }
449             }
450           
451             mBufferReader.close();
452             
453             return isMimeTypeExist;
454         } catch (IOException JavaDoc e) {
455             return false;
456         }
457     }
458
459     /**
460      * Checks whether the specified association object is valid for registration.
461      * <P>
462      * Both the name and mimeType fields must be specified to perform this operation.
463      * If either of the fields is null, an IllegalArgumentException is thrown.
464      *
465      * @param assoc a given Association object.
466      * @throws IllegalArgumentException if the given association is not valid for registration.
467      */

468     public void checkAssociationValidForRegistration(Association assoc)
469         throws IllegalArgumentException JavaDoc {
470         if (assoc.getName() == null || assoc.getMimeType() == null) {
471             throw new IllegalArgumentException JavaDoc("The given association is invalid. It should " +
472                 "specify both the name and mimeType fields to perform this operation.");
473         }
474     }
475   
476     /**
477      * Checks whether the specified association object is valid for unregistration.
478      * <P>
479      * The name field must be specified to perform this operation. Or else,
480      * an IllegalArgumentException is thrown.
481      *
482      * @param assoc a given Association object.
483      * @throws IllegalArgumentException if the given association is not valid for unregistration.
484      */

485     public void checkAssociationValidForUnregistration(Association assoc)
486         throws IllegalArgumentException JavaDoc {
487         if (assoc.getName() == null) {
488             throw new IllegalArgumentException JavaDoc("The given association is invalid. It should " +
489                 "specify the name field to perform this operation.");
490         }
491     }
492
493     /**
494      * Checks whether or not the given assocation already existed in the MIME type database.
495      * <P>
496      * If the mime files identified by the name field (name.mime and name.keys) already exists
497      * in the specified MIME database, return true.
498      *
499      * @param assoc a given Association
500      * @param level a given MIME database level.
501      * @return true if the given Association already exists in the specified MIME database.
502      */

503     public boolean isAssociationExist(Association assoc, int level) {
504         File JavaDoc dotMimeFile = null;
505         if (level == SYSTEM_LEVEL) {
506             // Check the mime files in system default MIME database.
507
dotMimeFile = new File JavaDoc(getSystemDotMimeFilePath(assoc));
508         } else {
509             // Check the mime files in user MIME database.
510
dotMimeFile = new File JavaDoc(getUserDotMimeFilePath(assoc));
511         }
512
513         if (dotMimeFile.exists()) {
514             // The .mime file exist, check the mime type in the .mime file.
515
if (assoc.getMimeType() == null) {
516                 return true;
517             } else {
518                 return dotMimeFileContainsMimeType(dotMimeFile, assoc.getMimeType());
519             }
520         } else {
521             return false;
522         }
523     }
524       
525     /**
526      * Registers the given association info in the specified level.
527      * <P>
528      * Generate the mime files identified by the name field(name.mime and name.keys)
529      * in the system or user MIME database. Then write the association info into the
530      * generated mime files.
531      *
532      * @param assoc the given association.
533      * @param level the given registration level.
534      * @throws RegisterFailedException if the registration failed.
535      */

536     public void registerAssociation(Association assoc, int level)
537         throws RegisterFailedException {
538         String JavaDoc dotMimeFilePath = null;
539         String JavaDoc dotKeysFilePath = null;
540         String JavaDoc dotApplicationsFilePath = null;
541         
542         try {
543             if (level == SYSTEM_LEVEL) {
544                 checkSystemMIMEDatabase();
545                 
546                 dotMimeFilePath = getSystemDotMimeFilePath(assoc);
547                 dotKeysFilePath = getSystemDotKeysFilePath(assoc);
548                 dotApplicationsFilePath = getSystemDotApplicationsFilePath(assoc);
549              } else {
550                 checkUserMIMEDatabase();
551                 
552                 dotMimeFilePath = getUserDotMimeFilePath(assoc);
553                 dotKeysFilePath = getUserDotKeysFilePath(assoc);
554                 dotApplicationsFilePath = getUserDotApplicationsFilePath(assoc);
555              }
556              
557             // Create and write .mime file.
558
writeDotMimeFile(assoc, dotMimeFilePath);
559
560             // Create and write .keys file.
561
writeDotKeysFile(assoc, dotKeysFilePath);
562             
563             // Create and write .applications file.
564
writeDotApplicationsFile(assoc, dotApplicationsFilePath);
565         } catch (IOException JavaDoc e) {
566             // If there are errors, try to delete all the created mime files.
567
if (dotMimeFilePath != null ) {
568                 (new File JavaDoc(dotMimeFilePath)).delete();
569             }
570             if (dotKeysFilePath != null) {
571                 (new File JavaDoc(dotKeysFilePath)).delete();
572             }
573             if (dotApplicationsFilePath != null) {
574                 (new File JavaDoc(dotApplicationsFilePath)).delete();
575             }
576             
577             throw new RegisterFailedException(e.getMessage());
578         }
579     }
580   
581     /**
582      * Unregisters the given association in the specified level.
583      * <P>
584      * Removes the mime files identified by the name field(name.mime and name.keys) from
585      * the system or user MIME type.
586      *
587      * @param assoc the given association.
588      * @param level the given unregistration level.
589      * @throws RegisterFailedException if the unregistration failed.
590      */

591     public void unregisterAssociation(Association assoc, int level) throws RegisterFailedException {
592         String JavaDoc dotMimeFilePath = null;
593         String JavaDoc dotKeysFilePath = null;
594         String JavaDoc dotApplicationsFilePath = null;
595                 
596         try {
597             if (level == SYSTEM_LEVEL) {
598                 checkSystemMIMEDatabase();
599                 
600                 dotMimeFilePath = getSystemDotMimeFilePath(assoc);
601                 dotKeysFilePath = getSystemDotKeysFilePath(assoc);
602                 dotApplicationsFilePath = getSystemDotApplicationsFilePath(assoc);
603              } else {
604                 checkUserMIMEDatabase();
605                 
606                 dotMimeFilePath = getUserDotMimeFilePath(assoc);
607                 dotKeysFilePath = getUserDotKeysFilePath(assoc);
608                 dotApplicationsFilePath = getUserDotApplicationsFilePath(assoc);
609              }
610
611             // Delete the mime files.
612
(new File JavaDoc(dotMimeFilePath)).delete();
613             (new File JavaDoc(dotKeysFilePath)).delete();
614             (new File JavaDoc(dotApplicationsFilePath)).delete();
615         } catch (IOException JavaDoc e) {
616             throw new RegisterFailedException(e.getMessage());
617         }
618     }
619 }
Popular Tags