mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-12 14:01:08 +01:00
Rework XML Element hierarchy and XmlStringBuilder
- Reduce the amount of types that are subtypes of NamedElement. See javadoc of NamedElement for rationale. - Work more with XmlEnvironment in XmlStringBuilder. - Some minor changes to XmlStringBuilder API.
This commit is contained in:
parent
e9bcdf3e6d
commit
65576cf3c2
74 changed files with 653 additions and 523 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2014 Anno van Vliet
|
||||
* Copyright 2014 Anno van Vliet, 2019 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -20,7 +20,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
|
||||
/**
|
||||
|
|
@ -96,24 +95,14 @@ public class DataLayout implements ExtensionElement {
|
|||
buf.optAttribute("label", getLabel());
|
||||
buf.rightAngleBracket();
|
||||
|
||||
walkList(buf, getPageLayout());
|
||||
buf.append(getPageLayout());
|
||||
|
||||
buf.closeElement(this);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param buf TODO javadoc me please
|
||||
* @param pageLayout TODO javadoc me please
|
||||
*/
|
||||
private static void walkList(XmlStringBuilder buf, List<DataFormLayoutElement> pageLayout) {
|
||||
for (DataFormLayoutElement object : pageLayout) {
|
||||
buf.append(object.toXML());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Fieldref implements DataFormLayoutElement{
|
||||
public static class Fieldref extends DataFormLayoutElement{
|
||||
|
||||
public static final String ELEMENT = "fieldref";
|
||||
private final String var;
|
||||
|
|
@ -128,7 +117,7 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this);
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this, enclosingNamespace);
|
||||
buf.attribute("var", getVar());
|
||||
buf.closeEmptyElement();
|
||||
return buf;
|
||||
|
|
@ -150,7 +139,7 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
}
|
||||
|
||||
public static class Section implements DataFormLayoutElement{
|
||||
public static class Section extends DataFormLayoutElement{
|
||||
|
||||
public static final String ELEMENT = "section";
|
||||
private final List<DataFormLayoutElement> sectionLayout = new ArrayList<>();
|
||||
|
|
@ -188,11 +177,12 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this);
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this, enclosingNamespace);
|
||||
buf.optAttribute("label", getLabel());
|
||||
buf.rightAngleBracket();
|
||||
|
||||
walkList(buf, getSectionLayout());
|
||||
buf.append(getSectionLayout());
|
||||
|
||||
buf.closeElement(ELEMENT);
|
||||
return buf;
|
||||
}
|
||||
|
|
@ -213,13 +203,13 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
}
|
||||
|
||||
public static class Reportedref implements DataFormLayoutElement{
|
||||
public static class Reportedref extends DataFormLayoutElement{
|
||||
|
||||
public static final String ELEMENT = "reportedref";
|
||||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this);
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this, enclosingNamespace);
|
||||
buf.closeEmptyElement();
|
||||
return buf;
|
||||
}
|
||||
|
|
@ -231,7 +221,7 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
}
|
||||
|
||||
public static class Text implements DataFormLayoutElement{
|
||||
public static class Text extends DataFormLayoutElement{
|
||||
public static final String ELEMENT = "text";
|
||||
private final String text;
|
||||
|
||||
|
|
@ -245,8 +235,10 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
@Override
|
||||
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
||||
XmlStringBuilder buf = new XmlStringBuilder();
|
||||
buf.element(ELEMENT, getText());
|
||||
XmlStringBuilder buf = new XmlStringBuilder(this, enclosingNamespace);
|
||||
buf.rightAngleBracket();
|
||||
buf.escape(getText());
|
||||
buf.closeElement(this);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
@ -266,7 +258,11 @@ public class DataLayout implements ExtensionElement {
|
|||
|
||||
}
|
||||
|
||||
public interface DataFormLayoutElement extends NamedElement {
|
||||
public abstract static class DataFormLayoutElement implements ExtensionElement {
|
||||
@Override
|
||||
public final String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue