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

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

fix #13513 - Registers a protocol handler for data: URLs allowing to display base64-inlined images in HTML help

  • Property svn:eol-style set to native
File size: 1.2 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 = System.getProperty("java.protocol.handler.pkgs", "");
33 if (!protocolHandlers.contains(pkg)) {
34 if (!protocolHandlers.isEmpty()) {
35 protocolHandlers += "|";
36 }
37 protocolHandlers += pkg;
38 Utils.updateSystemProperty("java.protocol.handler.pkgs", protocolHandlers);
39 }
40 }
41}
Note: See TracBrowser for help on using the repository browser.