minor code clean up for tag and element
This commit is contained in:
parent
5fc8ff899a
commit
6202cbe26b
|
@ -94,7 +94,7 @@ public class Element {
|
|||
}
|
||||
|
||||
public String findChildContent(String name, String xmlns) {
|
||||
Element element = findChild(name,xmlns);
|
||||
Element element = findChild(name, xmlns);
|
||||
return element == null ? null : element.getContent();
|
||||
}
|
||||
|
||||
|
@ -133,9 +133,8 @@ public class Element {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Element removeAttribute(String name) {
|
||||
public void removeAttribute(final String name) {
|
||||
this.attributes.remove(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Element setAttributes(Hashtable<String, String> attributes) {
|
||||
|
@ -171,21 +170,21 @@ public class Element {
|
|||
public String toString() {
|
||||
final StringBuilder elementOutput = new StringBuilder();
|
||||
if ((content == null) && (children.size() == 0)) {
|
||||
Tag emptyTag = Tag.empty(name);
|
||||
emptyTag.setAtttributes(this.attributes);
|
||||
elementOutput.append(emptyTag.toString());
|
||||
final Tag emptyTag = Tag.empty(name);
|
||||
emptyTag.setAttributes(this.attributes);
|
||||
elementOutput.append(emptyTag);
|
||||
} else {
|
||||
Tag startTag = Tag.start(name);
|
||||
startTag.setAtttributes(this.attributes);
|
||||
final Tag startTag = Tag.start(name);
|
||||
startTag.setAttributes(this.attributes);
|
||||
elementOutput.append(startTag);
|
||||
if (content != null) {
|
||||
elementOutput.append(XmlHelper.encodeEntities(content));
|
||||
} else {
|
||||
for (Element child : children) {
|
||||
for (final Element child : children) {
|
||||
elementOutput.append(child.toString());
|
||||
}
|
||||
}
|
||||
Tag endTag = Tag.end(name);
|
||||
final Tag endTag = Tag.end(name);
|
||||
elementOutput.append(endTag);
|
||||
}
|
||||
return elementOutput.toString();
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package eu.siacs.conversations.xml;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -42,29 +43,26 @@ public class Tag {
|
|||
return name;
|
||||
}
|
||||
|
||||
public String getAttribute(String attrName) {
|
||||
public String getAttribute(final String attrName) {
|
||||
return this.attributes.get(attrName);
|
||||
}
|
||||
|
||||
public Tag setAttribute(String attrName, String attrValue) {
|
||||
public Tag setAttribute(final String attrName, final String attrValue) {
|
||||
this.attributes.put(attrName, attrValue);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Tag setAtttributes(Hashtable<String, String> attributes) {
|
||||
public void setAttributes(final Hashtable<String, String> attributes) {
|
||||
this.attributes = attributes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isStart(String needle) {
|
||||
if (needle == null)
|
||||
return false;
|
||||
if (needle == null) return false;
|
||||
return (this.type == START) && (needle.equals(this.name));
|
||||
}
|
||||
|
||||
public boolean isEnd(String needle) {
|
||||
if (needle == null)
|
||||
return false;
|
||||
if (needle == null) return false;
|
||||
return (this.type == END) && (needle.equals(this.name));
|
||||
}
|
||||
|
||||
|
@ -72,18 +70,17 @@ public class Tag {
|
|||
return (this.type == NO);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String toString() {
|
||||
StringBuilder tagOutput = new StringBuilder();
|
||||
final StringBuilder tagOutput = new StringBuilder();
|
||||
tagOutput.append('<');
|
||||
if (type == END) {
|
||||
tagOutput.append('/');
|
||||
}
|
||||
tagOutput.append(name);
|
||||
if (type != END) {
|
||||
Set<Entry<String, String>> attributeSet = attributes.entrySet();
|
||||
Iterator<Entry<String, String>> it = attributeSet.iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<String, String> entry = it.next();
|
||||
final Set<Entry<String, String>> attributeSet = attributes.entrySet();
|
||||
for (final Entry<String, String> entry : attributeSet) {
|
||||
tagOutput.append(' ');
|
||||
tagOutput.append(entry.getKey());
|
||||
tagOutput.append("=\"");
|
||||
|
|
|
@ -498,6 +498,10 @@ public class XmppConnection implements Runnable {
|
|||
+ ")");
|
||||
account.setKey(
|
||||
Account.PINNED_MECHANISM_KEY, String.valueOf(saslMechanism.getPriority()));
|
||||
if (version == SaslMechanism.Version.SASL_2) {
|
||||
final String authorizationIdentifier = success.findChildContent("authorization-identifier");
|
||||
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": SASL 2.0 authorization identifier was "+authorizationIdentifier);
|
||||
}
|
||||
if (version == SaslMechanism.Version.SASL) {
|
||||
tagReader.reset();
|
||||
sendStartStream();
|
||||
|
@ -1179,7 +1183,7 @@ public class XmppConnection implements Runnable {
|
|||
Log.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure. (no jid)");
|
||||
}
|
||||
} else {
|
||||
Log.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure (" + packet.toString());
|
||||
Log.d(Config.LOGTAG, account.getJid() + ": disconnecting because of bind failure (" + packet);
|
||||
}
|
||||
final Element error = packet.findChild("error");
|
||||
if (packet.getType() == IqPacket.TYPE.ERROR && error != null && error.hasChild("conflict")) {
|
||||
|
@ -1449,7 +1453,7 @@ public class XmppConnection implements Runnable {
|
|||
features.carbonsEnabled = true;
|
||||
} else {
|
||||
Log.d(Config.LOGTAG, account.getJid().asBareJid()
|
||||
+ ": error enableing carbons " + packet.toString());
|
||||
+ ": could not enable carbons " + packet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -1472,7 +1476,7 @@ public class XmppConnection implements Runnable {
|
|||
failPendingMessages(text);
|
||||
throw new StateChangingException(Account.State.POLICY_VIOLATION);
|
||||
} else {
|
||||
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": stream error " + streamError.toString());
|
||||
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": stream error " + streamError);
|
||||
throw new StateChangingException(Account.State.STREAM_ERROR);
|
||||
}
|
||||
}
|
||||
|
@ -1839,8 +1843,8 @@ public class XmppConnection implements Runnable {
|
|||
Log.d(Config.LOGTAG, "getting certificate chain");
|
||||
try {
|
||||
return KeyChain.getCertificateChain(mXmppConnectionService, alias);
|
||||
} catch (Exception e) {
|
||||
Log.d(Config.LOGTAG, e.getMessage());
|
||||
} catch (final Exception e) {
|
||||
Log.d(Config.LOGTAG, "could not get certificate chain", e);
|
||||
return new X509Certificate[0];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue