aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
authorGavriel Fleischer <flocsy@gmail.com>2019-11-09 23:50:29 +0200
committerGavriel Fleischer <flocsy@gmail.com>2019-11-09 23:50:29 +0200
commitfd6d1aa06ba983e17833b11393cfb344e5825fba (patch)
tree977fb2295160ff31c393c28bb822c91139ce8640 /src/main/java/org/traccar
parentbc4a46a01e8d7c3e6238ba07f96eb67adc75c116 (diff)
downloadtraccar-server-fd6d1aa06ba983e17833b11393cfb344e5825fba.tar.gz
traccar-server-fd6d1aa06ba983e17833b11393cfb344e5825fba.tar.bz2
traccar-server-fd6d1aa06ba983e17833b11393cfb344e5825fba.zip
replace missing command keys with empty string
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/StringProtocolEncoder.java8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/main/java/org/traccar/StringProtocolEncoder.java b/src/main/java/org/traccar/StringProtocolEncoder.java
index d9acce7f0..7041a31ab 100644
--- a/src/main/java/org/traccar/StringProtocolEncoder.java
+++ b/src/main/java/org/traccar/StringProtocolEncoder.java
@@ -17,7 +17,10 @@ package org.traccar;
import org.traccar.model.Command;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
public abstract class StringProtocolEncoder extends BaseProtocolEncoder {
@@ -33,6 +36,7 @@ public abstract class StringProtocolEncoder extends BaseProtocolEncoder {
String result = String.format(format, (Object[]) keys);
+ Set<String> missingKeys = new HashSet<>(Arrays.asList(keys));
result = result.replaceAll("\\{" + Command.KEY_UNIQUE_ID + "}", getUniqueId(command.getDeviceId()));
for (Map.Entry<String, Object> entry : command.getAttributes().entrySet()) {
String value = null;
@@ -43,6 +47,10 @@ public abstract class StringProtocolEncoder extends BaseProtocolEncoder {
value = entry.getValue().toString();
}
result = result.replaceAll("\\{" + entry.getKey() + "}", value);
+ missingKeys.remove(entry.getKey());
+ }
+ for (String key : missingKeys) {
+ result = result.replaceAll("\\{" + key + "}", "");
}
return result;