]> git.basschouten.com Git - openhab-addons.git/blob
9cfd437c910fe5ad291b63f9507f928fa2c071b4
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.enigma2.internal;
14
15 import java.io.IOException;
16 import java.util.regex.Pattern;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.openhab.core.io.net.http.HttpUtil;
20
21 /**
22  * The {@link Enigma2HttpClient} class is responsible for sending HTTP-Get requests to the Enigma2 device.
23  * It is devided from {@link Enigma2Client} for better testing purpose.
24  *
25  * @author Guido Dolfen - Initial contribution
26  */
27 @NonNullByDefault
28 public class Enigma2HttpClient {
29     public static final Pattern PATTERN = Pattern
30             .compile("[^\\u0009\\u000A\\u000D\\u0020-\\uD7FF\\uE000-\\uFFFD\\u10000-\\u10FFF]+");
31     private final int timeout;
32
33     public Enigma2HttpClient(int timeout) {
34         this.timeout = timeout;
35     }
36
37     public String get(String url) throws IOException, IllegalArgumentException {
38         String xml = HttpUtil.executeUrl("GET", url, timeout * 1000);
39         // remove some unsupported xml-characters
40         return PATTERN.matcher(xml).replaceAll("");
41     }
42 }