import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.apache.commons.lang3.StringEscapeUtils;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
+import org.openhab.binding.sonos.internal.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.Attributes;
upnpClass = resourceMetaData.getUpnpClass();
}
- title = StringEscapeUtils.escapeXml(title);
+ title = StringUtils.escapeXml(title);
String metadata = METADATA_FORMAT.format(new Object[] { id, parentId, title, upnpClass, desc });
*/
package org.openhab.binding.sonos.internal.util;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
/**
* The {@link StringUtils} class defines some static string utility methods
*
* @author Leo Siepel - Initial contribution
*/
+@NonNullByDefault
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 :