]> git.basschouten.com Git - openhab-addons.git/commitdiff
[upnpcontrol] Remove org.apache.common (#14439)
authorlsiepel <leosiepel@gmail.com>
Sun, 19 Feb 2023 19:42:01 +0000 (20:42 +0100)
committerGitHub <noreply@github.com>
Sun, 19 Feb 2023 19:42:01 +0000 (20:42 +0100)
Signed-off-by: lsiepel <leosiepel@gmail.com>
bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/queue/UpnpEntry.java
bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/StringUtils.java [new file with mode: 0644]
bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/UpnpXMLParser.java

index e3ff96c273862c6c5980bc433851e1efb9914bff..2c25cd8a63be349784442cb0bcb81747a5d987b9 100644 (file)
@@ -18,9 +18,9 @@ import java.util.regex.Matcher;
 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;
 
 /**
  *
@@ -178,7 +178,7 @@ public class UpnpEntry {
      * @return the URI for the album art.
      */
     public String getAlbumArtUri() {
-        return StringEscapeUtils.unescapeXml(albumArtUri);
+        return StringUtils.unEscapeXml(albumArtUri);
     }
 
     /**
diff --git a/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/StringUtils.java b/bundles/org.openhab.binding.upnpcontrol/src/main/java/org/openhab/binding/upnpcontrol/internal/util/StringUtils.java
new file mode 100644 (file)
index 0000000..2ebb8b8
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+ * 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 :
+     * & - &amp;
+     * < - &lt;
+     * > - &gt;
+     * " - &quot;
+     * ' - &apos;
+     */
+    public static String escapeXml(String xml) {
+        xml = xml.replaceAll("&", "&amp;");
+        xml = xml.replaceAll("<", "&lt;");
+        xml = xml.replaceAll(">", "&gt;");
+        xml = xml.replaceAll("\"", "&quot;");
+        xml = xml.replaceAll("'", "&apos;");
+        return xml;
+    }
+
+    /**
+     * Simple method to un escape XML special characters in String.
+     * There are five XML Special characters which needs to be escaped :
+     * & - &amp;
+     * < - &lt;
+     * > - &gt;
+     * " - &quot;
+     * ' - &apos;
+     */
+    public static String unEscapeXml(String xml) {
+        xml = xml.replaceAll("&amp;", "&");
+        xml = xml.replaceAll("&lt;", "<");
+        xml = xml.replaceAll("&gt;", ">");
+        xml = xml.replaceAll("&quot;", "\"");
+        xml = xml.replaceAll("&apos;", "'");
+        return xml;
+    }
+}
index 27b86add791cc9b92dc8ae5f487603ca6de7aa8b..89983602f107e7444bede4318d56e429d9339a67 100644 (file)
@@ -25,7 +25,6 @@ import javax.xml.parsers.ParserConfigurationException;
 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;
@@ -406,14 +405,14 @@ public class UpnpXMLParser {
     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);