KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jnlp > sample > JreInstaller > Config


1 /*
2  * @(#)Config.java 1.7 05/11/30
3  *
4  * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * -Redistribution of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * -Redistribution in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * Neither the name of Sun Microsystems, Inc. or the names of contributors may
17  * be used to endorse or promote products derived from this software without
18  * specific prior written permission.
19  *
20  * This software is provided "AS IS," without a warranty of any kind. ALL
21  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
22  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
23  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
24  * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
25  * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
26  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
27  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
28  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
29  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
30  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31  *
32  * You acknowledge that this software is not designed, licensed or intended
33  * for use in the design, construction, operation or maintenance of any
34  * nuclear facility.
35  */

36 package jnlp.sample.JreInstaller;
37 import java.util.ResourceBundle JavaDoc;
38 import java.util.PropertyResourceBundle JavaDoc;
39 import java.lang.reflect.Field JavaDoc;
40 import java.net.URL JavaDoc;
41 import java.util.MissingResourceException JavaDoc;
42 import java.text.MessageFormat JavaDoc;
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 /** Contains configuration information for an
51  * installer.
52  *
53  * Part of the configuration is read as properties
54  * set in the JNLP file - other information is
55  * currently hard-coded as strings - they should
56  * properly be moved to resources.
57  *
58  */

