source: josm/trunk/src/org/openstreetmap/josm/io/protocols/data/Handler.java@ 13647

Last change on this file since 13647 was 13647, checked in by Don-vip, 7 years ago

see #16204 - Allow to start and close JOSM in WebStart sandbox mode (where every external access is denied). This was very useful to reproduce some very tricky bugs that occured in real life but were almost impossible to diagnose.

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.protocols.data;
3
4import java.io.IOException;
5import java.net.URL;
6import java.net.URLConnection;
7import java.net.URLStreamHandler;
8
9import org.openstreetmap.josm.tools.Utils;
10
11/**
12 * Protocol handler for {@code data:} URLs.
13 * This class must be named "Handler" and in a package "data" (fixed named convention)!
14 * <p>
15 * See <a href="http://stackoverflow.com/a/9388757/2257172">StackOverflow</a>.
16 * @since 10931
17 */
18public class Handler extends URLStreamHandler {
19
20 @Override
21 protected URLConnection openConnection(URL u) throws IOException {
22 return new DataConnection(u);
23 }
24
25 /**
26 * Installs protocol handler.
27 */
28 public static void install() {
29 String pkgName = Handler.class.getPackage().getName();
30 String pkg = pkgName.substring(0, pkgName.lastIndexOf('.'));
31
32 String protocolHandlers = Utils.getSystemProperty("java.protocol.handler.pkgs");
33 if (protocolHandlers != null && !protocolHandlers.contains(pkg)) {
34 StringBuilder sb = new StringBuilder(protocolHandlers);
35 if (sb.length() > 0) {
36 sb.append('|');
37 }
38 sb.append(pkg);
39 Utils.updateSystemProperty("java.protocol.handler.pkgs", sb.toString());
40 }
41 }
42}
Note: See TracBrowser for help on using the repository browser.