1 20 21 package org.jdesktop.jdic.filetypes.internal; 22 23 import java.net.URL ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 import org.jdesktop.jdic.filetypes.Action; 27 28 29 32 public class GnomeAssociationUtil { 33 34 public final static String GNOME_VFS_MIME_KEY_DESCRIPTION 35 = GnomeVfsWrapper.GNOME_VFS_MIME_KEY_DESCRIPTION; 36 public final static String GNOME_VFS_MIME_KEY_ICON_FILENAME 37 = GnomeVfsWrapper.GNOME_VFS_MIME_DEFAULT_KEY_ICON_FILENAME; 38 39 42 private GnomeAssociationUtil() {} 43 44 49 public static String getMimeTypeByFileExt(String fileExt) { 50 String resultMimeType = null; 51 String [] allMimeTypes = GnomeVfsWrapper.gnome_vfs_get_registered_mime_types(); 52 53 if (allMimeTypes == null) { 54 return null; 55 } 56 57 for (int i = 0; i < allMimeTypes.length; i++) { 58 String curMimeType = allMimeTypes[i]; 59 String [] fileExtensions = GnomeVfsWrapper.gnome_vfs_mime_get_extensions_list(curMimeType); 60 61 if (fileExtensions != null) { 62 for (int j = 0; j < fileExtensions.length; j++) { 63 if (fileExtensions[j].equals(fileExt)) { 64 resultMimeType = allMimeTypes[i]; 65 break; 66 } 67 } 68 } 69 if (resultMimeType != null) { 70 break; 71 } 72 } 73 74 return resultMimeType; 75 } 76 77 82 public static List getFileExtListByMimeType(String mimeType) { 83 String [] fileExtensions = GnomeVfsWrapper.gnome_vfs_mime_get_extensions_list(mimeType); 84 85 if (fileExtensions == null) { 86 return null; 87 } else { 88 List fileExtList = new ArrayList (); 90 for (int index = 0; index < fileExtensions.length; index++) { 91 fileExtList.add(fileExtensions[index]); 92 } 93 94 return fileExtList; 95 } 96 } 97 98 102 public static String getIconFileNameByMimeType(String mimeType) { 103 return GnomeVfsWrapper.gnome_vfs_mime_get_icon(mimeType); 104 } 105 106 112 public static String getDescriptionByMimeType(String mimeType) { 113 return GnomeVfsWrapper.gnome_vfs_mime_get_description(mimeType); 114 } 115 116 119 public static List getActionListByMimeType(String mimeType) { 120 List actionList = new ArrayList (); 121 Action oneAction = null; 122 123 String [] keys = GnomeVfsWrapper.gnome_vfs_mime_get_key_list(mimeType); 135 if (keys != null) { 136 String command = null; 137 for (int i = 0; i < keys.length; i++) { 138 command = GnomeVfsWrapper.gnome_vfs_mime_get_value(mimeType, keys[i]); 139 if (command != null) { 140 oneAction = new Action(keys[i], command); 141 actionList.add(oneAction); 142 } 143 } 144 } 145 146 151 String defaultCmd = GnomeVfsWrapper.gnome_vfs_mime_get_default_application_command(mimeType); 154 if (defaultCmd != null) { 155 actionList.add(new Action("open", defaultCmd)); 156 } 157 158 if (actionList.isEmpty()) { 159 return null; 160 } else { 161 return actionList; 162 } 163 } 164 165 169 public static String getMimeTypeByURL(URL url) { 170 return GnomeVfsWrapper.gnome_vfs_get_mime_type(url.toString()); 173 } 174 175 178 public static boolean isMimeTypeExist(String mimeType) { 179 boolean isMimeTypeExist = false; 181 String [] allMimeTypes = GnomeVfsWrapper.gnome_vfs_get_registered_mime_types(); 182 183 if (allMimeTypes == null) { 184 return false; 185 } 186 187 for (int i = 0; i < allMimeTypes.length; i++) { 188 if (mimeType.equals(allMimeTypes[i])) { 189 isMimeTypeExist = true; 190 break; 191 } 192 } 193 194 return isMimeTypeExist; 195 } 196 197 200 public static boolean isFileExtExist(String fileExt) { 201 return (getMimeTypeByFileExt(fileExt) != null) ? true : false; 202 } 203 204 208 public static String getEnv(String envName) { 209 return GnomeVfsWrapper.getenv(envName); 210 } 211 } 212 | Popular Tags |