59 public class Config {
60     
61     /** Localization */
62     static private ResourceBundle JavaDoc _resources = null;
63     
64     /** JNLP services */
65     static private ExtensionInstallerService _eiService;
66     static private BasicService _basicService;
67     static private DownloadService _downloadService;
68     
69     /** Initialize basic services class */
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     // We cannot really use this, since it breaks lazy loading. When resources for all locales
82
// are in place it should be ok. Or we need another solution.
83
//_resources = ResourceBundle.getBundle("jnlp/JreInstaller/resources/strings");
84
try {
85         URL JavaDoc bundle = (new Config()).getClass().getClassLoader().getResource("jnlp/sample/JreInstaller/resources/strings.properties");
86         _resources = new PropertyResourceBundle JavaDoc(bundle.openStream());
87     } catch(Throwable JavaDoc 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     /*
114      * Configuration for JNLP file
115      */

116     
117     static public String JavaDoc getJavaWSVersion() {
118     return System.getProperty("javawebstart.version");
119     }
120
121     // Win/Solaris
122
static public String JavaDoc getInstallerResource() {
123     return System.getProperty("installerEntry");
124     }
125     
126     static public String JavaDoc getLicenseResource() {
127     return System.getProperty("licenseEntry");
128     }
129     
130     // Win/Solaris
131
static public String JavaDoc getInstallerLocation() {
132     return System.getProperty("installerLocation");
133     }
134     
135     // Win/Solaris
136
static public String JavaDoc getInstallerVersion() {
137     String JavaDoc ver = System.getProperty("installerVersion");
138     return (ver != null && ver.trim().length() == 0) ? null : ver;
139     }
140     
141     // Win-only
142
static public String JavaDoc getNativeLibName() {
143     return System.getProperty("lib");
144     }
145     
146     // Win/Solaris
147
static public String JavaDoc getExecString() {
148     return System.getProperty("execString");
149     }
150     
151     // Solaris-only
152
static public String JavaDoc getWaitString(int i) {
153     return System.getProperty("waitString." + i);
154     }
155     
156     // Solaris-only
157
static public String JavaDoc getResponseString(int i) {
158     return System.getProperty("responseString." + i);
159     }
160     
161     // Win/Solaris
162
static public String JavaDoc getJavaPath() {
163     return System.getProperty("javaPath");
164     }
165     
166     // Solaris-only
167
static public boolean isSolarisInstall() {
168     String JavaDoc result = System.getProperty("isSolarisInstall");
169     return (result != null && result.length() > 0);
170     }
171
172     static public boolean isWindowsInstall() {
173     String JavaDoc result = System.getProperty("isWindowsInstall");
174     return (result != null && result.length() > 0);
175     }
176     
177     // Win/Solaris
178
static public boolean isVerbose() {
179     String JavaDoc result = System.getProperty("verbose");
180     return (result != null && result.length() > 0);
181     }
182
183     // Win-only
184
static public boolean isMerlin() {
185     String JavaDoc result = System.getProperty("merlin");
186     return (result != null && result.length() > 0);
187     }
188
189     // Win-only
190
static public boolean isHopper() {
191     String JavaDoc result = System.getProperty("hopper");
192     return (result != null && result.length() > 0);
193     }
194     
195     // Win-only
196
static public String JavaDoc getJavaVersion() {
197     return System.getProperty("javaVersion");
198     }
199
200     static public String JavaDoc getPlatformVersion() {
201     return System.getProperty("platformVersion");
202     }
203     
204     
205     // Win-only
206
static public String JavaDoc getMsvcrtVersionMS() {
207     return System.getProperty("msvcrt.versionMS");
208     }
209     
210     // Win-only
211
static public String JavaDoc getMsvcrtVersionLS() {
212     return System.getProperty("msvcrt.versionLS");
213     }
214     
215     /*
216      * String resources
217      */

218     public static String JavaDoc getJavaWSConfirmMessage() {
219     return getString("webstart.msg");
220     }
221
222     public static String JavaDoc getJavaWSConfirmTitle() {
223     return getString("webstart.title");
224     }
225
226     public static String JavaDoc getRebootMessage() {
227     return getString("reboot.msg");
228     }
229     
230     public static String JavaDoc getRebootTitle() {
231     return getString("reboot.title");
232     }
233     
234     public static String JavaDoc getRebootNowString() {
235     return getString("reboot.button.now");
236     }
237     
238     public static String JavaDoc getRebootLaterString() {
239     return getString("reboot.button.later");
240     }
241     
242     public static String JavaDoc getLicenseDialogTitle() {
243     return getString("license.title");
244     }
245     
246     public static String JavaDoc getLicenseDialogQuestionString() {
247     return getString("license.question");
248     }
249     
250     public static String JavaDoc getLicenseDialogAcceptString() {
251     return getString("license.button.accept");
252     }
253     
254     public static String JavaDoc getLicenseDialogExitString() {
255     return getString("license.button.exit");
256     }
257
258     public static String JavaDoc getWindowTitle() {
259         return getString("window.title");
260     }
261
262     public static String JavaDoc getWindowHeading() {
263         return getString("window.heading");
264     }
265
266     public static String JavaDoc getWindowLogo() {
267         return "resources/sunlogo.png";
268     }
269
270     public static String JavaDoc getWindowStep(int i) {
271         return getString("window.step." + i);
272     }
273
274     public static String JavaDoc 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 JavaDoc getWindowHiddenLabel() {
283         return getString("window.hiddenLabel");
284     }
285     
286     public static String JavaDoc getWindowStepProgress(int step, int percent) {
287     Object JavaDoc args[] = { getWindowStep(step), new Integer JavaDoc(percent) };
288         return applyPattern("window.step.progress", args);
289     }
290     
291     public static String JavaDoc getWindowStepWait(int step) {
292         Object JavaDoc args[] = { getWindowStep(step) };
293         return applyPattern("window.step.wait", args);
294     }
295     
296     /** Resource bundle stuff */
297     
298     // Returns a string from the resources
299
static private String JavaDoc getString(String JavaDoc key) {
300         try {
301         return _resources.getString(key);
302         } catch (MissingResourceException JavaDoc mre) {
303         return "Missing resource for: " + key;
304         }
305     }
306
307     static private int getMnemonic(String JavaDoc key) {
308         String JavaDoc resource = getString(key);
309         if (resource != null && resource.startsWith("VK_")) {
310             try {
311                 Class JavaDoc keyEventClazz= Class.forName("java.awt.event.KeyEvent");
312                 Field JavaDoc field = keyEventClazz.getDeclaredField(resource);
313                 int value = field.getInt(null);
314                 return value;
315             } catch (Exception JavaDoc e) {
316                 Config.trace("getMnemonic: " + e);
317             }
318         }
319         return 0;
320     }
321     
322     /** Helper function that applies the messageArguments to a message from the resource object */
323     static private String JavaDoc applyPattern(String JavaDoc key, Object JavaDoc[] messageArguments) {
324         String JavaDoc message = getString(key);
325         MessageFormat JavaDoc formatter = new MessageFormat JavaDoc(message);
326         String JavaDoc output = formatter.format(message, messageArguments);
327         return output;
328     }
329     
330     /** debugging method. No localized */
331     static public void trace(String JavaDoc msg) {
332     if (isVerbose()) {
333         System.out.println(msg);
334     }
335     }
336 }
337
338
339
Popular Tags