1 20 21 package org.jdesktop.jdic.desktop.internal.impl; 22 23 import java.io.File ; 24 import java.net.URL ; 25 26 27 32 public class WinUtility { 33 36 private WinUtility() {} 37 38 49 private static String getFileExtension(File file) { 50 String trimFileStr = file.toString().trim(); 51 52 if (trimFileStr == null || trimFileStr == "") { 53 return null; 54 } 55 56 int strIndex = trimFileStr.lastIndexOf(File.separator); 57 String filePart = trimFileStr.substring(strIndex + 1, trimFileStr.length()); 58 59 strIndex = filePart.lastIndexOf("."); 60 if (strIndex == -1 || strIndex == filePart.length() - 1) { 61 return null; 62 } else { 63 String fileExt = filePart.substring(strIndex, filePart.length()); 64 65 return fileExt; 66 } 67 } 68 69 80 public static String getVerbCommand(File file, String verb) { 81 String fileExt = getFileExtension(file); 82 if (fileExt == null) { 83 return null; 84 } else { 85 return(WinAPIWrapper.WinAssocQueryString(fileExt, verb)); 86 } 87 } 88 89 101 public static String getVerbCommand(URL url, String verb) { 102 String protocolType = url.getProtocol().trim(); 103 if (protocolType.compareToIgnoreCase("file") == 0) { 106 protocolType = "http"; 107 } 108 109 if (protocolType == null) { 110 return null; 111 } else { 112 return(WinAPIWrapper.WinAssocQueryString(protocolType, verb)); 113 } 114 } 115 116 121 static String getDefaultMailer() { 122 String defaultMailer = 123 WinAPIWrapper.WinRegQueryValueEx( 124 WinAPIWrapper.HKEY_LOCAL_MACHINE, 125 "SOFTWARE\\Clients\\Mail", 126 ""); 127 return defaultMailer; 128 } 129 130 137 static String getMozMailerLocation(String defMailer) { 138 String mailerPath = WinAPIWrapper.WinRegQueryValueEx( 139 WinAPIWrapper.HKEY_LOCAL_MACHINE, 140 "SOFTWARE\\Clients\\Mail\\"+defMailer+"\\shell\\open\\command", 141 ""); 142 int lastSpace = mailerPath.lastIndexOf(' '); 143 return mailerPath.substring(0, lastSpace); 144 } 145 146 151 static boolean isMapiSupported() { 152 String regMapi = 153 WinAPIWrapper.WinRegQueryValueEx( 154 WinAPIWrapper.HKEY_LOCAL_MACHINE, 155 "SOFTWARE\\Microsoft\\Windows Messaging Subsystem", 156 "MAPI"); 157 if(regMapi != null) { 158 if(regMapi.equals("1")) { 159 return true; 160 } 161 } 162 return false; 163 } 164 } | Popular Tags |