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