Skip to content

Commit

Permalink
Fixed forced encoding when exporting to clipboard. #31
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilfb committed Aug 6, 2017
1 parent 06299b5 commit 7474303
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,24 @@

public class MqttMessageAuditUtils implements MessageAuditUtils
{
public String getCurrentMessageAsMessageLog(final BasicMessageStoreWithSummary<? extends FormattedMessage> store, final int messageIndex)
public String getCurrentMessageAsMessageLog(final BasicMessageStoreWithSummary<? extends FormattedMessage> store, final int messageIndex, final boolean encode)
{
final FormattedMessage message = store.getMessages().get(messageIndex);
final MessageLogEnum format = encode ? MessageLogEnum.XML_WITH_ENCODED_PAYLOAD : MessageLogEnum.XML_WITH_PLAIN_PAYLOAD;

if (message instanceof FormattedMqttMessage)
{
return SimpleMqttMessageLogComposer.createReceivedMessageLog((FormattedMqttMessage) message,
new MessageLog(MessageLogEnum.XML_WITH_PLAIN_PAYLOAD, "", true, true, false, false, false));
new MessageLog(format, "", true, true, false, false, false));
}

return null;
}

public String getAllMessagesAsMessageLog(final BasicMessageStoreWithSummary<? extends FormattedMessage> store)
public String getAllMessagesAsMessageLog(final BasicMessageStoreWithSummary<? extends FormattedMessage> store, final boolean encode)
{
final StringBuffer messagesAsString = new StringBuffer();
final MessageLogEnum format = encode ? MessageLogEnum.XML_WITH_ENCODED_PAYLOAD : MessageLogEnum.XML_WITH_PLAIN_PAYLOAD;

final List<? extends FormattedMessage> messages = store.getMessages();
for (int i = messages.size() - 1; i >= 0; i--)
Expand All @@ -57,7 +59,7 @@ public String getAllMessagesAsMessageLog(final BasicMessageStoreWithSummary<? ex
final FormattedMqttMessage message = (FormattedMqttMessage) messages.get(i);

messagesAsString.append(SimpleMqttMessageLogComposer.createReceivedMessageLog(message,
new MessageLog(MessageLogEnum.XML_WITH_ENCODED_PAYLOAD, "", true, true, false, false, false)));
new MessageLog(format, "", true, true, false, false, false)));
}
messagesAsString.append(System.lineSeparator());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,13 @@ public void copyMessageToClipboard()
{
if (getSelectedMessageIndex() > 0)
{
UiUtils.copyToClipboard(messageAuditUtils.getCurrentMessageAsMessageLog(store, getSelectedMessageIndex() - 1));
UiUtils.copyToClipboard(messageAuditUtils.getCurrentMessageAsMessageLog(store, getSelectedMessageIndex() - 1, false));
}
}

public void copyMessagesToClipboard()
{
UiUtils.copyToClipboard(messageAuditUtils.getAllMessagesAsMessageLog(store));
UiUtils.copyToClipboard(messageAuditUtils.getAllMessagesAsMessageLog(store, false));
}


Expand All @@ -518,7 +518,7 @@ public void copyMessageToFile()

if (selectedFile != null)
{
FileUtils.writeToFile(selectedFile, messageAuditUtils.getCurrentMessageAsMessageLog(store, getSelectedMessageIndex() - 1));
FileUtils.writeToFile(selectedFile, messageAuditUtils.getCurrentMessageAsMessageLog(store, getSelectedMessageIndex() - 1, true));
}
}
}
Expand Down Expand Up @@ -552,7 +552,7 @@ public void copyMessagesToFile()

if (selectedFile != null)
{
FileUtils.writeToFile(selectedFile, messageAuditUtils.getAllMessagesAsMessageLog(store));
FileUtils.writeToFile(selectedFile, messageAuditUtils.getAllMessagesAsMessageLog(store, true));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public interface MessageAuditUtils
{
String getCurrentMessageAsMessageLog(final BasicMessageStoreWithSummary<? extends FormattedMessage> store, final int messageIndex);
String getCurrentMessageAsMessageLog(final BasicMessageStoreWithSummary<? extends FormattedMessage> store, final int messageIndex, final boolean encode);

String getAllMessagesAsMessageLog(final BasicMessageStoreWithSummary<? extends FormattedMessage> store);
String getAllMessagesAsMessageLog(final BasicMessageStoreWithSummary<? extends FormattedMessage> store, final boolean encode);
}

0 comments on commit 7474303

Please sign in to comment.