Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[homematic] Remove dependency org.apache.commons.* from CcuGateway #10028

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.util.StringContentProvider;
Expand Down Expand Up @@ -123,7 +121,7 @@ protected void setChannelDatapointValues(HmChannel channel, HmParamsetType param
HmDevice device = channel.getDevice();
String channelName = String.format("%s.%s:%s.", device.getHmInterface().getName(), device.getAddress(),
channel.getNumber());
String datapointNames = StringUtils.join(dpNames.toArray(), "\\t");
String datapointNames = String.join("\\t", dpNames);
TclScriptDataList resultList = sendScriptByName("getAllChannelValues", TclScriptDataList.class,
new String[] { "channel_name", "datapoint_names" },
new String[] { channelName, datapointNames });
Expand Down Expand Up @@ -151,7 +149,10 @@ protected void addChannelDatapoints(HmChannel channel, HmParamsetType paramsetTy

@Override
protected void setVariable(HmDatapoint dp, Object value) throws IOException {
String strValue = StringUtils.replace(ObjectUtils.toString(value), "\"", "\\\"");
String strValue = "";
if (value != null) {
strValue = value.toString().replace("\"", "\\\"");
cpmeister marked this conversation as resolved.
Show resolved Hide resolved
}
if (dp.isStringType()) {
strValue = "\"" + strValue + "\"";
}
Expand Down Expand Up @@ -185,7 +186,9 @@ private <T> T sendScriptByName(String scriptName, Class<T> clazz, String[] varia
throws IOException {
String script = tclregaScripts.get(scriptName);
for (int i = 0; i < variableNames.length; i++) {
script = StringUtils.replace(script, "{" + variableNames[i] + "}", values[i]);
if (script != null) {
script = script.replace("{" + variableNames[i] + "}", values[i]);
}
}
return sendScript(script, clazz);
}
Expand All @@ -196,8 +199,8 @@ private <T> T sendScriptByName(String scriptName, Class<T> clazz, String[] varia
@SuppressWarnings("unchecked")
private synchronized <T> T sendScript(String script, Class<T> clazz) throws IOException {
try {
script = StringUtils.trim(script);
if (StringUtils.isEmpty(script)) {
script = script == null ? null : script.trim();
if (script == null || script.length() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (script == null || script.length() == 0) {
if (script == null || script.isEmpty()) {

throw new RuntimeException("Homematic TclRegaScript is empty!");
}
if (logger.isTraceEnabled()) {
Expand All @@ -210,7 +213,14 @@ private synchronized <T> T sendScript(String script, Class<T> clazz) throws IOEx
.header(HttpHeader.CONTENT_TYPE, "text/plain;charset=" + config.getEncoding()).send();

String result = new String(response.getContent(), config.getEncoding());
result = StringUtils.substringBeforeLast(result, "<xml><exec>");
if (result.length() != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (result.length() != 0) {
if (!result.isEmpty()) {

String separator = "<xml><exec>";
// Gets the substring before the last occurrence of the separator.
int pos = result.lastIndexOf(separator);
if (pos != -1) {
result = result.substring(0, pos);
}
}
if (logger.isTraceEnabled()) {
logger.trace("Result TclRegaScript: {}", result);
}
Expand All @@ -231,7 +241,10 @@ private Map<String, String> loadTclRegaScripts() throws IOException {
Map<String, String> result = new HashMap<>();
if (scriptList.getScripts() != null) {
for (TclScript script : scriptList.getScripts()) {
result.put(script.name, StringUtils.trimToNull(script.data));
// trim data to null (if it's empty)
String data = script.data == null ? null : script.data.trim();
data = (data == null || data.length() == 0) ? null : data;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data = (data == null || data.length() == 0) ? null : data;
data = (data == null || data.isEmpty()) ? null : data;

result.put(script.name, data);
}
}
return result;
Expand Down