1 36 package jnlp.sample.JreInstaller; 37 import java.util.ResourceBundle ; 38 import java.util.PropertyResourceBundle ; 39 import java.lang.reflect.Field ; 40 import java.net.URL ; 41 import java.util.MissingResourceException ; 42 import java.text.MessageFormat ; 43 import javax.jnlp.ServiceManager; 44 import javax.jnlp.BasicService; 45 import javax.jnlp.ExtensionInstallerService; 46 import javax.jnlp.DownloadService; 47 import javax.jnlp.UnavailableServiceException; 48 49 50 59 public class Config { 60 61 62 static private ResourceBundle _resources = null; 63 64 65 static private ExtensionInstallerService _eiService; 66 static private BasicService _basicService; 67 static private DownloadService _downloadService; 68 69 70 static private synchronized void initServices() { 71 if (_eiService == null) { 72 try { 73 _eiService = (ExtensionInstallerService)ServiceManager.lookup("javax.jnlp.ExtensionInstallerService"); 74 _basicService = (BasicService)ServiceManager.lookup("javax.jnlp.BasicService"); 75 _downloadService = (DownloadService)ServiceManager.lookup("javax.jnlp.DownloadService"); 76 } catch(UnavailableServiceException use) { 77 Config.trace("Unable to locate service: " + use); 78 } 79 } 80 81 try { 85 URL bundle = (new Config()).getClass().getClassLoader().getResource("jnlp/sample/JreInstaller/resources/strings.properties"); 86 _resources = new PropertyResourceBundle (bundle.openStream()); 87 } catch(Throwable t) { 88 Config.trace("Unable to load resources: " + t); 89 } 90 } 91 92 static public BasicService getBasicService() { 93 if (_basicService == null) { 94 initServices(); 95 } 96 return _basicService; 97 } 98 99 static public ExtensionInstallerService getInstallService() { 100 if (_eiService == null) { 101 initServices(); 102 } 103 return _eiService; 104 } 105 106 static public DownloadService getDownloadService() { 107 if (_downloadService == null) { 108 initServices(); 109 } 110 return _downloadService; 111 } 112 113 116 117 static public String getJavaWSVersion() { 118 return System.getProperty("javawebstart.version"); 119 } 120 121 static public String getInstallerResource() { 123 return System.getProperty("installerEntry"); 124 } 125 126 static public String getLicenseResource() { 127 return System.getProperty("licenseEntry"); 128 } 129 130 static public String getInstallerLocation() { 132 return System.getProperty("installerLocation"); 133 } 134 135 static public String getInstallerVersion() { 137 String ver = System.getProperty("installerVersion"); 138 return (ver != null && ver.trim().length() == 0) ? null : ver; 139 } 140 141 static public String getNativeLibName() { 143 return System.getProperty("lib"); 144 } 145 146 static public String getExecString() { 148 return System.getProperty("execString"); 149 } 150 151 static public String getWaitString(int i) { 153 return System.getProperty("waitString." + i); 154 } 155 156 static public String getResponseString(int i) { 158 return System.getProperty("responseString." + i); 159 } 160 161 static public String getJavaPath() { 163 return System.getProperty("javaPath"); 164 } 165 166 static public boolean isSolarisInstall() { 168 String result = System.getProperty("isSolarisInstall"); 169 return (result != null && result.length() > 0); 170 } 171 172 static public boolean isWindowsInstall() { 173 String result = System.getProperty("isWindowsInstall"); 174 return (result != null && result.length() > 0); 175 } 176 177 static public boolean isVerbose() { 179 String result = System.getProperty("verbose"); 180 return (result != null && result.length() > 0); 181 } 182 183 static public boolean isMerlin() { 185 String result = System.getProperty("merlin"); 186 return (result != null && result.length() > 0); 187 } 188 189 static public boolean isHopper() { 191 String result = System.getProperty("hopper"); 192 return (result != null && result.length() > 0); 193 } 194 195 static public String getJavaVersion() { 197 return System.getProperty("javaVersion"); 198 } 199 200 static public String getPlatformVersion() { 201 return System.getProperty("platformVersion"); 202 } 203 204 205 static public String getMsvcrtVersionMS() { 207 return System.getProperty("msvcrt.versionMS"); 208 } 209 210 static public String getMsvcrtVersionLS() { 212 return System.getProperty("msvcrt.versionLS"); 213 } 214 215 218 public static String getJavaWSConfirmMessage() { 219 return getString("webstart.msg"); 220 } 221 222 public static String getJavaWSConfirmTitle() { 223 return getString("webstart.title"); 224 } 225 226 public static String getRebootMessage() { 227 return getString("reboot.msg"); 228 } 229 230 public static String getRebootTitle() { 231 return getString("reboot.title"); 232 } 233 234 public static String getRebootNowString() { 235 return getString("reboot.button.now"); 236 } 237 238 public static String getRebootLaterString() { 239 return getString("reboot.button.later"); 240 } 241 242 public static String getLicenseDialogTitle() { 243 return getString("license.title"); 244 } 245 246 public static String getLicenseDialogQuestionString() { 247 return getString("license.question"); 248 } 249 250 public static String getLicenseDialogAcceptString() { 251 return getString("license.button.accept"); 252 } 253 254 public static String getLicenseDialogExitString() { 255 return getString("license.button.exit"); 256 } 257 258 public static String getWindowTitle() { 259 return getString("window.title"); 260 } 261 262 public static String getWindowHeading() { 263 return getString("window.heading"); 264 } 265 266 public static String getWindowLogo() { 267 return "resources/sunlogo.png"; 268 } 269 270 public static String getWindowStep(int i) { 271 return getString("window.step." + i); 272 } 273 274 public static String getWindowAbortButton() { 275 return getString("window.button.abort"); 276 } 277 278 public static int getWindowAbortMnemonic() { 279 return getMnemonic("window.button.abort.key"); 280 } 281 282 public static String getWindowHiddenLabel() { 283 return getString("window.hiddenLabel"); 284 } 285 286 public static String getWindowStepProgress(int step, int percent) { 287 Object args[] = { getWindowStep(step), new Integer (percent) }; 288 return applyPattern("window.step.progress", args); 289 } 290 291 public static String getWindowStepWait(int step) { 292 Object args[] = { getWindowStep(step) }; 293 return applyPattern("window.step.wait", args); 294 } 295 296 297 298 static private String getString(String key) { 300 try { 301 return _resources.getString(key); 302 } catch (MissingResourceException mre) { 303 return "Missing resource for: " + key; 304 } 305 } 306 307 static private int getMnemonic(String key) { 308 String resource = getString(key); 309 if (resource != null && resource.startsWith("VK_")) { 310 try { 311 Class keyEventClazz= Class.forName("java.awt.event.KeyEvent"); 312 Field field = keyEventClazz.getDeclaredField(resource); 313 int value = field.getInt(null); 314 return value; 315 } catch (Exception e) { 316 Config.trace("getMnemonic: " + e); 317 } 318 } 319 return 0; 320 } 321 322 323 static private String applyPattern(String key, Object [] messageArguments) { 324 String message = getString(key); 325 MessageFormat formatter = new MessageFormat (message); 326 String output = formatter.format(message, messageArguments); 327 return output; 328 } 329 330 331 static public void trace(String msg) { 332 if (isVerbose()) { 333 System.out.println(msg); 334 } 335 } 336 } 337 338 339 | Popular Tags |