adapt to core StringUtils (#15770)

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel 2023-10-19 21:48:09 +02:00 committed by GitHub
parent e798ba9406
commit b8805ba687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.openhab.core.util.StringUtils;
/**
* A XML-RPC request for sending data to the Homematic server.
*
@ -122,7 +124,7 @@ public class XmlRpcRequest implements RpcRequest<String> {
} else {
Class<?> clazz = value.getClass();
if (clazz == String.class || clazz == Character.class) {
sb.append(escapeXml(value.toString()));
sb.append(StringUtils.escapeXml(value.toString()));
} else if (clazz == Long.class || clazz == Integer.class || clazz == Short.class || clazz == Byte.class) {
tag("int", value.toString());
} else if (clazz == Double.class) {
@ -176,30 +178,4 @@ public class XmlRpcRequest implements RpcRequest<String> {
}
}
}
private StringBuilder escapeXml(String inValue) {
StringBuilder outValue = new StringBuilder(inValue.length());
for (int i = 0; i < inValue.length(); i++) {
switch (inValue.charAt(i)) {
case '<':
outValue.append("&lt;");
break;
case '>':
outValue.append("&gt;");
break;
case '&':
outValue.append("&amp;");
break;
case '\'':
outValue.append("&apost;");
break;
case '"':
outValue.append("&quot;");
break;
default:
outValue.append(inValue.charAt(i));
}
}
return outValue;
}
}