public abstract class Stanza extends java.lang.Object implements StanzaView, TopLevelStreamElement
Every stanza has a unique ID (which is automatically generated, but can be overridden). Stanza IDs are required for IQ stanzas and recommended for presence and message stanzas. Optionally, the "to" and "from" fields can be set.
XMPP Stanzas are Message, IQ and Presence. Which therefore subclass this
class. If you think you need to subclass this class, then you are doing something wrong.
Use StanzaBuilder to construct a stanza instance. All instance mutating methods of this
class are deprecated, although not all of them are currently marked as such, and must not be used.
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.String |
DEFAULT_LANGUAGE |
static java.lang.String |
ITEM |
protected java.lang.String |
language
Optional value of the 'xml:lang' attribute of the outermost element of
the stanza.
|
static java.lang.String |
TEXT |
| Modifier | Constructor and Description |
|---|---|
protected |
Stanza() |
protected |
Stanza(Stanza p) |
protected |
Stanza(StanzaBuilder<?> stanzaBuilder) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addCommonAttributes(XmlStringBuilder xml)
Add to, from, and id attributes.
|
void |
addExtension(ExtensionElement extension)
Adds a stanza extension to the packet.
|
void |
addExtensions(java.util.Collection<? extends ExtensionElement> extensions)
Adds a collection of stanza extensions to the packet.
|
protected void |
appendErrorIfExists(XmlStringBuilder xml)
Append an XMPPError is this stanza has one set.
|
static java.lang.String |
getDefaultLanguage()
Returns the default language used for all messages containing localized content.
|
StanzaError |
getError()
Returns the error associated with this packet, or
null if there are
no errors. |
ExtensionElement |
getExtension(javax.xml.namespace.QName qname) |
ExtensionElement |
getExtension(java.lang.String namespace)
Returns the first extension of this stanza that has the given namespace.
|
<E extends ExtensionElement> |
getExtension(java.lang.String elementName,
java.lang.String namespace)
Deprecated.
use
StanzaView.getExtension(Class) or getExtensionElement(String, String) instead. |
ExtensionElement |
getExtensionElement(java.lang.String elementName,
java.lang.String namespace)
Returns the first extension that matches the specified element name and
namespace, or
null if it doesn't exist. |
java.util.List<ExtensionElement> |
getExtensions()
Returns a list of all extension elements of this stanza.
|
<E extends ExtensionElement> |
getExtensions(java.lang.Class<E> extensionElementClass)
Return all extension elements of the given type.
|
java.util.List<ExtensionElement> |
getExtensions(javax.xml.namespace.QName qname) |
java.util.List<ExtensionElement> |
getExtensions(java.lang.String elementName,
java.lang.String namespace)
Return a list of all extensions with the given element name and namespace.
|
MultiMap<javax.xml.namespace.QName,ExtensionElement> |
getExtensionsMap() |
org.jxmpp.jid.Jid |
getFrom()
Returns who the stanza is being sent "from" or
null if
the value is not set. |
java.lang.String |
getLanguage()
Returns the xml:lang of this XML element, or null if one has not been set.
|
java.lang.String |
getNamespace()
Returns the root element XML namespace.
|
java.lang.String |
getStanzaId()
Returns the unique ID of the stanza.
|
org.jxmpp.jid.Jid |
getTo()
Returns who the stanza is being sent "to", or
null if
the value is not set. |
boolean |
hasExtension(java.lang.String namespace)
Check if a extension element with the given namespace exists.
|
boolean |
hasExtension(java.lang.String elementName,
java.lang.String namespace)
Check if a stanza extension with the given element and namespace exists.
|
boolean |
hasStanzaIdSet()
Check if this stanza has an ID set.
|
protected void |
logCommonAttributes(java.lang.StringBuilder sb) |
ExtensionElement |
overrideExtension(ExtensionElement extension)
Add the given extension and override eventually existing extensions with the same name and
namespace.
|
ExtensionElement |
removeExtension(ExtensionElement extension)
Deprecated.
use
StanzaBuilder instead. |
ExtensionElement |
removeExtension(java.lang.String elementName,
java.lang.String namespace)
Remove the stanza extension with the given elementName and namespace.
|
void |
setError(StanzaError.Builder stanzaError)
Deprecated.
use
StanzaBuilder instead. |
void |
setError(StanzaError stanzaError)
Sets the error for this stanza.
|
void |
setFrom(org.jxmpp.jid.Jid from)
Sets who the packet is being sent "from".
|
void |
setLanguage(java.lang.String language)
Deprecated.
use
StanzaBuilder.setLanguage(String) instead. |
protected java.lang.String |
setNewStanzaId()
Ensure that a stanza ID is set.
|
java.lang.String |
setStanzaId()
Deprecated.
use
StanzaBuilder instead. |
void |
setStanzaId(java.lang.String id)
Sets the unique ID of the packet.
|
void |
setTo(org.jxmpp.jid.Jid to)
Sets who the packet is being sent "to".
|
void |
throwIfNoStanzaId()
Throws an
IllegalArgumentException if this stanza has no stanza ID set. |
abstract java.lang.String |
toString()
Returns a short String describing the Stanza.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetExtension, hasExtension, hasExtensiongetQNamegetElementNamepublic static final java.lang.String TEXT
public static final java.lang.String ITEM
protected static final java.lang.String DEFAULT_LANGUAGE
protected java.lang.String language
Such an attribute is defined for all stanza types. For IQ, see for example XEP-50 3.7: "The requester SHOULD provide its locale information using the "xml:lang " attribute on either the <iq/> (RECOMMENDED) or <command/> element."
protected Stanza()
protected Stanza(StanzaBuilder<?> stanzaBuilder)
protected Stanza(Stanza p)
public final java.lang.String getStanzaId()
StanzaViewnull.getStanzaId in interface StanzaViewnull if the id is not available.public void setStanzaId(java.lang.String id)
null as the packet's id value.id - the unique ID for the packet.public final boolean hasStanzaIdSet()
@Deprecated public java.lang.String setStanzaId()
StanzaBuilder instead.public final void throwIfNoStanzaId()
IllegalArgumentException if this stanza has no stanza ID set.java.lang.IllegalArgumentException - if this stanza has no stanza ID set.protected java.lang.String setNewStanzaId()
public final org.jxmpp.jid.Jid getTo()
StanzaViewnull if
the value is not set. The XMPP protocol often makes the "to"
attribute optional, so it does not always need to be set.getTo in interface StanzaViewnull if the
value has not been set.public void setTo(org.jxmpp.jid.Jid to)
to - who the packet is being sent to.public final org.jxmpp.jid.Jid getFrom()
StanzaViewnull if
the value is not set. The XMPP protocol often makes the "from"
attribute optional, so it does not always need to be set.getFrom in interface StanzaViewnull if the
value has not been set.public void setFrom(org.jxmpp.jid.Jid from)
from - who the packet is being sent to.public final StanzaError getError()
StanzaViewnull if there are
no errors.getError in interface StanzaViewnull if there isn't an error.public void setError(StanzaError stanzaError)
stanzaError - the error that this stanza carries and hence signals.@Deprecated public void setError(StanzaError.Builder stanzaError)
StanzaBuilder instead.stanzaError - the stanza error.public final java.lang.String getLanguage()
XmlLangElementgetLanguage in interface FullyQualifiedElementgetLanguage in interface XmlLangElement@Deprecated public void setLanguage(java.lang.String language)
StanzaBuilder.setLanguage(String) instead.language - the xml:lang of this Stanza.public final java.util.List<ExtensionElement> getExtensions()
StanzaViewgetExtensions in interface StanzaViewpublic final MultiMap<javax.xml.namespace.QName,ExtensionElement> getExtensionsMap()
public final java.util.List<ExtensionElement> getExtensions(java.lang.String elementName, java.lang.String namespace)
Changes to the returned set will update the stanza extensions, if the returned set is not the empty set.
elementName - the element name, must not be null.namespace - the namespace of the element(s), must not be null.public final java.util.List<ExtensionElement> getExtensions(javax.xml.namespace.QName qname)
getExtensions in interface StanzaViewpublic final <E extends ExtensionElement> java.util.List<E> getExtensions(java.lang.Class<E> extensionElementClass)
StanzaViewgetExtensions in interface StanzaViewE - the type of extension elements.extensionElementClass - the class of the type of extension elements.public final ExtensionElement getExtension(java.lang.String namespace)
When possible, use getExtensionElement(String, String) instead.
namespace - the namespace of the extension that is desired.public final ExtensionElement getExtensionElement(java.lang.String elementName, java.lang.String namespace)
null if it doesn't exist. Extensions are
are arbitrary XML elements in standard XMPP stanzas.
Note that it is recommended to use StanzaView.getExtension(Class) instead of this method.
The StanzaView.getExtension(Class) is more robust, as it is type safe.
elementName - the XML element name of the extension.namespace - the XML element namespace of the extension.null if it doesn't exist.@Deprecated public final <E extends ExtensionElement> E getExtension(java.lang.String elementName, java.lang.String namespace)
StanzaView.getExtension(Class) or getExtensionElement(String, String) instead.StanzaView.getExtension(Class) or getExtensionElement(String, String).E - the type to cast to.elementName - the XML element name of the extension. (May be null)namespace - the XML element namespace of the extension.null if it doesn't exist.public final ExtensionElement getExtension(javax.xml.namespace.QName qname)
getExtension in interface StanzaViewpublic final void addExtension(ExtensionElement extension)
Please note that although this method is not yet marked as deprecated, it is recommended to use
StanzaBuilder.addExtension(ExtensionElement) instead.
extension - a stanza extension.public final ExtensionElement overrideExtension(ExtensionElement extension)
Please note that although this method is not yet marked as deprecated, it is recommended to use
StanzaBuilder.overrideExtension(ExtensionElement) instead.
extension - the extension element to add.null if there are none.public final void addExtensions(java.util.Collection<? extends ExtensionElement> extensions)
extensions - a collection of stanza extensionspublic final boolean hasExtension(java.lang.String elementName,
java.lang.String namespace)
The argument elementName may be null.
elementName - TODO javadoc me pleasenamespace - TODO javadoc me pleasepublic final boolean hasExtension(java.lang.String namespace)
StanzaViewhasExtension in interface StanzaViewnamespace - the namespace of the extension element to check for.public final ExtensionElement removeExtension(java.lang.String elementName, java.lang.String namespace)
elementName - TODO javadoc me pleasenamespace - TODO javadoc me please@Deprecated public final ExtensionElement removeExtension(ExtensionElement extension)
StanzaBuilder instead.extension - the stanza extension to remove.public abstract java.lang.String toString()
toString in class java.lang.Objectpublic final java.lang.String getNamespace()
FullyQualifiedElementgetNamespace in interface FullyQualifiedElementpublic static java.lang.String getDefaultLanguage()
protected final void addCommonAttributes(XmlStringBuilder xml)
xml - the XmlStringBuilder.protected void logCommonAttributes(java.lang.StringBuilder sb)
protected final void appendErrorIfExists(XmlStringBuilder xml)
xml - the XmlStringBuilder to append the error to.