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

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

see #16204 - fix unit test, checkstyle

  • Property svn:eol-style set to native
File size: 1.4 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;
8import java.util.Optional;
9
10import 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 */
19public 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.