public abstract class Stanza extends Object implements TopLevelStreamElement, Packet
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.
Modifier and Type | Field and Description |
---|---|
protected static String |
DEFAULT_LANGUAGE |
static String |
ITEM |
protected String |
language
Optional value of the 'xml:lang' attribute of the outermost element of
the stanza.
|
static String |
TEXT |
Modifier | Constructor and Description |
---|---|
protected |
Stanza() |
protected |
Stanza(Stanza p) |
protected |
Stanza(String stanzaId) |
Modifier and Type | Method and Description |
---|---|
protected void |
addCommonAttributes(XmlStringBuilder xml)
Add to, from, id and 'xml:lang' attributes
|
void |
addExtension(ExtensionElement extension)
Adds a stanza(/packet) extension to the packet.
|
void |
addExtensions(Collection<ExtensionElement> extensions)
Adds a collection of stanza(/packet) extensions to the packet.
|
protected void |
appendErrorIfExists(XmlStringBuilder xml)
Append an XMPPError is this stanza(/packet) has one set.
|
static String |
getDefaultLanguage()
Returns the default language used for all messages containing localized content.
|
XMPPError |
getError()
Returns the error associated with this packet, or null if there are
no errors.
|
ExtensionElement |
getExtension(String namespace)
Returns the first extension of this stanza(/packet) that has the given namespace.
|
<PE extends ExtensionElement> |
getExtension(String elementName,
String namespace)
Returns the first extension that matches the specified element name and
namespace, or null if it doesn't exist.
|
List<ExtensionElement> |
getExtensions()
Returns a list of all extension elements of this stanza.
|
Set<ExtensionElement> |
getExtensions(String elementName,
String namespace)
Return a set of all extensions with the given element name
|
protected XmlStringBuilder |
getExtensionsXML()
Returns the extension sub-packets (including properties data) as an XML
String, or the Empty String if there are no stanza(/packet) extensions.
|
String |
getFrom()
Returns who the stanza(/packet) is being sent "from" or null if
the value is not set.
|
String |
getLanguage()
Returns the xml:lang of this Stanza, or null if one has not been set.
|
String |
getPacketID()
Deprecated.
use
getStanzaId() instead. |
String |
getStanzaId()
Returns the unique ID of the stanza.
|
String |
getTo()
Returns who the stanza(/packet) is being sent "to", or null if
the value is not set.
|
boolean |
hasExtension(String namespace)
Check if a stanza(/packet) extension with the given namespace exists.
|
boolean |
hasExtension(String elementName,
String namespace)
Check if a stanza(/packet) extension with the given element and namespace exists.
|
boolean |
hasStanzaIdSet()
Check if this stanza has an ID set.
|
ExtensionElement |
overrideExtension(ExtensionElement extension)
Add the given extension and override eventually existing extensions with the same name and
namespace.
|
ExtensionElement |
removeExtension(ExtensionElement extension)
Removes a stanza(/packet) extension from the packet.
|
ExtensionElement |
removeExtension(String elementName,
String namespace)
Remove the stanza(/packet) extension with the given elementName and namespace.
|
void |
setError(XMPPError error)
Sets the error for this packet.
|
void |
setFrom(String from)
Sets who the stanza(/packet) is being sent "from".
|
void |
setLanguage(String language)
Sets the xml:lang of this Stanza.
|
void |
setPacketID(String packetID)
Deprecated.
use
setStanzaId(String) instead. |
void |
setStanzaId(String id)
Sets the unique ID of the packet.
|
void |
setTo(String to)
Sets who the stanza(/packet) is being sent "to".
|
String |
toString() |
public static final String TEXT
public static final String ITEM
protected static final String DEFAULT_LANGUAGE
protected 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
protected Stanza()
public String getStanzaId()
null
.getStanzaId
in interface Packet
null
if the id is not available.@Deprecated public String getPacketID()
getStanzaId()
instead.getPacketID
in interface Packet
public void setStanzaId(String id)
null
as the packet's id value.setStanzaId
in interface Packet
id
- the unique ID for the packet.@Deprecated public void setPacketID(String packetID)
setStanzaId(String)
instead.setPacketID
in interface Packet
packetID
- public boolean hasStanzaIdSet()
public String getTo()
public void setTo(String to)
public String getFrom()
public void setFrom(String from)
public XMPPError getError()
public String getLanguage()
getLanguage
in interface Packet
public void setLanguage(String language)
setLanguage
in interface Packet
language
- the xml:lang of this Stanza.public List<ExtensionElement> getExtensions()
getExtensions
in interface Packet
public Set<ExtensionElement> getExtensions(String elementName, String namespace)
Changes to the returned set will update the stanza(/packet) extensions, if the returned set is not the empty set.
getExtensions
in interface Packet
elementName
- the element name, must not be null.namespace
- the namespace of the element(s), must not be null.public ExtensionElement getExtension(String namespace)
When possible, use getExtension(String,String)
instead.
getExtension
in interface Packet
namespace
- the namespace of the extension that is desired.public <PE extends ExtensionElement> PE getExtension(String elementName, String namespace)
DefaultExtensionElement
instance will be returned for each extension. However,
ExtensionElementProvider instances can be registered with the
ProviderManager
class to handle custom parsing. In that case, the type of the Object
will be determined by the provider.getExtension
in interface Packet
elementName
- the XML element name of the extension. (May be null)namespace
- the XML element namespace of the extension.public void addExtension(ExtensionElement extension)
addExtension
in interface Packet
extension
- a stanza(/packet) extension.public ExtensionElement overrideExtension(ExtensionElement extension)
extension
- the extension element to add.null
if there are none.public void addExtensions(Collection<ExtensionElement> extensions)
addExtensions
in interface Packet
extensions
- a collection of stanza(/packet) extensionspublic boolean hasExtension(String elementName, String namespace)
The argument elementName
may be null.
hasExtension
in interface Packet
elementName
- namespace
- public boolean hasExtension(String namespace)
hasExtension
in interface Packet
namespace
- public ExtensionElement removeExtension(String elementName, String namespace)
removeExtension
in interface Packet
elementName
- namespace
- public ExtensionElement removeExtension(ExtensionElement extension)
removeExtension
in interface Packet
extension
- the stanza(/packet) extension to remove.protected final XmlStringBuilder getExtensionsXML()
public static String getDefaultLanguage()
protected void addCommonAttributes(XmlStringBuilder xml)
xml
- protected void appendErrorIfExists(XmlStringBuilder xml)
xml
- the XmlStringBuilder to append the error to.