2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bosesoundtouch.internal.discovery;
15 import java.io.IOException;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.core.io.net.http.HttpUtil;
21 * The {@link DiscoveryUtil} is a static helper class, to get infos from a XML
23 * @author Thomas Traunbauer - Initial contribution
26 public class DiscoveryUtil {
29 * Finds the content in an element
31 * This is a quick and dirty method, it always delivers the first appearance of content in an element
33 public static String getContentOfFirstElement(String content, String element) {
34 String beginTag = "<" + element + ">";
35 String endTag = "</" + element + ">";
37 int startIndex = content.indexOf(beginTag) + beginTag.length();
38 int endIndex = content.indexOf(endTag);
40 if (startIndex != -1 && endIndex != -1) {
41 String result = content.substring(startIndex, endIndex);
42 return result != null ? result : "";
49 * Executes an URL and returns to answer
51 public static String executeUrl(String url) throws IOException {
52 return HttpUtil.executeUrl("GET", url, 5000);