mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +01:00
Remove duplicate code in XmlStringBuilder
This commit is contained in:
parent
85ef149c83
commit
935465a11b
1 changed files with 13 additions and 19 deletions
|
@ -591,21 +591,10 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
|
||||||
* @throws IOException if an I/O error occured.
|
* @throws IOException if an I/O error occured.
|
||||||
*/
|
*/
|
||||||
public void write(Writer writer, String enclosingNamespace) throws IOException {
|
public void write(Writer writer, String enclosingNamespace) throws IOException {
|
||||||
for (CharSequence csq : sb.getAsList()) {
|
XmlEnvironment enclosingXmlEnvironment = XmlEnvironment.builder()
|
||||||
if (csq instanceof XmlStringBuilder) {
|
.withNamespace(enclosingNamespace)
|
||||||
((XmlStringBuilder) csq).write(writer, enclosingNamespace);
|
.build();
|
||||||
}
|
appendXmlTo(writer, enclosingXmlEnvironment);
|
||||||
else if (csq instanceof XmlNsAttribute) {
|
|
||||||
XmlNsAttribute xmlNsAttribute = (XmlNsAttribute) csq;
|
|
||||||
if (!xmlNsAttribute.value.equals(enclosingNamespace)) {
|
|
||||||
writer.write(xmlNsAttribute.toString());
|
|
||||||
enclosingNamespace = xmlNsAttribute.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
writer.write(csq.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<CharSequence> getCharSequenceIterator() {
|
public Iterator<CharSequence> getCharSequenceIterator() {
|
||||||
|
@ -615,14 +604,19 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
|
||||||
@Override
|
@Override
|
||||||
public CharSequence toXML(XmlEnvironment enclosingXmlEnvironment) {
|
public CharSequence toXML(XmlEnvironment enclosingXmlEnvironment) {
|
||||||
StringBuilder res = new StringBuilder();
|
StringBuilder res = new StringBuilder();
|
||||||
appendXmlTo(res, enclosingXmlEnvironment);
|
try {
|
||||||
|
appendXmlTo(res, enclosingXmlEnvironment);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// Should never happen.
|
||||||
|
throw new AssertionError(e);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendXmlTo(StringBuilder res, XmlEnvironment enclosingXmlEnvironment) {
|
private void appendXmlTo(Appendable appendable, XmlEnvironment enclosingXmlEnvironment) throws IOException {
|
||||||
for (CharSequence csq : sb.getAsList()) {
|
for (CharSequence csq : sb.getAsList()) {
|
||||||
if (csq instanceof XmlStringBuilder) {
|
if (csq instanceof XmlStringBuilder) {
|
||||||
((XmlStringBuilder) csq).appendXmlTo(res, enclosingXmlEnvironment);
|
((XmlStringBuilder) csq).appendXmlTo(appendable, enclosingXmlEnvironment);
|
||||||
}
|
}
|
||||||
else if (csq instanceof XmlNsAttribute) {
|
else if (csq instanceof XmlNsAttribute) {
|
||||||
XmlNsAttribute xmlNsAttribute = (XmlNsAttribute) csq;
|
XmlNsAttribute xmlNsAttribute = (XmlNsAttribute) csq;
|
||||||
|
@ -632,7 +626,7 @@ public class XmlStringBuilder implements Appendable, CharSequence, Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.append(csq);
|
appendable.append(csq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue