~ubuntu-branches/ubuntu/oneiric/icedtea-web/oneiric

« back to all changes in this revision

Viewing changes to netx/net/sourceforge/jnlp/Launcher.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2011-04-06 13:10:44 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20110406131044-6jky8obchc43cf02
Tags: 1.1~20110406-0ubuntu1
Fix typo in icedtea-netx postinst to install the javaws alternative.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import java.net.UnknownHostException;
28
28
import java.util.LinkedList;
29
29
import java.util.List;
 
30
import java.util.Map;
30
31
import java.util.jar.JarFile;
31
32
 
32
33
import net.sourceforge.jnlp.cache.CacheUtil;
76
77
    /** If the application should call System.exit on fatal errors */
77
78
    private boolean exitOnFailure = true;
78
79
 
 
80
    private ParserSettings parserSettings = new ParserSettings();
 
81
 
 
82
    private Map<String, String[]> extra = null;
79
83
 
80
84
    /**
81
85
     * Create a launcher with the runtime's default update policy
165
169
    }
166
170
 
167
171
    /**
 
172
     * Set the parser settings to use when the Launcher initiates parsing of
 
173
     * a JNLP file.
 
174
     * @param settings
 
175
     */
 
176
    public void setParserSettings(ParserSettings settings) {
 
177
        parserSettings = settings;
 
178
    }
 
179
 
 
180
    /**
 
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
 
185
     * used.
 
186
     */
 
187
    public void setInformationToMerge(Map<String, String[]> input) {
 
188
        this.extra = input;
 
189
    }
 
190
 
 
191
    /**
168
192
     * Launches a JNLP file by calling the launch method for the
169
193
     * appropriate file type.  The application will be started in
170
194
     * a new window.
189
213
    public ApplicationInstance launch(JNLPFile file, Container cont) throws LaunchException {
190
214
        TgThread tg;
191
215
 
 
216
        mergeExtraInformation(file, extra);
 
217
 
192
218
        JNLPRuntime.markNetxRunning();
193
219
 
194
220
        //First checks whether offline-allowed tag is specified inside the jnlp
246
272
 
247
273
    /**
248
274
     * Launches a JNLP file by calling the launch method for the
 
275
     * appropriate file type.
 
276
     *
 
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
 
282
     */
 
283
    public ApplicationInstance launch(URL location, boolean fromSource) throws LaunchException {
 
284
        return launch(fromUrl(location, fromSource));
 
285
    }
 
286
 
 
287
    /**
 
288
     * Merges extra information into the jnlp file
 
289
     *
 
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
 
293
     * extra information
 
294
     */
 
295
    private void mergeExtraInformation(JNLPFile file, Map<String, String[]> extra) throws LaunchException {
 
296
        if (extra == null) {
 
297
            return;
 
298
        }
 
299
 
 
300
        String[] properties = extra.get("properties");
 
301
        if (properties != null) {
 
302
            addProperties(file, properties);
 
303
        }
 
304
 
 
305
        String[] arguments = extra.get("arguments");
 
306
        if (arguments != null && file.isApplication()) {
 
307
            addArguments(file, arguments);
 
308
        }
 
309
 
 
310
        String[] parameters = extra.get("parameters");
 
311
        if (parameters != null && file.isApplet()) {
 
312
            addParameters(file, parameters);
 
313
        }
 
314
    }
 
315
 
 
316
    /**
 
317
     * Add the properties to the JNLP file.
 
318
     * @throws LaunchException if an exception occurs while extracting
 
319
     * extra information
 
320
     */
 
321
    private void addProperties(JNLPFile file, String[] props) throws LaunchException {
 
322
        ResourcesDesc resources = file.getResources();
 
323
 
 
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("=");
 
327
            if (equals == -1) {
 
328
                throw launchError(new LaunchException(R("BBadProp", props[i])));
 
329
            }
 
330
 
 
331
            String key = props[i].substring(0, equals);
 
332
            String value = props[i].substring(equals + 1, props[i].length());
 
333
 
 
334
            resources.addResource(new PropertyDesc(key, value));
 
335
        }
 
336
    }
 
337
 
 
338
    /**
 
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
 
342
     * extra information
 
343
     */
 
344
    private void addParameters(JNLPFile file, String[] params) throws LaunchException {
 
345
        AppletDesc applet = file.getApplet();
 
346
 
 
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("=");
 
350
            if (equals == -1) {
 
351
                throw launchError(new LaunchException(R("BBadParam", params[i])));
 
352
            }
 
353
 
 
354
            String name = params[i].substring(0, equals);
 
355
            String value = params[i].substring(equals + 1, params[i].length());
 
356
 
 
357
            applet.addParameter(name, value);
 
358
        }
 
359
    }
 
360
 
 
361
    /**
 
362
     * Add the arguments to the JNLP file; only call if file is
 
363
     * actually an application (not installer).
 
364
     */
 
365
    private void addArguments(JNLPFile file, String[] args) {
 
366
        ApplicationDesc app = file.getApplication();
 
367
 
 
368
        for (int i = 0; i < args.length; i++) {
 
369
            app.addArgument(args[i]);
 
370
        }
 
371
    }
 
372
 
 
373
    /**
 
374
     * Launches a JNLP file by calling the launch method for the
249
375
     * appropriate file type in a different thread.
250
376
     *
251
377
     * @param file the JNLP file to launch
345
471
    /**
346
472
     * Returns the JNLPFile for the URL, with error handling.
347
473
     */
 
474
    private JNLPFile fromUrl(URL location, boolean fromSource) throws LaunchException {
 
475
        try {
 
476
            JNLPFile file = null;
 
477
 
 
478
            file = new JNLPFile(location, parserSettings.isStrict());
 
479
 
 
480
            if (fromSource) {
 
481
                // Launches the jnlp file where this file originated.
 
482
                if (file.getSourceLocation() != null) {
 
483
                    file = new JNLPFile(file.getSourceLocation(), parserSettings.isStrict());
 
484
                }
 
485
            }
 
486
            return file;
 
487
        } catch (Exception ex) {
 
488
            if (ex instanceof LaunchException)
 
489
                throw (LaunchException) ex; // already sent to handler when first thrown
 
490
            else
 
491
                // IO and Parse
 
492
                throw launchError(new LaunchException(null, ex, R("LSFatal"), R("LCReadError"), R("LCantRead"), R("LCantReadInfo")));
 
493
        }
 
494
    }
 
495
 
 
496
    /**
 
497
     * Returns the JNLPFile for the URL, with error handling.
 
498
     */
 
499
    @Deprecated
348
500
    private JNLPFile toFile(URL location) throws LaunchException {
349
501
        try {
350
502
            JNLPFile file = null;
396
548
                return null;
397
549
            }
398
550
 
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);
411
 
                }
412
 
            }
 
551
            handler.launchInitialized(file);
413
552
 
414
553
            ApplicationInstance app = createApplication(file);
415
554
            app.initialize();
446
585
 
447
586
            setContextClassLoaderForAllThreads(app.getThreadGroup(), app.getClassLoader());
448
587
 
449
 
            if (splashScreen != null) {
450
 
                if (splashScreen.isSplashScreenValid()) {
451
 
                    splashScreen.setVisible(false);
452
 
                }
453
 
                splashScreen.dispose();
454
 
            }
 
588
            handler.launchStarting(app);
455
589
 
456
590
            main.setAccessible(true);
457
591
            main.invoke(null, new Object[] { args });
563
697
        try {
564
698
            JNLPClassLoader loader = JNLPClassLoader.getInstance(file, updatePolicy);
565
699
 
566
 
            if (enableCodeBase || file.getResources().getJARs().length == 0)
 
700
            if (enableCodeBase) {
567
701
                loader.enableCodeBase();
 
702
            } else if (file.getResources().getJARs().length == 0) {
 
703
                throw new ClassNotFoundException("Can't do a codebase look up and there are no jars. Failing sooner rather than later");
 
704
            }
568
705
 
569
706
            AppThreadGroup group = (AppThreadGroup) Thread.currentThread().getThreadGroup();
570
707
 
603
740
        try {
604
741
            JNLPClassLoader loader = JNLPClassLoader.getInstance(file, updatePolicy);
605
742
 
606
 
            if (enableCodeBase || file.getResources().getJARs().length == 0)
 
743
            if (enableCodeBase) {
607
744
                loader.enableCodeBase();
 
745
            } else if (file.getResources().getJARs().length == 0) {
 
746
                throw new ClassNotFoundException("Can't do a codebase look up and there are no jars. Failing sooner rather than later");
 
747
            }
608
748
 
609
749
            String appletName = file.getApplet().getMainClass();
610
750
 
742
882
                if (isPlugin) {
743
883
                    // Do not display download indicators if we're using gcjwebplugin.
744
884
                    JNLPRuntime.setDefaultDownloadIndicator(null);
745
 
                    application = getApplet(file, true, cont);
 
885
                    application = getApplet(file, ((PluginBridge)file).codeBaseLookup(), cont);
746
886
                } else {
747
887
                    if (file.isApplication())
748
888
                        application = launchApplication(file);