[Homematic] Removed Apache Commons (#10035)
Signed-off-by: Martin Herbst <develop@mherbst.de>pull/10115/head
parent
a58676dc41
commit
ac02141d0b
|
@ -12,8 +12,6 @@
|
|||
*/
|
||||
package org.openhab.binding.homematic.internal.common;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
import org.openhab.binding.homematic.internal.model.HmGatewayInfo;
|
||||
import org.openhab.binding.homematic.internal.model.HmInterface;
|
||||
|
@ -405,14 +403,12 @@ public class HomematicConfig {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
ToStringBuilder tsb = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
|
||||
tsb.append("gatewayAddress", gatewayAddress).append("callbackHost", callbackHost)
|
||||
.append("bindAddress", bindAddress).append("xmlCallbackPort", xmlCallbackPort)
|
||||
.append("binCallbackPort", binCallbackPort).append("gatewayType", gatewayType)
|
||||
.append("rfPort", getRfPort()).append("wiredPort", getWiredPort()).append("hmIpPort", getHmIpPort())
|
||||
.append("cuxdPort", getCuxdPort()).append("groupPort", getGroupPort()).append("timeout", timeout)
|
||||
.append("discoveryTimeToLive", discoveryTimeToLive).append("installModeDuration", installModeDuration)
|
||||
.append("socketMaxAlive", socketMaxAlive);
|
||||
return tsb.toString();
|
||||
return String.format(
|
||||
"%s[gatewayAddress=%s,callbackHost=%s,bindAddress=%s,xmlCallbackPort=%d,binCallbackPort=%d,"
|
||||
+ "gatewayType=%s,rfPort=%d,wiredPort=%d,hmIpPort=%d,cuxdPort=%d,groupPort=%d,timeout=%d,"
|
||||
+ "discoveryTimeToLive=%d,installModeDuration=%d,socketMaxAlive=%d]",
|
||||
getClass().getSimpleName(), gatewayAddress, callbackHost, bindAddress, xmlCallbackPort, binCallbackPort,
|
||||
gatewayType, getRfPort(), getWiredPort(), getHmIpPort(), getCuxdPort(), getGroupPort(), timeout,
|
||||
discoveryTimeToLive, installModeDuration, socketMaxAlive);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.eclipse.jetty.client.HttpClient;
|
||||
import org.openhab.binding.homematic.internal.common.HomematicConfig;
|
||||
import org.openhab.binding.homematic.internal.communicator.client.BinRpcClient;
|
||||
|
@ -800,7 +799,7 @@ public abstract class AbstractHomematicGateway implements RpcEventListener, Home
|
|||
* Creates a virtual device for handling variables, scripts and other special gateway functions.
|
||||
*/
|
||||
private HmDevice createGatewayDevice() {
|
||||
String type = String.format("%s-%s", HmDevice.TYPE_GATEWAY_EXTRAS, StringUtils.upperCase(id));
|
||||
String type = String.format("%s-%s", HmDevice.TYPE_GATEWAY_EXTRAS, id.toUpperCase());
|
||||
HmDevice device = new HmDevice(HmDevice.ADDRESS_GATEWAY_EXTRAS, getDefaultInterface(), type,
|
||||
config.getGatewayInfo().getId(), null, null);
|
||||
device.setName(HmDevice.TYPE_GATEWAY_EXTRAS);
|
||||
|
|
|
@ -18,10 +18,9 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
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;
|
||||
|
@ -123,7 +122,7 @@ public class CcuGateway extends AbstractHomematicGateway {
|
|||
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 });
|
||||
|
@ -151,7 +150,7 @@ public class CcuGateway extends AbstractHomematicGateway {
|
|||
|
||||
@Override
|
||||
protected void setVariable(HmDatapoint dp, Object value) throws IOException {
|
||||
String strValue = StringUtils.replace(ObjectUtils.toString(value), "\"", "\\\"");
|
||||
String strValue = Objects.toString(value, "").replace("\"", "\\\"");
|
||||
if (dp.isStringType()) {
|
||||
strValue = "\"" + strValue + "\"";
|
||||
}
|
||||
|
@ -184,8 +183,10 @@ public class CcuGateway extends AbstractHomematicGateway {
|
|||
private <T> T sendScriptByName(String scriptName, Class<T> clazz, String[] variableNames, String[] values)
|
||||
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) {
|
||||
for (int i = 0; i < variableNames.length; i++) {
|
||||
script = script.replace("{" + variableNames[i] + "}", values[i]);
|
||||
}
|
||||
}
|
||||
return sendScript(script, clazz);
|
||||
}
|
||||
|
@ -196,8 +197,8 @@ public class CcuGateway extends AbstractHomematicGateway {
|
|||
@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.isEmpty()) {
|
||||
throw new RuntimeException("Homematic TclRegaScript is empty!");
|
||||
}
|
||||
if (logger.isTraceEnabled()) {
|
||||
|
@ -210,7 +211,10 @@ public class CcuGateway extends AbstractHomematicGateway {
|
|||
.header(HttpHeader.CONTENT_TYPE, "text/plain;charset=" + config.getEncoding()).send();
|
||||
|
||||
String result = new String(response.getContent(), config.getEncoding());
|
||||
result = StringUtils.substringBeforeLast(result, "<xml><exec>");
|
||||
int lastPos = result.lastIndexOf("<xml><exec>");
|
||||
if (lastPos != -1) {
|
||||
result = result.substring(0, lastPos);
|
||||
}
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Result TclRegaScript: {}", result);
|
||||
}
|
||||
|
@ -231,7 +235,8 @@ public class CcuGateway extends AbstractHomematicGateway {
|
|||
Map<String, String> result = new HashMap<>();
|
||||
if (scriptList.getScripts() != null) {
|
||||
for (TclScript script : scriptList.getScripts()) {
|
||||
result.put(script.name, StringUtils.trimToNull(script.data));
|
||||
String value = script.data.trim();
|
||||
result.put(script.name, value.isEmpty() ? null : value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -20,7 +20,6 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.homematic.internal.HomematicBindingConstants;
|
||||
import org.openhab.binding.homematic.internal.common.HomematicConfig;
|
||||
import org.openhab.binding.homematic.internal.communicator.message.RpcRequest;
|
||||
|
@ -34,6 +33,7 @@ import org.openhab.binding.homematic.internal.communicator.parser.HomegearLoadDe
|
|||
import org.openhab.binding.homematic.internal.communicator.parser.ListBidcosInterfacesParser;
|
||||
import org.openhab.binding.homematic.internal.communicator.parser.ListDevicesParser;
|
||||
import org.openhab.binding.homematic.internal.communicator.parser.RssiInfoParser;
|
||||
import org.openhab.binding.homematic.internal.misc.MiscUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapoint;
|
||||
import org.openhab.binding.homematic.internal.model.HmDevice;
|
||||
|
@ -233,7 +233,7 @@ public abstract class RpcClient<T> {
|
|||
|
||||
try {
|
||||
ddParser = getDeviceDescription(HmInterface.RF);
|
||||
isHomegear = StringUtils.equalsIgnoreCase(ddParser.getType(), "Homegear");
|
||||
isHomegear = "Homegear".equalsIgnoreCase(ddParser.getType());
|
||||
} catch (IOException ex) {
|
||||
// can't load gateway infos via RF interface
|
||||
ddParser = new GetDeviceDescriptionParser();
|
||||
|
@ -247,21 +247,23 @@ public abstract class RpcClient<T> {
|
|||
|
||||
HmGatewayInfo gatewayInfo = new HmGatewayInfo();
|
||||
gatewayInfo.setAddress(biParser.getGatewayAddress());
|
||||
String gwType = biParser.getType();
|
||||
if (isHomegear) {
|
||||
gatewayInfo.setId(HmGatewayInfo.ID_HOMEGEAR);
|
||||
gatewayInfo.setType(ddParser.getType());
|
||||
gatewayInfo.setFirmware(ddParser.getFirmware());
|
||||
} else if ((StringUtils.startsWithIgnoreCase(biParser.getType(), "CCU")
|
||||
|| StringUtils.startsWithIgnoreCase(biParser.getType(), "HMIP_CCU")
|
||||
|| StringUtils.startsWithIgnoreCase(ddParser.getType(), "HM-RCV-50") || config.isCCUType())
|
||||
} else if ((MiscUtils.strStartsWithIgnoreCase(gwType, "CCU")
|
||||
|| MiscUtils.strStartsWithIgnoreCase(gwType, "HMIP_CCU")
|
||||
|| MiscUtils.strStartsWithIgnoreCase(ddParser.getType(), "HM-RCV-50") || config.isCCUType())
|
||||
&& !config.isNoCCUType()) {
|
||||
gatewayInfo.setId(HmGatewayInfo.ID_CCU);
|
||||
String type = StringUtils.isBlank(biParser.getType()) ? "CCU" : biParser.getType();
|
||||
String type = gwType.isBlank() ? "CCU" : gwType;
|
||||
gatewayInfo.setType(type);
|
||||
gatewayInfo.setFirmware(ddParser.getFirmware() != null ? ddParser.getFirmware() : biParser.getFirmware());
|
||||
gatewayInfo
|
||||
.setFirmware(!ddParser.getFirmware().isEmpty() ? ddParser.getFirmware() : biParser.getFirmware());
|
||||
} else {
|
||||
gatewayInfo.setId(HmGatewayInfo.ID_DEFAULT);
|
||||
gatewayInfo.setType(biParser.getType());
|
||||
gatewayInfo.setType(gwType);
|
||||
gatewayInfo.setFirmware(biParser.getFirmware());
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -84,7 +83,7 @@ public class BinRpcMessage implements RpcRequest<byte[]>, RpcResponse {
|
|||
if (length != 4) {
|
||||
throw new EOFException("Only " + length + " bytes received reading message length");
|
||||
}
|
||||
int datasize = (new BigInteger(ArrayUtils.subarray(sig, 4, 8))).intValue();
|
||||
int datasize = (new BigInteger(Arrays.copyOfRange(sig, 4, 8))).intValue();
|
||||
byte payload[] = new byte[datasize];
|
||||
int offset = 0;
|
||||
int currentLength;
|
||||
|
@ -96,7 +95,10 @@ public class BinRpcMessage implements RpcRequest<byte[]>, RpcResponse {
|
|||
throw new EOFException("Only " + offset + " bytes received while reading message payload, expected "
|
||||
+ datasize + " bytes");
|
||||
}
|
||||
byte[] message = ArrayUtils.addAll(sig, payload);
|
||||
byte[] message = new byte[sig.length + payload.length];
|
||||
System.arraycopy(sig, 0, message, 0, sig.length);
|
||||
System.arraycopy(payload, 0, message, sig.length, payload.length);
|
||||
|
||||
decodeMessage(message, methodHeader);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
|
||||
/**
|
||||
* A XML-RPC request for sending data to the Homematic server.
|
||||
*
|
||||
|
@ -124,7 +122,7 @@ public class XmlRpcRequest implements RpcRequest<String> {
|
|||
} else {
|
||||
Class<?> clazz = value.getClass();
|
||||
if (clazz == String.class || clazz == Character.class) {
|
||||
sb.append(StringEscapeUtils.escapeXml(value.toString()));
|
||||
sb.append(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,4 +174,30 @@ 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("<");
|
||||
break;
|
||||
case '>':
|
||||
outValue.append(">");
|
||||
break;
|
||||
case '&':
|
||||
outValue.append("&");
|
||||
break;
|
||||
case '\'':
|
||||
outValue.append("&apost;");
|
||||
break;
|
||||
case '"':
|
||||
outValue.append(""");
|
||||
break;
|
||||
default:
|
||||
outValue.append(inValue.charAt(i));
|
||||
}
|
||||
}
|
||||
return outValue;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ package org.openhab.binding.homematic.internal.communicator.parser;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapoint;
|
||||
import org.openhab.binding.homematic.internal.model.HmInterface;
|
||||
|
@ -52,7 +51,7 @@ public class CcuParamsetDescriptionParser extends CommonRpcParser<TclScriptDataL
|
|||
}
|
||||
|
||||
private String[] toOptionList(String options) {
|
||||
String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(options, ";");
|
||||
String[] result = options == null ? null : options.split(";");
|
||||
return result == null || result.length == 0 ? null : result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ package org.openhab.binding.homematic.internal.communicator.parser;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapoint;
|
||||
import org.openhab.binding.homematic.internal.model.HmParamsetType;
|
||||
|
@ -57,8 +56,7 @@ public class CcuVariablesAndScriptsParser extends CommonRpcParser<TclScriptDataL
|
|||
}
|
||||
dp.setReadOnly(entry.readOnly);
|
||||
dp.setUnit(entry.unit);
|
||||
|
||||
String[] result = StringUtils.splitByWholeSeparatorPreserveAllTokens(entry.options, ";");
|
||||
String[] result = entry.options == null ? null : entry.options.split(";");
|
||||
dp.setOptions(result == null || result.length == 0 ? null : result);
|
||||
|
||||
if (dp.getOptions() != null) {
|
||||
|
|
|
@ -13,11 +13,9 @@
|
|||
package org.openhab.binding.homematic.internal.communicator.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.openhab.binding.homematic.internal.misc.MiscUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapoint;
|
||||
import org.openhab.binding.homematic.internal.model.HmParamsetType;
|
||||
|
@ -38,7 +36,8 @@ public abstract class CommonRpcParser<M, R> implements RpcParser<M, R> {
|
|||
* Converts the object to a string.
|
||||
*/
|
||||
protected String toString(Object object) {
|
||||
return StringUtils.trimToNull(ObjectUtils.toString(object));
|
||||
String value = Objects.toString(object, "").trim();
|
||||
return value.isEmpty() ? null : value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -49,7 +48,7 @@ public abstract class CommonRpcParser<M, R> implements RpcParser<M, R> {
|
|||
return (Integer) object;
|
||||
}
|
||||
try {
|
||||
return Double.valueOf(ObjectUtils.toString(object)).intValue();
|
||||
return Double.valueOf(object.toString()).intValue();
|
||||
} catch (NumberFormatException ex) {
|
||||
logger.debug("Failed converting {} to a Double", object, ex);
|
||||
return null;
|
||||
|
@ -64,7 +63,7 @@ public abstract class CommonRpcParser<M, R> implements RpcParser<M, R> {
|
|||
return (Double) object;
|
||||
}
|
||||
try {
|
||||
return Double.valueOf(ObjectUtils.toString(object));
|
||||
return Double.valueOf(object.toString());
|
||||
} catch (NumberFormatException ex) {
|
||||
logger.debug("Failed converting {} to a Double", object, ex);
|
||||
return null;
|
||||
|
@ -79,7 +78,12 @@ public abstract class CommonRpcParser<M, R> implements RpcParser<M, R> {
|
|||
return (Number) object;
|
||||
}
|
||||
try {
|
||||
return NumberUtils.createNumber(ObjectUtils.toString(object));
|
||||
String value = object.toString();
|
||||
if (value.contains(".")) {
|
||||
return Float.parseFloat(value);
|
||||
} else {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
logger.debug("Failed converting {} to a Number", object, ex);
|
||||
return null;
|
||||
|
@ -93,7 +97,7 @@ public abstract class CommonRpcParser<M, R> implements RpcParser<M, R> {
|
|||
if (object == null || object instanceof Boolean) {
|
||||
return (Boolean) object;
|
||||
}
|
||||
return BooleanUtils.toBoolean(ObjectUtils.toString(object));
|
||||
return "true".equals(object.toString().toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -114,9 +118,10 @@ public abstract class CommonRpcParser<M, R> implements RpcParser<M, R> {
|
|||
/**
|
||||
* Returns the address of a device, replacing group address identifier and illegal characters.
|
||||
*/
|
||||
@NonNull
|
||||
protected String getSanitizedAddress(Object object) {
|
||||
String address = StringUtils.trimToNull(StringUtils.replaceOnce(toString(object), "*", "T-"));
|
||||
return MiscUtils.validateCharacters(address, "Address", "_");
|
||||
String address = Objects.toString(object, "").trim().replaceFirst("\\*", "T-");
|
||||
return MiscUtils.validateCharacters(address.isEmpty() ? null : address, "Address", "_");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,8 +172,11 @@ public abstract class CommonRpcParser<M, R> implements RpcParser<M, R> {
|
|||
HmDatapoint dp = new HmDatapoint();
|
||||
dp.setName(name);
|
||||
dp.setDescription(name);
|
||||
dp.setUnit(StringUtils.replace(StringUtils.trimToNull(unit), "\ufffd", "°"));
|
||||
if (dp.getUnit() == null && StringUtils.startsWith(dp.getName(), "RSSI_")) {
|
||||
if (unit != null) {
|
||||
unit = unit.trim().replace("\ufffd", "°");
|
||||
}
|
||||
dp.setUnit(unit == null || unit.isEmpty() ? null : unit);
|
||||
if (dp.getUnit() == null && dp.getName() != null && dp.getName().startsWith("RSSI_")) {
|
||||
dp.setUnit("dBm");
|
||||
}
|
||||
|
||||
|
@ -210,7 +218,7 @@ public abstract class CommonRpcParser<M, R> implements RpcParser<M, R> {
|
|||
* Converts a string value to the type.
|
||||
*/
|
||||
protected Object convertToType(String value) {
|
||||
if (StringUtils.isBlank(value)) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("on")) {
|
||||
|
|
|
@ -16,7 +16,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.homematic.internal.misc.MiscUtils;
|
||||
|
||||
/**
|
||||
* Parses a delete device event received from a Homematic gateway.
|
||||
|
@ -31,12 +31,9 @@ public class DeleteDevicesParser extends CommonRpcParser<Object[], List<String>>
|
|||
Object[] data = (Object[]) message[1];
|
||||
for (int i = 0; i < message.length; i++) {
|
||||
String address = getSanitizedAddress(data[i]);
|
||||
boolean isDevice = !StringUtils.contains(address, ":")
|
||||
&& !StringUtils.startsWithIgnoreCase(address, "BidCos");
|
||||
if (isDevice) {
|
||||
if (MiscUtils.isDevice(address)) {
|
||||
adresses.add(address);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return adresses;
|
||||
|
|
|
@ -16,10 +16,9 @@ import static org.openhab.binding.homematic.internal.misc.HomematicConstants.*;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapoint;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapointInfo;
|
||||
|
@ -36,7 +35,7 @@ import org.slf4j.LoggerFactory;
|
|||
public class DisplayOptionsParser extends CommonRpcParser<Object, Void> {
|
||||
private final Logger logger = LoggerFactory.getLogger(DisplayOptionsParser.class);
|
||||
private static final String[] onOff = new String[] { "ON", "OFF" };
|
||||
|
||||
private static final int IDX_NOT_FOUND = -1;
|
||||
private HmChannel channel;
|
||||
private String text;
|
||||
private int beep = 0;
|
||||
|
@ -50,7 +49,8 @@ public class DisplayOptionsParser extends CommonRpcParser<Object, Void> {
|
|||
|
||||
@Override
|
||||
public Void parse(Object value) throws IOException {
|
||||
String optionsString = StringUtils.remove(toString(value), ' ');
|
||||
String valueString = toString(value);
|
||||
String optionsString = valueString == null ? null : valueString.replace(" ", "");
|
||||
if (optionsString != null) {
|
||||
int idxFirstSep = optionsString.indexOf(",");
|
||||
if (idxFirstSep == -1) {
|
||||
|
@ -61,7 +61,7 @@ public class DisplayOptionsParser extends CommonRpcParser<Object, Void> {
|
|||
optionsString = optionsString.substring(idxFirstSep + 1);
|
||||
}
|
||||
|
||||
String[] options = StringUtils.split(optionsString, ",");
|
||||
String[] options = optionsString.split(",");
|
||||
|
||||
String[] availableSymbols = getAvailableSymbols(channel);
|
||||
String[] availableBeepOptions = getAvailableOptions(channel, DATAPOINT_NAME_BEEP);
|
||||
|
@ -87,7 +87,7 @@ public class DisplayOptionsParser extends CommonRpcParser<Object, Void> {
|
|||
DATAPOINT_NAME_BACKLIGHT, deviceAddress);
|
||||
unit = getIntParameter(availableUnitOptions, unit, parameter, DATAPOINT_NAME_UNIT, deviceAddress);
|
||||
|
||||
if (ArrayUtils.contains(availableSymbols, parameter)) {
|
||||
if (findInArray(availableSymbols, parameter) != IDX_NOT_FOUND) {
|
||||
logger.debug("Symbol '{}' found for remote control '{}'", parameter, deviceAddress);
|
||||
symbols.add(parameter);
|
||||
}
|
||||
|
@ -102,8 +102,8 @@ public class DisplayOptionsParser extends CommonRpcParser<Object, Void> {
|
|||
*/
|
||||
private int getIntParameter(String[] options, int currentValue, String parameter, String parameterName,
|
||||
String deviceAddress) {
|
||||
int idx = ArrayUtils.indexOf(options, parameter);
|
||||
if (idx != -1) {
|
||||
int idx = findInArray(options, parameter);
|
||||
if (idx != IDX_NOT_FOUND) {
|
||||
if (currentValue == 0) {
|
||||
logger.debug("{} option '{}' found at index {} for remote control '{}'", parameterName, parameter,
|
||||
idx + 1, deviceAddress);
|
||||
|
@ -125,10 +125,12 @@ public class DisplayOptionsParser extends CommonRpcParser<Object, Void> {
|
|||
HmDatapointInfo dpInfo = HmDatapointInfo.createValuesInfo(channel, datapointName);
|
||||
HmDatapoint dp = channel.getDatapoint(dpInfo);
|
||||
if (dp != null) {
|
||||
String[] options = (String[]) ArrayUtils.remove(dp.getOptions(), 0);
|
||||
String[] dpOpts = dp.getOptions();
|
||||
String[] options = new String[dpOpts.length - 1];
|
||||
options = Arrays.copyOfRange(dpOpts, 1, dpOpts.length);
|
||||
for (String onOffString : onOff) {
|
||||
int onIdx = ArrayUtils.indexOf(options, onOffString);
|
||||
if (onIdx != -1) {
|
||||
int onIdx = findInArray(options, onOffString);
|
||||
if (onIdx != IDX_NOT_FOUND) {
|
||||
options[onIdx] = datapointName + "_" + onOffString;
|
||||
}
|
||||
}
|
||||
|
@ -137,6 +139,18 @@ public class DisplayOptionsParser extends CommonRpcParser<Object, Void> {
|
|||
return new String[0];
|
||||
}
|
||||
|
||||
private int findInArray(String[] arr, String searchString) {
|
||||
if (arr.length == 0) {
|
||||
return IDX_NOT_FOUND;
|
||||
}
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
if (arr[i].equals(searchString)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return IDX_NOT_FOUND;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all possible symbols from the remote control.
|
||||
*/
|
||||
|
|
|
@ -14,8 +14,6 @@ package org.openhab.binding.homematic.internal.communicator.parser;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapointInfo;
|
||||
import org.openhab.binding.homematic.internal.model.HmDevice;
|
||||
|
@ -38,10 +36,11 @@ public class EventParser extends CommonRpcParser<Object[], HmDatapointInfo> {
|
|||
address = HmDevice.ADDRESS_GATEWAY_EXTRAS;
|
||||
channel = HmChannel.CHANNEL_NUMBER_VARIABLE;
|
||||
} else {
|
||||
String[] configParts = StringUtils.trimToEmpty(addressWithChannel).split(":");
|
||||
String addrChannel = addressWithChannel == null ? "" : addressWithChannel.trim();
|
||||
String[] configParts = addrChannel.split(":");
|
||||
address = getSanitizedAddress(configParts[0]);
|
||||
if (configParts.length > 1) {
|
||||
channel = NumberUtils.createInteger(configParts[1]);
|
||||
channel = configParts[1] == null ? null : Integer.valueOf(configParts[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
package org.openhab.binding.homematic.internal.communicator.parser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapoint;
|
||||
import org.openhab.binding.homematic.internal.model.HmParamsetType;
|
||||
|
@ -36,7 +36,7 @@ public class GetAllScriptsParser extends CommonRpcParser<Object[], Void> {
|
|||
public Void parse(Object[] message) throws IOException {
|
||||
message = (Object[]) message[0];
|
||||
for (int i = 0; i < message.length; i++) {
|
||||
String scriptName = ObjectUtils.toString(message[i]);
|
||||
String scriptName = Objects.toString(message[i], "");
|
||||
HmDatapoint dpScript = new HmDatapoint(scriptName, scriptName, HmValueType.BOOL, Boolean.FALSE, false,
|
||||
HmParamsetType.VALUES);
|
||||
dpScript.setInfo(scriptName);
|
||||
|
|
|
@ -50,7 +50,7 @@ public class ListBidcosInterfacesParser extends CommonRpcParser<Object[], ListBi
|
|||
* Returns the parsed type.
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
return type == null ? "" : type;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,7 +19,6 @@ import java.util.Collection;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.homematic.internal.common.HomematicConfig;
|
||||
import org.openhab.binding.homematic.internal.misc.MiscUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
|
@ -48,9 +47,7 @@ public class ListDevicesParser extends CommonRpcParser<Object[], Collection<HmDe
|
|||
|
||||
for (int i = 0; i < message.length; i++) {
|
||||
Map<String, ?> data = (Map<String, ?>) message[i];
|
||||
boolean isDevice = !StringUtils.contains(toString(data.get("ADDRESS")), ":");
|
||||
|
||||
if (isDevice) {
|
||||
if (MiscUtils.isDevice(toString(data.get("ADDRESS")), true)) {
|
||||
String address = getSanitizedAddress(data.get("ADDRESS"));
|
||||
String type = MiscUtils.validateCharacters(toString(data.get("TYPE")), "Device type", "-");
|
||||
String id = toString(data.get("ID"));
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.homematic.internal.misc.MiscUtils;
|
||||
|
||||
/**
|
||||
* Parses a new device event received from a Homematic gateway.
|
||||
|
@ -35,9 +35,7 @@ public class NewDevicesParser extends CommonRpcParser<Object[], List<String>> {
|
|||
Map<String, ?> data = (Map<String, ?>) message[i];
|
||||
|
||||
String address = toString(data.get("ADDRESS"));
|
||||
boolean isDevice = !StringUtils.contains(address, ":")
|
||||
&& !StringUtils.startsWithIgnoreCase(address, "BidCos");
|
||||
if (isDevice) {
|
||||
if (MiscUtils.isDevice(address)) {
|
||||
adresses.add(getSanitizedAddress(address));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ package org.openhab.binding.homematic.internal.communicator.parser;
|
|||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.homematic.internal.communicator.client.UnknownParameterSetException;
|
||||
import org.openhab.binding.homematic.internal.communicator.client.UnknownRpcFailureException;
|
||||
import org.openhab.binding.homematic.internal.communicator.message.RpcRequest;
|
||||
|
@ -43,9 +42,9 @@ public class RpcResponseParser extends CommonRpcParser<Object[], Object[]> {
|
|||
Number faultCode = toNumber(map.get("faultCode"));
|
||||
String faultString = toString(map.get("faultString"));
|
||||
String faultMessage = String.format("%s %s (sending %s)", faultCode, faultString, request);
|
||||
if (faultCode.intValue() == -1 && StringUtils.equals("Failure", faultString)) {
|
||||
if (faultCode.intValue() == -1 && "Failure".equals(faultString)) {
|
||||
throw new UnknownRpcFailureException(faultMessage);
|
||||
} else if (faultCode.intValue() == -3 && StringUtils.equals("Unknown paramset", faultString)) {
|
||||
} else if (faultCode.intValue() == -3 && "Unknown paramset".equals(faultString)) {
|
||||
throw new UnknownParameterSetException(faultMessage);
|
||||
}
|
||||
throw new IOException(faultMessage);
|
||||
|
|
|
@ -18,8 +18,8 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.openhab.binding.homematic.internal.communicator.message.RpcRequest;
|
||||
import org.openhab.binding.homematic.internal.communicator.parser.DeleteDevicesParser;
|
||||
import org.openhab.binding.homematic.internal.communicator.parser.EventParser;
|
||||
|
@ -63,7 +63,7 @@ public abstract class RpcResponseHandler<T> {
|
|||
for (Object o : (Object[]) responseData[0]) {
|
||||
Map<?, ?> call = (Map<?, ?>) o;
|
||||
if (call != null) {
|
||||
String method = ObjectUtils.toString(call.get("methodName"));
|
||||
String method = Objects.toString(call.get("methodName"), "");
|
||||
Object[] data = (Object[]) call.get("params");
|
||||
handleMethodCall(method, data);
|
||||
}
|
||||
|
|
|
@ -14,13 +14,13 @@ package org.openhab.binding.homematic.internal.communicator.virtual;
|
|||
|
||||
import static org.openhab.binding.homematic.internal.misc.HomematicConstants.VIRTUAL_DATAPOINT_NAME_BUTTON;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.homematic.internal.misc.MiscUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapoint;
|
||||
import org.openhab.binding.homematic.internal.model.HmDevice;
|
||||
import org.openhab.binding.homematic.internal.model.HmValueType;
|
||||
import org.openhab.core.thing.CommonTriggerEvents;
|
||||
import org.openhab.core.thing.DefaultSystemChannelTypeProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -59,7 +59,8 @@ public class ButtonVirtualDatapointHandler extends AbstractVirtualDatapointHandl
|
|||
public void handleEvent(VirtualGateway gateway, HmDatapoint dp) {
|
||||
HmDatapoint vdp = getVirtualDatapoint(dp.getChannel());
|
||||
if (MiscUtils.isTrueValue(dp.getValue())) {
|
||||
String pressType = StringUtils.substringAfter(dp.getName(), "_");
|
||||
int usPos = dp.getName().indexOf("_");
|
||||
String pressType = usPos == -1 ? dp.getName() : dp.getName().substring(usPos + 1);
|
||||
switch (pressType) {
|
||||
case "SHORT":
|
||||
if (dp.getValue() == null || !dp.getValue().equals(dp.getPreviousValue())) {
|
||||
|
|
|
@ -16,7 +16,6 @@ import static org.openhab.binding.homematic.internal.misc.HomematicConstants.VIR
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.homematic.internal.misc.HomematicClientException;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapoint;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapointConfig;
|
||||
|
@ -61,7 +60,7 @@ public class DeleteDeviceModeVirtualDatapointHandler extends AbstractVirtualData
|
|||
public void handleCommand(VirtualGateway gateway, HmDatapoint dp, HmDatapointConfig dpConfig, Object value)
|
||||
throws IOException, HomematicClientException {
|
||||
dp.setValue(value);
|
||||
if (!StringUtils.equals(dp.getOptionValue(), MODE_LOCKED)) {
|
||||
if (!MODE_LOCKED.equals(dp.getOptionValue())) {
|
||||
gateway.disableDatapoint(dp, DELETE_MODE_DURATION);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import static org.openhab.binding.homematic.internal.misc.HomematicConstants.*;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.homematic.internal.communicator.parser.DisplayOptionsParser;
|
||||
import org.openhab.binding.homematic.internal.misc.HomematicClientException;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
|
@ -60,8 +59,9 @@ public class DisplayOptionsVirtualDatapointHandler extends AbstractVirtualDatapo
|
|||
DisplayOptionsParser rcOptionsParser = new DisplayOptionsParser(channel);
|
||||
rcOptionsParser.parse(value);
|
||||
|
||||
if (StringUtils.isNotBlank(rcOptionsParser.getText())) {
|
||||
sendDatapoint(gateway, channel, DATAPOINT_NAME_TEXT, rcOptionsParser.getText());
|
||||
String dpNameText = rcOptionsParser.getText();
|
||||
if (dpNameText != null && !dpNameText.isBlank()) {
|
||||
sendDatapoint(gateway, channel, DATAPOINT_NAME_TEXT, dpNameText);
|
||||
}
|
||||
|
||||
sendDatapoint(gateway, channel, DATAPOINT_NAME_BEEP, rcOptionsParser.getBeep());
|
||||
|
|
|
@ -21,9 +21,8 @@ import java.util.Arrays;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.openhab.binding.homematic.internal.misc.HomematicClientException;
|
||||
import org.openhab.binding.homematic.internal.misc.MiscUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
|
@ -328,9 +327,9 @@ public class DisplayTextVirtualDatapoint extends AbstractVirtualDatapointHandler
|
|||
}
|
||||
|
||||
for (int i = 1; i <= getLineCount(channel.getDevice()); i++) {
|
||||
String line = ObjectUtils.toString(
|
||||
channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_LINE + i).getValue());
|
||||
if (StringUtils.isEmpty(line)) {
|
||||
String line = Objects.toString(
|
||||
channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_LINE + i).getValue(), "");
|
||||
if (line.isEmpty()) {
|
||||
line = " ";
|
||||
}
|
||||
message.add(LINE);
|
||||
|
@ -340,12 +339,12 @@ public class DisplayTextVirtualDatapoint extends AbstractVirtualDatapointHandler
|
|||
.getOptionValue();
|
||||
message.add(COLOR);
|
||||
String colorCode = Color.getCode(color);
|
||||
message.add(StringUtils.isBlank(colorCode) ? Color.WHITE.getCode() : colorCode);
|
||||
message.add(colorCode == null || colorCode.isBlank() ? Color.WHITE.getCode() : colorCode);
|
||||
}
|
||||
String icon = channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_DISPLAY_ICON + i)
|
||||
.getOptionValue();
|
||||
String iconCode = Icon.getCode(icon);
|
||||
if (StringUtils.isNotBlank(iconCode)) {
|
||||
if (iconCode != null && !iconCode.isBlank()) {
|
||||
message.add(ICON);
|
||||
message.add(iconCode);
|
||||
}
|
||||
|
@ -374,7 +373,7 @@ public class DisplayTextVirtualDatapoint extends AbstractVirtualDatapointHandler
|
|||
message.add(STOP);
|
||||
|
||||
gateway.sendDatapoint(channel.getDatapoint(HmParamsetType.VALUES, DATAPOINT_NAME_SUBMIT),
|
||||
new HmDatapointConfig(), StringUtils.join(message, ","), null);
|
||||
new HmDatapointConfig(), String.join(",", message), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
*/
|
||||
package org.openhab.binding.homematic.internal.discovery.eq3udp;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* Extracts a UDP response from a Homematic CCU gateway.
|
||||
*
|
||||
|
@ -86,7 +83,7 @@ public class Eq3UdpResponse {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("deviceTypeId", deviceTypeId)
|
||||
.append("serialNumber", serialNumber).toString();
|
||||
return String.format("%s[deviceTypeId=%s,serialNumber=%s]", getClass().getSimpleName(), deviceTypeId,
|
||||
serialNumber);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,9 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.openhab.binding.homematic.internal.HomematicBindingConstants;
|
||||
import org.openhab.binding.homematic.internal.common.HomematicConfig;
|
||||
import org.openhab.binding.homematic.internal.communicator.HomematicGateway;
|
||||
|
@ -216,8 +214,8 @@ public class HomematicThingHandler extends BaseThingHandler {
|
|||
private static boolean containsChannel(List<Channel> channels, ChannelUID channelUID) {
|
||||
for (Channel channel : channels) {
|
||||
ChannelUID uid = channel.getUID();
|
||||
if (StringUtils.equals(channelUID.getGroupId(), uid.getGroupId())
|
||||
&& StringUtils.equals(channelUID.getId(), uid.getId())) {
|
||||
if (Objects.equals(channelUID.getGroupId(), uid.getGroupId())
|
||||
&& Objects.equals(channelUID.getId(), uid.getId())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -232,7 +230,7 @@ public class HomematicThingHandler extends BaseThingHandler {
|
|||
HmDatapoint dp = channelZero
|
||||
.getDatapoint(new HmDatapointInfo(HmParamsetType.VALUES, channelZero, datapointName));
|
||||
if (dp != null) {
|
||||
properties.put(propertyName, ObjectUtils.toString(dp.getValue()));
|
||||
properties.put(propertyName, Objects.toString(dp.getValue(), ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -375,7 +373,7 @@ public class HomematicThingHandler extends BaseThingHandler {
|
|||
throws IOException, GatewayNotAvailableException, ConverterException {
|
||||
if (dp.isTrigger()) {
|
||||
if (dp.getValue() != null) {
|
||||
triggerChannel(channel.getUID(), ObjectUtils.toString(dp.getValue()));
|
||||
triggerChannel(channel.getUID(), dp.getValue() == null ? "" : dp.getValue().toString());
|
||||
}
|
||||
} else if (isLinked(channel)) {
|
||||
loadHomematicChannelValues(dp.getChannel());
|
||||
|
@ -495,9 +493,10 @@ public class HomematicThingHandler extends BaseThingHandler {
|
|||
Object newValue = configurationParameter.getValue();
|
||||
|
||||
if (key.startsWith("HMP_")) {
|
||||
key = StringUtils.removeStart(key, "HMP_");
|
||||
Integer channelNumber = NumberUtils.toInt(StringUtils.substringBefore(key, "_"));
|
||||
String dpName = StringUtils.substringAfter(key, "_");
|
||||
key = key.substring(4);
|
||||
int sepPos = key.indexOf("_");
|
||||
Integer channelNumber = Integer.valueOf(key.substring(0, sepPos));
|
||||
String dpName = key.substring(sepPos + 1);
|
||||
|
||||
HmDatapointInfo dpInfo = new HmDatapointInfo(device.getAddress(), HmParamsetType.MASTER,
|
||||
channelNumber, dpName);
|
||||
|
@ -514,8 +513,7 @@ public class HomematicThingHandler extends BaseThingHandler {
|
|||
newValue = decimal.doubleValue();
|
||||
}
|
||||
}
|
||||
if (ObjectUtils.notEqual(dp.isEnumType() ? dp.getOptionValue() : dp.getValue(),
|
||||
newValue)) {
|
||||
if (!Objects.equals(dp.isEnumType() ? dp.getOptionValue() : dp.getValue(), newValue)) {
|
||||
sendDatapoint(dp, new HmDatapointConfig(), newValue);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,4 +50,62 @@ public class MiscUtils {
|
|||
public static boolean isFalseValue(Object value) {
|
||||
return value != null && value == Boolean.FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if str starts with search. Check is done case-insensitive.
|
||||
*/
|
||||
public static boolean strStartsWithIgnoreCase(String str, String search) {
|
||||
if (str == null || search == null || search.length() > str.length()) {
|
||||
return false;
|
||||
}
|
||||
return str.substring(0, search.length()).equalsIgnoreCase(search);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if address is a device
|
||||
*/
|
||||
public static boolean isDevice(String address) {
|
||||
return isDevice(address, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if address is a device. If allowBidCos ist true then addresses starting with "BidCos" classified as
|
||||
* devices, too.
|
||||
*/
|
||||
public static boolean isDevice(String address, boolean allowBidCos) {
|
||||
if (address == null) {
|
||||
return false;
|
||||
}
|
||||
if (address.contains(":")) {
|
||||
return false;
|
||||
}
|
||||
if (allowBidCos && strStartsWithIgnoreCase(address.trim(), "BidCos")) {
|
||||
return true;
|
||||
}
|
||||
return !strStartsWithIgnoreCase(address.trim(), "BidCos");
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes all characters after whitespace to upper-case and all other character to lower case.
|
||||
*/
|
||||
public static String capitalize(String value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
char[] chars = value.toCharArray();
|
||||
boolean capitalizeNextChar = true;
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
if (Character.isWhitespace(chars[i])) {
|
||||
capitalizeNextChar = true;
|
||||
} else {
|
||||
if (capitalizeNextChar) {
|
||||
chars[i] = Character.toTitleCase(chars[i]);
|
||||
capitalizeNextChar = false;
|
||||
} else {
|
||||
chars[i] = Character.toLowerCase(chars[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return new String(chars);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
import org.openhab.binding.homematic.internal.misc.HomematicConstants;
|
||||
|
||||
/**
|
||||
|
@ -216,7 +214,6 @@ public class HmChannel {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("number", number).append("type", type)
|
||||
.append("initialized", initialized).toString();
|
||||
return String.format("%s[number=%d,initialized=%b]", getClass().getSimpleName(), number, initialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
*/
|
||||
package org.openhab.binding.homematic.internal.model;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
import org.openhab.binding.homematic.internal.misc.MiscUtils;
|
||||
|
||||
/**
|
||||
|
@ -431,11 +428,10 @@ public class HmDatapoint implements Cloneable {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("name", name).append("value", value)
|
||||
.append("defaultValue", defaultValue).append("type", type).append("minValue", minValue)
|
||||
.append("maxValue", maxValue).append("step", step).append("options", StringUtils.join(options, ";"))
|
||||
.append("readOnly", readOnly).append("readable", readable).append("unit", unit)
|
||||
.append("description", description).append("info", info).append("paramsetType", paramsetType)
|
||||
.append("virtual", virtual).append("trigger", trigger).toString();
|
||||
return String.format("%s[name=%s,value=%s,defaultValue=%s,type=%s,minValue=%s,maxValue=%s,step=%s,options=%s,"
|
||||
+ "readOnly=%b,readable=%b,unit=%s,description=%s,info=%s,paramsetType=%s,virtual=%b,trigger=%b]",
|
||||
getClass().getSimpleName(), name, value, defaultValue, type, minValue, maxValue, step,
|
||||
(options == null ? null : String.join(";", options)), readOnly, readable, unit, description, info,
|
||||
paramsetType, virtual, trigger);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
*/
|
||||
package org.openhab.binding.homematic.internal.model;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* Configuration object for sending a datapoint.
|
||||
*
|
||||
|
@ -54,7 +51,6 @@ public class HmDatapointConfig {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("delay", delay)
|
||||
.append("receiveDelay", receiveDelay).toString();
|
||||
return String.format("%s[delay=%f,receiveDelay=%f]", getClass().getSimpleName(), delay, receiveDelay);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
*/
|
||||
package org.openhab.binding.homematic.internal.model;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Simple representation of a datapoint.
|
||||
|
@ -92,7 +91,7 @@ public class HmDatapointInfo {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder().append(address).append(paramsetType).append(channel).append(name).toHashCode();
|
||||
return Objects.hash(address, paramsetType, channel, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,8 +100,8 @@ public class HmDatapointInfo {
|
|||
return false;
|
||||
}
|
||||
HmDatapointInfo comp = (HmDatapointInfo) obj;
|
||||
return new EqualsBuilder().append(address, comp.getAddress()).append(paramsetType, comp.getParamsetType())
|
||||
.append(channel, comp.getChannel()).append(name, comp.getName()).isEquals();
|
||||
return Objects.equals(address, comp.getAddress()) && Objects.equals(paramsetType, comp.getParamsetType())
|
||||
&& Objects.equals(channel, comp.getChannel()) && Objects.equals(name, comp.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,11 +16,8 @@ import static org.openhab.binding.homematic.internal.misc.HomematicConstants.*;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
import org.openhab.binding.homematic.internal.misc.MiscUtils;
|
||||
|
||||
/**
|
||||
|
@ -202,7 +199,7 @@ public class HmDevice {
|
|||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder().append(address).toHashCode();
|
||||
return Objects.hash(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -211,13 +208,12 @@ public class HmDevice {
|
|||
return false;
|
||||
}
|
||||
HmDevice comp = (HmDevice) obj;
|
||||
return new EqualsBuilder().append(address, comp.getAddress()).isEquals();
|
||||
return Objects.equals(address, comp.getAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("hmInterface", hmInterface)
|
||||
.append("address", address).append("type", type).append("name", name).append("firmware", firmware)
|
||||
.append("gatewayId", gatewayId).toString();
|
||||
return String.format("%s[hmInterface=%s,address=%s,type=%s,name=%s,firmware=%s,gatewayId=%s]",
|
||||
getClass().getSimpleName(), hmInterface, address, type, name, firmware, gatewayId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
*/
|
||||
package org.openhab.binding.homematic.internal.model;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* Info object which holds gateway specific informations.
|
||||
*
|
||||
|
@ -184,9 +181,8 @@ public class HmGatewayInfo {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("id", id).append("type", type)
|
||||
.append("firmware", firmware).append("address", address).append("rf", rfInterface)
|
||||
.append("wired", wiredInterface).append("hmip", hmipInterface).append("cuxd", cuxdInterface)
|
||||
.append("group", groupInterface).toString();
|
||||
return String.format("%s[id=%s,type=%s,firmware=%s,address=%s,rf=%b,wired=%b,hmip=%b,cuxd=%b,group=%b]",
|
||||
getClass().getSimpleName(), id, type, firmware, address, rfInterface, wiredInterface, hmipInterface,
|
||||
cuxdInterface, groupInterface);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
*/
|
||||
package org.openhab.binding.homematic.internal.model;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
|
||||
/**
|
||||
* Object that holds the rssi infos for a RF device.
|
||||
*
|
||||
|
@ -65,7 +62,6 @@ public class HmRssiInfo {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).append("address", address)
|
||||
.append("device", device).append("peer", peer).toString();
|
||||
return String.format("%s[address=%s,device=%d,peer=%i]", getClass().getSimpleName(), address, device, peer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,11 +23,10 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.openhab.binding.homematic.internal.misc.MiscUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapoint;
|
||||
import org.openhab.binding.homematic.internal.model.HmDevice;
|
||||
|
@ -171,7 +170,7 @@ public class HomematicTypeGeneratorImpl implements HomematicTypeGenerator {
|
|||
ChannelGroupType groupType = channelGroupTypeProvider.getInternalChannelGroupType(groupTypeUID);
|
||||
if (groupType == null || device.isGatewayExtras()) {
|
||||
String groupLabel = String.format("%s",
|
||||
WordUtils.capitalizeFully(StringUtils.replace(channel.getType(), "_", " ")));
|
||||
MiscUtils.capitalize(channel.getType().replace("_", " ")));
|
||||
groupType = ChannelGroupTypeBuilder.instance(groupTypeUID, groupLabel)
|
||||
.withChannelDefinitions(channelDefinitions).build();
|
||||
channelGroupTypeProvider.addChannelGroupType(groupType);
|
||||
|
@ -195,7 +194,7 @@ public class HomematicTypeGeneratorImpl implements HomematicTypeGenerator {
|
|||
"Multiple firmware versions for device type '{}' found ({}). "
|
||||
+ "Make sure, all devices of the same type have the same firmware version, "
|
||||
+ "otherwise you MAY have channel and/or datapoint errors in the logfile",
|
||||
deviceType, StringUtils.join(firmwares, ", "));
|
||||
deviceType, String.join(", ", firmwares));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +203,7 @@ public class HomematicTypeGeneratorImpl implements HomematicTypeGenerator {
|
|||
* Adds the firmware version for validation.
|
||||
*/
|
||||
private void addFirmware(HmDevice device) {
|
||||
if (!StringUtils.equals(device.getFirmware(), "?") && !DEVICE_TYPE_VIRTUAL.equals(device.getType())
|
||||
if (!"?".equals(device.getFirmware()) && !DEVICE_TYPE_VIRTUAL.equals(device.getType())
|
||||
&& !DEVICE_TYPE_VIRTUAL_WIRED.equals(device.getType())) {
|
||||
Set<String> firmwares = firmwaresByType.get(device.getType());
|
||||
if (firmwares == null) {
|
||||
|
@ -237,7 +236,8 @@ public class HomematicTypeGeneratorImpl implements HomematicTypeGenerator {
|
|||
|
||||
List<ChannelGroupDefinition> groupDefinitions = new ArrayList<>();
|
||||
for (ChannelGroupType groupType : groupTypes) {
|
||||
String id = StringUtils.substringAfterLast(groupType.getUID().getId(), "_");
|
||||
int usPos = groupType.getUID().getId().lastIndexOf("_");
|
||||
String id = usPos == -1 ? groupType.getUID().getId() : groupType.getUID().getId().substring(usPos + 1);
|
||||
groupDefinitions.add(new ChannelGroupDefinition(id, groupType.getUID()));
|
||||
}
|
||||
|
||||
|
@ -337,7 +337,7 @@ public class HomematicTypeGeneratorImpl implements HomematicTypeGenerator {
|
|||
MetadataUtils.getParameterName(dp), MetadataUtils.getConfigDescriptionParameterType(dp));
|
||||
|
||||
builder.withLabel(MetadataUtils.getLabel(dp));
|
||||
builder.withDefault(ObjectUtils.toString(dp.getDefaultValue()));
|
||||
builder.withDefault(Objects.toString(dp.getDefaultValue(), ""));
|
||||
builder.withDescription(MetadataUtils.getDatapointDescription(dp));
|
||||
|
||||
if (dp.isEnumType()) {
|
||||
|
@ -383,6 +383,11 @@ public class HomematicTypeGeneratorImpl implements HomematicTypeGenerator {
|
|||
* Returns true, if the given datapoint can be ignored for metadata generation.
|
||||
*/
|
||||
public static boolean isIgnoredDatapoint(HmDatapoint dp) {
|
||||
return StringUtils.indexOfAny(dp.getName(), IGNORE_DATAPOINT_NAMES) != -1;
|
||||
for (String testValue : IGNORE_DATAPOINT_NAMES) {
|
||||
if (dp.getName().indexOf(testValue) > -1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -29,8 +30,7 @@ import java.util.Map;
|
|||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import org.openhab.binding.homematic.internal.misc.MiscUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapoint;
|
||||
import org.openhab.binding.homematic.internal.model.HmDevice;
|
||||
import org.openhab.core.config.core.ConfigDescriptionParameter.Type;
|
||||
|
@ -77,9 +77,16 @@ public class MetadataUtils {
|
|||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (StringUtils.trimToNull(line) != null && !StringUtils.startsWith(line, "#")) {
|
||||
String channelType = StringUtils.trimToNull(StringUtils.substringBefore(line, "|"));
|
||||
String datapointName = StringUtils.trimToNull(StringUtils.substringAfter(line, "|"));
|
||||
if (!line.trim().isEmpty() && !line.startsWith("#")) {
|
||||
String[] parts = line.split("\\|");
|
||||
String channelType = null;
|
||||
String datapointName = null;
|
||||
if (parts.length > 0) {
|
||||
channelType = parts[0].trim();
|
||||
if (parts.length > 1) {
|
||||
datapointName = parts[1].trim();
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> channelDatapoints = standardDatapoints.get(channelType);
|
||||
if (channelDatapoints == null) {
|
||||
|
@ -142,8 +149,7 @@ public class MetadataUtils {
|
|||
*/
|
||||
public static String getUnit(HmDatapoint dp) {
|
||||
if (dp.getUnit() != null) {
|
||||
String unit = StringUtils.replace(dp.getUnit(), "100%", "%");
|
||||
return StringUtils.replace(unit, "%", "%%");
|
||||
return dp.getUnit().replace("100%", "%").replace("%", "%%");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -182,7 +188,7 @@ public class MetadataUtils {
|
|||
* Returns the label string for the given Datapoint.
|
||||
*/
|
||||
public static String getLabel(HmDatapoint dp) {
|
||||
return WordUtils.capitalizeFully(StringUtils.replace(dp.getName(), "_", " "));
|
||||
return MiscUtils.capitalize(dp.getName().replace("_", " "));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -198,7 +204,7 @@ public class MetadataUtils {
|
|||
public static String getDescription(String... keys) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int startIdx = 0; startIdx < keys.length; startIdx++) {
|
||||
String key = StringUtils.join(keys, "|", startIdx, keys.length);
|
||||
String key = String.join("|", Arrays.copyOfRange(keys, startIdx, keys.length));
|
||||
if (key.endsWith("|")) {
|
||||
key = key.substring(0, key.length() - 1);
|
||||
}
|
||||
|
@ -209,7 +215,7 @@ public class MetadataUtils {
|
|||
sb.append(key).append(", ");
|
||||
}
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Description not found for: {}", StringUtils.substring(sb.toString(), 0, -2));
|
||||
logger.trace("Description not found for: {}", sb.toString().substring(0, sb.length() - 2));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -224,9 +230,8 @@ public class MetadataUtils {
|
|||
|
||||
String deviceDescription = null;
|
||||
boolean isTeam = device.getType().endsWith("-Team");
|
||||
String type = isTeam ? StringUtils.remove(device.getType(), "-Team") : device.getType();
|
||||
String type = isTeam ? device.getType().replace("-Team", "") : device.getType();
|
||||
deviceDescription = getDescription(type);
|
||||
|
||||
if (deviceDescription != null && isTeam) {
|
||||
deviceDescription += " Team";
|
||||
}
|
||||
|
@ -276,7 +281,10 @@ public class MetadataUtils {
|
|||
*/
|
||||
public static String getItemType(HmDatapoint dp) {
|
||||
String dpName = dp.getName();
|
||||
String channelType = StringUtils.defaultString(dp.getChannel().getType());
|
||||
String channelType = dp.getChannel().getType();
|
||||
if (channelType == null) {
|
||||
channelType = "";
|
||||
}
|
||||
|
||||
if (dp.isBooleanType()) {
|
||||
if (((dpName.equals(DATAPOINT_NAME_STATE) || dpName.equals(VIRTUAL_DATAPOINT_NAME_STATE_CONTACT))
|
||||
|
@ -359,7 +367,10 @@ public class MetadataUtils {
|
|||
*/
|
||||
public static String getCategory(HmDatapoint dp, String itemType) {
|
||||
String dpName = dp.getName();
|
||||
String channelType = StringUtils.defaultString(dp.getChannel().getType());
|
||||
String channelType = dp.getChannel().getType();
|
||||
if (channelType == null) {
|
||||
channelType = "";
|
||||
}
|
||||
|
||||
if (dpName.equals(DATAPOINT_NAME_BATTERY_TYPE) || dpName.equals(DATAPOINT_NAME_LOWBAT)
|
||||
|| dpName.equals(DATAPOINT_NAME_LOWBAT_IP)) {
|
||||
|
|
|
@ -14,7 +14,6 @@ package org.openhab.binding.homematic.internal.type;
|
|||
|
||||
import static org.openhab.binding.homematic.internal.HomematicBindingConstants.BINDING_ID;
|
||||
|
||||
import org.apache.commons.lang.math.NumberUtils;
|
||||
import org.openhab.binding.homematic.internal.model.HmChannel;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapoint;
|
||||
import org.openhab.binding.homematic.internal.model.HmDatapointInfo;
|
||||
|
@ -83,8 +82,15 @@ public class UidUtils {
|
|||
* Generates the HmDatapointInfo for the given thing and channelUID.
|
||||
*/
|
||||
public static HmDatapointInfo createHmDatapointInfo(ChannelUID channelUID) {
|
||||
return new HmDatapointInfo(channelUID.getThingUID().getId(), HmParamsetType.VALUES,
|
||||
NumberUtils.toInt(channelUID.getGroupId()), channelUID.getIdWithoutGroup());
|
||||
int value;
|
||||
try {
|
||||
String groupID = channelUID.getGroupId();
|
||||
value = groupID == null ? 0 : Integer.parseInt(groupID);
|
||||
} catch (NumberFormatException e) {
|
||||
value = 0;
|
||||
}
|
||||
return new HmDatapointInfo(channelUID.getThingUID().getId(), HmParamsetType.VALUES, value,
|
||||
channelUID.getIdWithoutGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,9 +25,6 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
/**
|
||||
* The CcuMetadataExtractor loads some JavaScript files from the CCU and generates the device and datapoint
|
||||
* descriptions into the file generated-descriptions.properties.
|
||||
|
@ -122,7 +119,7 @@ public class CcuMetadataExtractor {
|
|||
*/
|
||||
private Map<String, String> loadJsonLangDescriptionFile(String url, String lang) throws IOException {
|
||||
final Map<String, String> descriptions = new TreeMap<>();
|
||||
String descriptionUrl = StringUtils.replace(url, "{LANGUAGE}", lang);
|
||||
String descriptionUrl = url.replace("{LANGUAGE}", lang);
|
||||
|
||||
String startLine = " \"" + lang + "\" : {";
|
||||
String endLine = " },";
|
||||
|
@ -132,7 +129,7 @@ public class CcuMetadataExtractor {
|
|||
public void line(String line) {
|
||||
String[] entry = handleStringTable(line);
|
||||
if (entry != null) {
|
||||
descriptions.put(StringUtils.trim(entry[0]), unescape(StringUtils.trim(entry[1])));
|
||||
descriptions.put(entry[0].trim(), unescape(entry[1].trim()));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -150,20 +147,24 @@ public class CcuMetadataExtractor {
|
|||
@Override
|
||||
public void line(String line) {
|
||||
if (line.startsWith("elvST['")) {
|
||||
line = StringUtils.remove(line, "elvST['");
|
||||
line = StringUtils.replace(line, "'] = '", "=");
|
||||
line = StringUtils.remove(line, "';");
|
||||
line = StringUtils.remove(line, "$");
|
||||
line = StringUtils.remove(line, "{");
|
||||
line = StringUtils.remove(line, "}");
|
||||
line = line.replace("elvST['", "");
|
||||
line = line.replace("'] = '", "=");
|
||||
line = line.replace("';", "");
|
||||
line = line.replace("$", "");
|
||||
line = line.replace("{", "");
|
||||
line = line.replace("}", "");
|
||||
|
||||
int count = StringUtils.countMatches(line, "=");
|
||||
if (count > 1) {
|
||||
line = StringUtils.replace(line, "=", "|", 1);
|
||||
int count = 0;
|
||||
for (int i = 0; i < line.length(); i++) {
|
||||
if (line.charAt(i) == '=') {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
String[] split = StringUtils.split(line, "=", 2);
|
||||
deviceKeys.put(StringUtils.trim(split[0]), StringUtils.trim(split[1]));
|
||||
if (count > 1) {
|
||||
line = line.replaceFirst("=", "|");
|
||||
}
|
||||
String[] split = line.split("=", 2);
|
||||
deviceKeys.put(split[0].trim(), split[1].trim());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -174,11 +175,11 @@ public class CcuMetadataExtractor {
|
|||
* Splits a JSON JavaScript entry.
|
||||
*/
|
||||
private String[] handleStringTable(String line) {
|
||||
line = StringUtils.remove(line, " \"");
|
||||
line = StringUtils.remove(line, "\",");
|
||||
line = StringUtils.remove(line, "\"");
|
||||
line = line.replace(" \"", "");
|
||||
line = line.replace("\",", "");
|
||||
line = line.replace("\"", "");
|
||||
|
||||
String[] splitted = StringUtils.split(line, ":", 2);
|
||||
String[] splitted = line.split(":", 2);
|
||||
return splitted.length != 2 ? null : splitted;
|
||||
}
|
||||
|
||||
|
@ -186,16 +187,21 @@ public class CcuMetadataExtractor {
|
|||
* Transforms a string for a Java property file.
|
||||
*/
|
||||
private String unescape(String str) {
|
||||
str = StringUtils.replace(str, "%FC", "ü");
|
||||
str = StringUtils.replace(str, "%DC", "Ü");
|
||||
str = StringUtils.replace(str, "%E4", "ä");
|
||||
str = StringUtils.replace(str, "%C4", "Ä");
|
||||
str = StringUtils.replace(str, "%F6", "ö");
|
||||
str = StringUtils.replace(str, "%D6", "Ö");
|
||||
str = StringUtils.replace(str, "%DF", "ß");
|
||||
str = StringUtils.remove(str, " ");
|
||||
str = StringUtils.replace(str, "<br/>", " ");
|
||||
str = StringEscapeUtils.unescapeHtml(str);
|
||||
str = str.replace("%FC", "ü");
|
||||
str = str.replace("%DC", "Ü");
|
||||
str = str.replace("%E4", "ä");
|
||||
str = str.replace("%C4", "Ä");
|
||||
str = str.replace("%F6", "ö");
|
||||
str = str.replace("%D6", "Ö");
|
||||
str = str.replace("%DF", "ß");
|
||||
str = str.replace(" ", "");
|
||||
str = str.replace("<br/>", " ");
|
||||
str = str.replace("ü", "ü");
|
||||
str = str.replace("ä", "ä");
|
||||
str = str.replace("ö", "ö");
|
||||
str = str.replace("Ü", "Ü");
|
||||
str = str.replace("Ä", "Ä");
|
||||
str = str.replace("Ö", "Ö");
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -222,7 +228,7 @@ public class CcuMetadataExtractor {
|
|||
includeLine = false;
|
||||
}
|
||||
}
|
||||
if ((includeLine == null || includeLine) && StringUtils.isNotBlank(line)) {
|
||||
if ((includeLine == null || includeLine) && !line.isBlank()) {
|
||||
line(line);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue