KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.URL JavaDoc;
24 import java.util.List JavaDoc;
25
26
27 /**
28  * Concrete implementation of the AppAssociationReader class for Gnome.
29  */

30 public class GnomeAppAssociationReader implements AppAssociationReader {
31
32     /**
33      * Returns the description associated with the given mime type.
34      *
35      * @param mimeType Given mime type
36      * @return String
37      */

38     public String JavaDoc getDescriptionByMimeType(String JavaDoc mimeType) {
39         return GnomeAssociationUtil.getDescriptionByMimeType(mimeType);
40     }
41   
42     /**
43      * Returns the description associated with the given file extension.
44      *
45      * @param fileExt Given file extension
46      * @return String
47      */

48     public String JavaDoc getDescriptionByFileExt(String JavaDoc fileExt) {
49         // Removes the leading '.' character from the file extension if exists.
50
fileExt = AppUtility.removeDotFromFileExtension(fileExt);
51         if (getMimeTypeByFileExt(fileExt) == null) {
52             return null;
53         } else {
54             return getDescriptionByMimeType(getMimeTypeByFileExt(fileExt));
55         }
56     }
57
58     /**
59      * Returns the mime type associated with the given URL, by checking the content of
60      *
61      * the URL.
62      * @param url The specified URL
63      * @return String
64      */

65     public String JavaDoc getMimeTypeByURL(URL JavaDoc url) {
66         return GnomeAssociationUtil.getMimeTypeByURL(url);
67     }
68
69     /**
70      * Returns the file extensione list associated with the given mime type.
71      *
72      * @param mimeType Given mime type
73      * @return String
74      */

75     public List JavaDoc getFileExtListByMimeType(String JavaDoc mimeType) {
76         return GnomeAssociationUtil.getFileExtListByMimeType(mimeType);
77     }
78   
79     /**
80      * Returns the mime type associated with the given file extension.
81      *
82      * @param fileExt Given file extension
83      * @return String
84      */

85     public String JavaDoc getMimeTypeByFileExt(String JavaDoc fileExt) {
86         // Removes the leading '.' character from the file extension if exists.
87
fileExt = AppUtility.removeDotFromFileExtension(fileExt);
88         return GnomeAssociationUtil.getMimeTypeByFileExt(fileExt);
89     }
90   
91     /**
92      * Returns the icon file name associated with the given mime type.
93      *
94      * @param mimeType Given mime type.
95      * @return String
96      */

97     public String JavaDoc getIconFileNameByMimeType(String JavaDoc mimeType) {
98         return GnomeAssociationUtil.getIconFileNameByMimeType(mimeType);
99     }
100   
101     /**
102      * Returns the icon file name associated with the given file extension.
103      *
104      * @param fileExt Given file extension.
105      * @return String
106      */

107     public String JavaDoc getIconFileNameByFileExt(String JavaDoc fileExt) {
108         // Remove the leading '.' character from the file extension if exists.
109
fileExt = AppUtility.removeDotFromFileExtension(fileExt);
110         if (getMimeTypeByFileExt(fileExt) == null) {
111             return null;
112         } else {
113             return getIconFileNameByMimeType(getMimeTypeByFileExt(fileExt));
114         }
115     }
116  
117     /**
118      * Returns the action list associated with the given file extension.
119      *
120      * @param mimeType the given mime type.
121      * @return List the action list associated with the given mime type.
122      */

123     public List JavaDoc getActionListByMimeType(String JavaDoc mimeType) {
124         return GnomeAssociationUtil.getActionListByMimeType(mimeType);
125     }
126
127     /**
128      * Returns the action list associated with the given mime type.
129      *
130      * @param fileExt the given file extension.
131      * @return List the action list associated with the given file extension.
132      */

133     public List JavaDoc getActionListByFileExt(String JavaDoc fileExt) {
134         // Remove the leading '.' character from the file extension if exists.
135
fileExt = AppUtility.removeDotFromFileExtension(fileExt);
136         if (getMimeTypeByFileExt(fileExt) == null) {
137             return null;
138         } else {
139             return getActionListByMimeType(getMimeTypeByFileExt(fileExt));
140         }
141     }
142
143     /**
144      * Returns true if the mime type exists in the MIME database.
145      *
146      * @param mimeType given mimeType
147      * @return true if the mime type exists in the MIME database
148      */

149     public boolean isMimeTypeExist(String JavaDoc mimeType) {
150         // The given mime type may exist in either .mime files or .keys files.
151
// First check if it's registered in .mime files.
152
boolean isExist = GnomeAssociationUtil.isMimeTypeExist(mimeType);
153
154         if (!isExist) {
155             // Then check if it exists in .keys files by checking the association info.
156
String JavaDoc iconFileName = getIconFileNameByMimeType(mimeType);
157             String JavaDoc description = getDescriptionByMimeType(mimeType);
158             List JavaDoc actionList = getActionListByMimeType(mimeType);
159
160             // If no association info, it's supposed not exists.
161
if (iconFileName != null || description != null || actionList != null) {
162                 isExist = true;
163             }
164         }
165         
166         return isExist;
167     }
168     
169     /**
170      * Returns true if the file extension exists in the MIME database.
171      *
172      * @param fileExt given file extension
173      * @return true if the file extension exists in the MIME database
174      */

175     public boolean isFileExtExist(String JavaDoc fileExt) {
176         // Remove the leading '.' character from the file extension if exists.
177
fileExt = AppUtility.removeDotFromFileExtension(fileExt);
178        
179         return GnomeAssociationUtil.isFileExtExist(fileExt);
180     }
181 }
182
Popular Tags