mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-08 12:01:09 +01:00
Add Message.toString() providing a short description
This commit is contained in:
parent
98ec77caee
commit
86e11e69e8
8 changed files with 126 additions and 4 deletions
|
|
@ -112,6 +112,18 @@ public abstract class IQ extends Stanza {
|
|||
return childElementNamespace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("IQ Stanza (");
|
||||
sb.append(getChildElementName()).append(' ').append(getChildElementNamespace());
|
||||
sb.append(") [");
|
||||
logCommonAttributes(sb);
|
||||
sb.append("type=").append(type).append(',');
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final XmlStringBuilder toXML() {
|
||||
XmlStringBuilder buf = new XmlStringBuilder();
|
||||
|
|
|
|||
|
|
@ -418,6 +418,18 @@ public final class Message extends Stanza implements TypedCloneable<Message> {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Message Stanza [");
|
||||
logCommonAttributes(sb);
|
||||
if (type != null) {
|
||||
sb.append("type=").append(type).append(',');
|
||||
}
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML() {
|
||||
XmlStringBuilder buf = new XmlStringBuilder();
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import java.util.Locale;
|
|||
|
||||
import org.jivesoftware.smack.packet.id.StanzaIdUtil;
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
import org.jivesoftware.smack.util.StringUtils;
|
||||
import org.jivesoftware.smack.util.TypedCloneable;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
|
|
@ -222,6 +223,25 @@ public final class Presence extends Stanza implements TypedCloneable<Presence> {
|
|||
this.mode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Presence Stanza [");
|
||||
logCommonAttributes(sb);
|
||||
sb.append("type=").append(type).append(',');
|
||||
if (mode != null) {
|
||||
sb.append("mode=").append(mode).append(',');
|
||||
}
|
||||
if (!StringUtils.isNullOrEmpty(status)) {
|
||||
sb.append("status=").append(status).append(',');
|
||||
}
|
||||
if (priority != Integer.MIN_VALUE) {
|
||||
sb.append("prio=").append(priority).append(',');
|
||||
}
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML() {
|
||||
XmlStringBuilder buf = new XmlStringBuilder();
|
||||
|
|
|
|||
|
|
@ -458,11 +458,11 @@ public abstract class Stanza implements TopLevelStreamElement {
|
|||
return removeExtension(extension.getElementName(), extension.getNamespace());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a short String describing the Stanza. This method is suited for log purposes.
|
||||
*/
|
||||
@Override
|
||||
// NOTE When Smack is using Java 8, then this method should be moved in Element as "Default Method".
|
||||
public String toString() {
|
||||
return toXML().toString();
|
||||
}
|
||||
public abstract String toString();
|
||||
|
||||
/**
|
||||
* Returns the extension sub-packets (including properties data) as an XML
|
||||
|
|
@ -501,6 +501,18 @@ public abstract class Stanza implements TopLevelStreamElement {
|
|||
xml.xmllangAttribute(getLanguage());
|
||||
}
|
||||
|
||||
protected void logCommonAttributes(StringBuilder sb) {
|
||||
if (getTo() != null) {
|
||||
sb.append("to=").append(to).append(',');
|
||||
}
|
||||
if (getFrom() != null) {
|
||||
sb.append("from=").append(from).append(',');
|
||||
}
|
||||
if (hasStanzaIdSet()) {
|
||||
sb.append("id=").append(id).append(',');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append an XMPPError is this stanza(/packet) has one set.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue