]> git.basschouten.com Git - openhab-addons.git/blob
62b84607dc23176cd042360d08492ab41851d573
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.bosesoundtouch.internal.discovery;
14
15 import java.io.IOException;
16
17 import org.openhab.core.io.net.http.HttpUtil;
18
19 /**
20  * The {@link DiscoveryUtil} is a static helper class, to get infos from a XML
21  *
22  * @author Thomas Traunbauer - Initial contribution
23  */
24 public class DiscoveryUtil {
25
26     /**
27      * Finds the content in an element
28      *
29      * This is a quick and dirty method, it always delivers the first appearance of content in an element
30      */
31     public static String getContentOfFirstElement(String content, String element) {
32         if (content == null) {
33             return "";
34         }
35         String beginTag = "<" + element + ">";
36         String endTag = "</" + element + ">";
37
38         int startIndex = content.indexOf(beginTag) + beginTag.length();
39         int endIndex = content.indexOf(endTag);
40
41         if (startIndex != -1 && endIndex != -1) {
42             return content.substring(startIndex, endIndex);
43         } else {
44             return "";
45         }
46     }
47
48     /**
49      * Executes an URL and returns to answer
50      */
51     public static String executeUrl(String url) throws IOException {
52         return HttpUtil.executeUrl("GET", url, 5000);
53     }
54 }