172
* Set the parser settings to use when the Launcher initiates parsing of
176
public void setParserSettings(ParserSettings settings) {
177
parserSettings = settings;
181
* Set a map to use when trying to extract extra information, including
182
* arguments, properties and parameters, to be merged into the main JNLP
183
* @param input a map containing extra information to add to the main JNLP.
184
* the values for keys "arguments", "parameters", and "properties" are
187
public void setInformationToMerge(Map<String, String[]> input) {
168
192
* Launches a JNLP file by calling the launch method for the
169
193
* appropriate file type. The application will be started in
248
274
* Launches a JNLP file by calling the launch method for the
275
* appropriate file type.
277
* @param location the URL of the JNLP file to launch
278
* @param fromSource if true, the JNLP file will be re-read from the source
279
* location to get the pristine version
280
* @throws LaunchException if there was an exception
281
* @return the application instance
283
public ApplicationInstance launch(URL location, boolean fromSource) throws LaunchException {
284
return launch(fromUrl(location, fromSource));
288
* Merges extra information into the jnlp file
290
* @param file the JNLPFile
291
* @param extra extra information to merge into the JNLP file
292
* @throws LaunchException if an exception occurs while extracting
295
private void mergeExtraInformation(JNLPFile file, Map<String, String[]> extra) throws LaunchException {
300
String[] properties = extra.get("properties");
301
if (properties != null) {
302
addProperties(file, properties);
305
String[] arguments = extra.get("arguments");
306
if (arguments != null && file.isApplication()) {
307
addArguments(file, arguments);
310
String[] parameters = extra.get("parameters");
311
if (parameters != null && file.isApplet()) {
312
addParameters(file, parameters);
317
* Add the properties to the JNLP file.
318
* @throws LaunchException if an exception occurs while extracting
321
private void addProperties(JNLPFile file, String[] props) throws LaunchException {
322
ResourcesDesc resources = file.getResources();
324
for (int i = 0; i < props.length; i++) {
325
// allows empty property, not sure about validity of that.
326
int equals = props[i].indexOf("=");
328
throw launchError(new LaunchException(R("BBadProp", props[i])));
331
String key = props[i].substring(0, equals);
332
String value = props[i].substring(equals + 1, props[i].length());
334
resources.addResource(new PropertyDesc(key, value));
339
* Add the params to the JNLP file; only call if file is
340
* actually an applet file.
341
* @throws LaunchException if an exception occurs while extracting
344
private void addParameters(JNLPFile file, String[] params) throws LaunchException {
345
AppletDesc applet = file.getApplet();
347
for (int i = 0; i < params.length; i++) {
348
// allows empty param, not sure about validity of that.
349
int equals = params[i].indexOf("=");
351
throw launchError(new LaunchException(R("BBadParam", params[i])));
354
String name = params[i].substring(0, equals);
355
String value = params[i].substring(equals + 1, params[i].length());
357
applet.addParameter(name, value);
362
* Add the arguments to the JNLP file; only call if file is
363
* actually an application (not installer).
365
private void addArguments(JNLPFile file, String[] args) {
366
ApplicationDesc app = file.getApplication();
368
for (int i = 0; i < args.length; i++) {
369
app.addArgument(args[i]);
374
* Launches a JNLP file by calling the launch method for the
249
375
* appropriate file type in a different thread.
251
377
* @param file the JNLP file to launch
346
472
* Returns the JNLPFile for the URL, with error handling.
474
private JNLPFile fromUrl(URL location, boolean fromSource) throws LaunchException {
476
JNLPFile file = null;
478
file = new JNLPFile(location, parserSettings.isStrict());
481
// Launches the jnlp file where this file originated.
482
if (file.getSourceLocation() != null) {
483
file = new JNLPFile(file.getSourceLocation(), parserSettings.isStrict());
487
} catch (Exception ex) {
488
if (ex instanceof LaunchException)
489
throw (LaunchException) ex; // already sent to handler when first thrown
492
throw launchError(new LaunchException(null, ex, R("LSFatal"), R("LCReadError"), R("LCantRead"), R("LCantReadInfo")));
497
* Returns the JNLPFile for the URL, with error handling.
348
500
private JNLPFile toFile(URL location) throws LaunchException {
350
502
JNLPFile file = null;
399
final int preferredWidth = 500;
400
final int preferredHeight = 400;
401
JNLPSplashScreen splashScreen = null;
402
URL splashImageURL = file.getInformation().getIconLocation(
403
IconDesc.SPLASH, preferredWidth, preferredHeight);
404
if (splashImageURL != null) {
405
ResourceTracker resourceTracker = new ResourceTracker(true);
406
resourceTracker.addResource(splashImageURL, file.getFileVersion(), null, updatePolicy);
407
splashScreen = new JNLPSplashScreen(resourceTracker, null, null);
408
splashScreen.setSplashImageURL(splashImageURL);
409
if (splashScreen.isSplashScreenValid()) {
410
splashScreen.setVisible(true);
551
handler.launchInitialized(file);
414
553
ApplicationInstance app = createApplication(file);
415
554
app.initialize();