2 * Copyright (c) 2010-2021 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.openhab.core.io.net.http.HttpUtil;
20 * The {@link DiscoveryUtil} is a static helper class, to get infos from a XML
22 * @author Thomas Traunbauer - Initial contribution
24 public class DiscoveryUtil {
27 * Finds the content in an element
29 * This is a quick and dirty method, it always delivers the first appearance of content in an element
31 public static String getContentOfFirstElement(String content, String element) {
32 if (content == null) {
35 String beginTag = "<" + element + ">";
36 String endTag = "</" + element + ">";
38 int startIndex = content.indexOf(beginTag) + beginTag.length();
39 int endIndex = content.indexOf(endTag);
41 if (startIndex != -1 && endIndex != -1) {
42 return content.substring(startIndex, endIndex);
49 * Executes an URL and returns to answer
51 public static String executeUrl(String url) throws IOException {
52 return HttpUtil.executeUrl("GET", url, 5000);