mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
Introduce packet.Element
Re-work filetransfer/bytestream stanza toXML() method to use XmlStringBuilder. Move the ELEMENT and NAMESPACE definitions in the right place, ie. the stanza class.
This commit is contained in:
parent
f05b208120
commit
8526f8ab29
20 changed files with 203 additions and 199 deletions
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2014 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack.packet;
|
||||
|
||||
/**
|
||||
* Interface to represent a XML element. This is similar to {@link PacketExtension}, but does not
|
||||
* carry a namespace and is usually included as child element of an packet extension.
|
||||
*/
|
||||
public interface Element {
|
||||
|
||||
/**
|
||||
* Returns the root element name.
|
||||
*
|
||||
* @return the element name.
|
||||
*/
|
||||
public String getElementName();
|
||||
|
||||
/**
|
||||
* Returns the XML representation of the PacketExtension.
|
||||
*
|
||||
* @return the packet extension as XML.
|
||||
*/
|
||||
public CharSequence toXML();
|
||||
}
|
|
@ -40,6 +40,8 @@ import org.jivesoftware.smack.util.XmlStringBuilder;
|
|||
*/
|
||||
public abstract class IQ extends Packet {
|
||||
|
||||
public static final String QUERY_ELEMENT = "query";
|
||||
|
||||
private Type type = Type.get;
|
||||
|
||||
public IQ() {
|
||||
|
|
|
@ -28,14 +28,7 @@ package org.jivesoftware.smack.packet;
|
|||
* @see org.jivesoftware.smack.provider.PacketExtensionProvider
|
||||
* @author Matt Tucker
|
||||
*/
|
||||
public interface PacketExtension {
|
||||
|
||||
/**
|
||||
* Returns the root element name.
|
||||
*
|
||||
* @return the element name.
|
||||
*/
|
||||
public String getElementName();
|
||||
public interface PacketExtension extends Element {
|
||||
|
||||
/**
|
||||
* Returns the root element XML namespace.
|
||||
|
@ -44,10 +37,4 @@ public interface PacketExtension {
|
|||
*/
|
||||
public String getNamespace();
|
||||
|
||||
/**
|
||||
* Returns the XML representation of the PacketExtension.
|
||||
*
|
||||
* @return the packet extension as XML.
|
||||
*/
|
||||
public CharSequence toXML();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.util;
|
||||
|
||||
import org.jivesoftware.smack.packet.Element;
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
|
||||
public class XmlStringBuilder implements Appendable, CharSequence {
|
||||
|
@ -32,6 +33,11 @@ public class XmlStringBuilder implements Appendable, CharSequence {
|
|||
prelude(pe);
|
||||
}
|
||||
|
||||
public XmlStringBuilder(Element e) {
|
||||
this();
|
||||
halfOpenElement(e.getElementName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing if content is null.
|
||||
*
|
||||
|
@ -83,8 +89,8 @@ public class XmlStringBuilder implements Appendable, CharSequence {
|
|||
return this;
|
||||
}
|
||||
|
||||
public XmlStringBuilder closeElement(PacketExtension pe) {
|
||||
closeElement(pe.getElementName());
|
||||
public XmlStringBuilder closeElement(Element e) {
|
||||
closeElement(e.getElementName());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue