Last change
on this file since 10936 was 10936, checked in by Don-vip, 8 years ago |
sonar
|
-
Property svn:eol-style
set to
native
|
File size:
1.3 KB
|
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 |
|
---|
9 | import 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 | */
|
---|
18 | public 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 = System.getProperty("java.protocol.handler.pkgs", "");
|
---|
33 | if (!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.