public abstract class Packet extends java.lang.Object implements TopLevelStreamElement
| 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 |
| Constructor and Description |
|---|
Packet() |
Packet(Packet p) |
Packet(java.lang.String packetID) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addCommonAttributes(XmlStringBuilder xml)
Add to, from, id and 'xml:lang' attributes
|
void |
addExtension(PacketExtension extension)
Adds a packet extension to the packet.
|
void |
addExtensions(java.util.Collection<PacketExtension> extensions)
Adds a collection of packet extensions to the packet.
|
protected void |
appendErrorIfExists(XmlStringBuilder xml)
Append an XMPPError is this packet has one set.
|
static java.lang.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.
|
PacketExtension |
getExtension(java.lang.String namespace)
Returns the first extension of this packet that has the given namespace.
|
<PE extends PacketExtension> |
getExtension(java.lang.String elementName,
java.lang.String namespace)
Returns the first packet extension that matches the specified element name and
namespace, or null if it doesn't exist.
|
java.util.List<PacketExtension> |
getExtensions()
Returns a copy of the packet extensions attached to the packet.
|
protected XmlStringBuilder |
getExtensionsXML()
Returns the extension sub-packets (including properties data) as an XML
String, or the Empty String if there are no packet extensions.
|
java.lang.String |
getFrom()
Returns who the packet is being sent "from" or null if
the value is not set.
|
java.lang.String |
getLanguage()
Returns the xml:lang of this Stanza, or null if one has not been set.
|
java.lang.String |
getPacketID()
Returns the unique ID of the packet.
|
java.lang.String |
getTo()
Returns who the packet is being sent "to", or null if
the value is not set.
|
boolean |
hasExtension(java.lang.String namespace)
Check if a packet extension with the given namespace exists.
|
boolean |
hasExtension(java.lang.String elementName,
java.lang.String namespace)
Check if a packet extension with the given element and namespace exists.
|
PacketExtension |
removeExtension(PacketExtension extension)
Removes a packet extension from the packet.
|
PacketExtension |
removeExtension(java.lang.String elementName,
java.lang.String namespace)
Remove the packet extension with the given elementName and namespace.
|
void |
setError(XMPPError error)
Sets the error for this packet.
|
void |
setFrom(java.lang.String from)
Sets who the packet is being sent "from".
|
void |
setLanguage(java.lang.String language)
Sets the xml:lang of this Stanza.
|
void |
setPacketID(java.lang.String packetID)
Sets the unique ID of the packet.
|
void |
setTo(java.lang.String to)
Sets who the packet is being sent "to".
|
java.lang.String |
toString() |
public 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
public Packet()
public Packet(java.lang.String packetID)
public Packet(Packet p)
public java.lang.String getPacketID()
null.null if the packet's id is not available.public void setPacketID(java.lang.String packetID)
null as the packet's id value.packetID - the unique ID for the packet.public java.lang.String getTo()
public void setTo(java.lang.String to)
to - who the packet is being sent to.public java.lang.String getFrom()
public void setFrom(java.lang.String from)
from - who the packet is being sent to.public XMPPError getError()
public void setError(XMPPError error)
error - the error to associate with this packet.public java.lang.String getLanguage()
public void setLanguage(java.lang.String language)
language - the xml:lang of this Stanza.public java.util.List<PacketExtension> getExtensions()
public PacketExtension getExtension(java.lang.String namespace)
When possible, use getExtension(String,String) instead.
namespace - the namespace of the extension that is desired.public <PE extends PacketExtension> PE getExtension(java.lang.String elementName, java.lang.String namespace)
ProviderManager
class to handle custom parsing. In that case, the type of the Object
will be determined by the provider.elementName - the XML element name of the packet extension. (May be null)namespace - the XML element namespace of the packet extension.public void addExtension(PacketExtension extension)
extension - a packet extension.public void addExtensions(java.util.Collection<PacketExtension> extensions)
extensions - a collection of packet extensionspublic boolean hasExtension(java.lang.String elementName,
java.lang.String namespace)
The argument elementName may be null.
elementName - namespace - public boolean hasExtension(java.lang.String namespace)
namespace - public PacketExtension removeExtension(java.lang.String elementName, java.lang.String namespace)
elementName - namespace - public PacketExtension removeExtension(PacketExtension extension)
extension - the packet extension to remove.public java.lang.String toString()
toString in class java.lang.Objectprotected final XmlStringBuilder getExtensionsXML()
public static java.lang.String getDefaultLanguage()
protected void addCommonAttributes(XmlStringBuilder xml)
xml - protected void appendErrorIfExists(XmlStringBuilder xml)
xml - the XmlStringBuilder to append the error to.