import java.util.regex.Pattern;
import java.util.stream.Collectors;
-import org.apache.commons.lang3.StringEscapeUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.upnpcontrol.internal.util.StringUtils;
/**
*
* @return the URI for the album art.
*/
public String getAlbumArtUri() {
- return StringEscapeUtils.unescapeXml(albumArtUri);
+ return StringUtils.unEscapeXml(albumArtUri);
}
/**
--- /dev/null
+/**
+ * Copyright (c) 2010-2023 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.upnpcontrol.internal.util;
+
+/**
+ * The {@link StringUtils} class defines some static string utility methods
+ *
+ * @author Leo Siepel - Initial contribution
+ */
+public class StringUtils {
+
+ /**
+ * Simple method to escape XML special characters in String.
+ * There are five XML Special characters which needs to be escaped :
+ * & - &
+ * < - <
+ * > - >
+ * " - "
+ * ' - '
+ */
+ public static String escapeXml(String xml) {
+ xml = xml.replaceAll("&", "&");
+ xml = xml.replaceAll("<", "<");
+ xml = xml.replaceAll(">", ">");
+ xml = xml.replaceAll("\"", """);
+ xml = xml.replaceAll("'", "'");
+ return xml;
+ }
+
+ /**
+ * Simple method to un escape XML special characters in String.
+ * There are five XML Special characters which needs to be escaped :
+ * & - &
+ * < - <
+ * > - >
+ * " - "
+ * ' - '
+ */
+ public static String unEscapeXml(String xml) {
+ xml = xml.replaceAll("&", "&");
+ xml = xml.replaceAll("<", "<");
+ xml = xml.replaceAll(">", ">");
+ xml = xml.replaceAll(""", "\"");
+ xml = xml.replaceAll("'", "'");
+ return xml;
+ }
+}
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
-import org.apache.commons.lang3.StringEscapeUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.upnpcontrol.internal.queue.UpnpEntry;
public static String compileMetadataString(UpnpEntry entry) {
String id = entry.getId();
String parentId = entry.getParentId();
- String title = StringEscapeUtils.escapeXml(entry.getTitle());
+ String title = StringUtils.escapeXml(entry.getTitle());
String upnpClass = entry.getUpnpClass();
- String album = StringEscapeUtils.escapeXml(entry.getAlbum());
+ String album = StringUtils.escapeXml(entry.getAlbum());
String albumArtUri = entry.getAlbumArtUri();
- String creator = StringEscapeUtils.escapeXml(entry.getCreator());
- String artist = StringEscapeUtils.escapeXml(entry.getArtist());
- String publisher = StringEscapeUtils.escapeXml(entry.getPublisher());
- String genre = StringEscapeUtils.escapeXml(entry.getGenre());
+ String creator = StringUtils.escapeXml(entry.getCreator());
+ String artist = StringUtils.escapeXml(entry.getArtist());
+ String publisher = StringUtils.escapeXml(entry.getPublisher());
+ String genre = StringUtils.escapeXml(entry.getGenre());
Integer trackNumber = entry.getOriginalTrackNumber();
final MessageFormat messageFormat = new MessageFormat(METADATA_PATTERN);