1 /*
2 * Copyright (c) 2002-2025 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.protocol.data;
16
17 import java.io.UnsupportedEncodingException;
18 import java.net.URL;
19 import java.net.URLConnection;
20 import java.net.URLStreamHandler;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 /**
26 * Stream handler for data URLs.
27 *
28 * @author Marc Guillemot
29 */
30 public class Handler extends URLStreamHandler {
31
32 /** Logging support. */
33 private static final Log LOG = LogFactory.getLog(Handler.class);
34
35 /**
36 * Returns a new URLConnection for this URL.
37 * @param url the JavaScript URL
38 * @return the connection
39 */
40 @Override
41 protected URLConnection openConnection(final URL url) {
42 try {
43 return new DataURLConnection(url);
44 }
45 catch (final UnsupportedEncodingException e) {
46 if (LOG.isErrorEnabled()) {
47 LOG.error("Exception decoding " + url, e);
48 }
49 }
50 return null;
51 }
52 }