Class Jabber::XMLStanza
In: lib/xmpp4r/xmlstanza.rb
Parent: REXML::Element
XMLStanza Message Presence Iq REXML::Element X IqQuery Error StreamHost IqSiFileRange IqSiFile StreamHostUsed IqSi XRosterItem RosterItem IqFeature XMUCUserItem XMUCUserInvite XDataField XDataReported XDataTitle XDataInstructions Feature Identity Item IqVcard Singleton IdGenerator Connection Client Component Comparable JID RuntimeError AuthenticationFailure ErrorException SOCKS5Error Stream SOCKS5Bytestreams SOCKS5BytestreamsTarget SOCKS5BytestreamsInitiator SOCKS5BytestreamsServerStreamHost TCPSocket SOCKS5Socket IBB IBBTarget IBBInitiator IqQuery IqQueryBytestreams IqQueryVersion IqQueryRoster IqQueryDiscoItems IqQueryDiscoInfo Responder SimpleResponder X XRoster XMUCUser XMUC XDelay XData MUCClient SimpleMUCClient Base DigestMD5 Plain FileSource StreamParser SOCKS5BytestreamsPeer SOCKS5BytestreamsServer IBBQueueItem Helper MUCBrowser Helper Helper lib/xmpp4r/authenticationfailure.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/connection.rb lib/xmpp4r/iq.rb lib/xmpp4r/jid.rb lib/xmpp4r/xmlstanza.rb lib/xmpp4r/errorexception.rb lib/xmpp4r/stream.rb lib/xmpp4r/client.rb lib/xmpp4r/x.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/error.rb lib/xmpp4r/component.rb lib/xmpp4r/query.rb lib/xmpp4r/message.rb lib/xmpp4r/presence.rb lib/xmpp4r/bytestreams/helper/ibb/initiator.rb lib/xmpp4r/bytestreams/iq/si.rb lib/xmpp4r/bytestreams/iq/bytestreams.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb lib/xmpp4r/bytestreams/helper/ibb/base.rb lib/xmpp4r/bytestreams/helper/ibb/target.rb Bytestreams lib/xmpp4r/version/iq/version.rb lib/xmpp4r/version/helper/responder.rb lib/xmpp4r/version/helper/simpleresponder.rb Version lib/xmpp4r/roster/helper/roster.rb lib/xmpp4r/roster/iq/roster.rb lib/xmpp4r/roster/x/roster.rb Roster lib/xmpp4r/feature_negotiation/iq/feature.rb FeatureNegotiation lib/xmpp4r/muc/x/muc.rb lib/xmpp4r/muc/helper/mucclient.rb lib/xmpp4r/muc/x/mucuseritem.rb lib/xmpp4r/muc/helper/mucbrowser.rb lib/xmpp4r/muc/x/mucuserinvite.rb lib/xmpp4r/muc/helper/simplemucclient.rb MUC lib/xmpp4r/sasl.rb SASL lib/xmpp4r/bytestreams/helper/filetransfer.rb TransferSource FileTransfer lib/xmpp4r/delay/x/delay.rb Delay lib/xmpp4r/dataforms/x/data.rb Dataforms lib/xmpp4r/discovery/iq/discoinfo.rb lib/xmpp4r/discovery/iq/discoitems.rb Discovery lib/xmpp4r/vcard/helper/vcard.rb lib/xmpp4r/vcard/iq/vcard.rb Vcard Jabber dot/m_60_0.png

root class of all Jabber XML elements

Methods

answer   answer   error   from   from=   id   id=   normalize   set_from   set_id   set_to   set_type   to   to=   type   type=   typed_add  

Public Class methods

Compose a response by doing the following:

  • Create a new XMLStanza of the same subclass with the same element-name
  • Import xmlstanza if import is true
  • Swap ‘to’ and ‘from
  • Copy ‘id
  • Does not take care about the type

Attention: Be careful when answering to stanzas with type == :error - answering to an error may generate another error on the other side, which could be leading to a ping-pong effect quickly!

xmlstanza:[XMLStanza] source
import:[true or false] Copy attributes and children of source
result:[XMLStanza] answer stanza

[Source]

    # File lib/xmpp4r/xmlstanza.rb, line 29
29:     def XMLStanza.answer(xmlstanza, import=true)
30:       x = xmlstanza.class::new
31:       if import
32:         x.import(xmlstanza)
33:       end
34:       x.from = xmlstanza.to
35:       x.to = xmlstanza.from
36:       x.id = xmlstanza.id
37:       x
38:     end

Public Instance methods

Compose a response of this XMLStanza (see XMLStanza.answer)

result:[XMLStanza] New constructed stanza

[Source]

    # File lib/xmpp4r/xmlstanza.rb, line 63
63:     def answer(import=true)
64:       XMLStanza.answer(self, import)
65:     end

Return the first <error/> child

[Source]

    # File lib/xmpp4r/xmlstanza.rb, line 55
55:     def error
56:       first_element('error')
57:     end

get the from attribute

return:[String] the element‘s from attribute

[Source]

     # File lib/xmpp4r/xmlstanza.rb, line 103
103:     def from
104:       (a = attribute('from')).nil? ? a : JID::new(a.value)
105:     end

set the from attribute

v:[String] the value from set

[Source]

     # File lib/xmpp4r/xmlstanza.rb, line 111
111:     def from= (v)
112:       add_attribute('from', v ? v.to_s : nil)
113:     end

get the id attribute

return:[String] the element‘s id attribute

[Source]

     # File lib/xmpp4r/xmlstanza.rb, line 128
128:     def id
129:       (a = attribute('id')).nil? ? a : a.value
130:     end

set the id attribute

v:[String] the value id set

[Source]

     # File lib/xmpp4r/xmlstanza.rb, line 136
136:     def id= (v)
137:       add_attribute('id', v)
138:     end

Makes some changes to the structure of an XML element to help it respect the specification. For example, in a message, we should have <subject/> < <body/> < { rest of tags }

[Source]

    # File lib/xmpp4r/xmlstanza.rb, line 71
71:     def normalize
72:     end

set the from attribute (chaining-friendly)

v:[String] the value from set

[Source]

     # File lib/xmpp4r/xmlstanza.rb, line 119
119:     def set_from(v)
120:       add_attribute('from', v ? v.to_s : nil)
121:       self
122:     end

set the id attribute (chaining-friendly)

v:[String] the value id set

[Source]

     # File lib/xmpp4r/xmlstanza.rb, line 144
144:     def set_id(v)
145:       add_attribute('id', v)
146:       self
147:     end

set the to attribute (chaining-friendly)

v:[String] the value to set

[Source]

    # File lib/xmpp4r/xmlstanza.rb, line 94
94:     def set_to(v)
95:       self.to = v
96:       self
97:     end

set the type attribute (chaining-friendly)

v:[String] the value type set

[Source]

     # File lib/xmpp4r/xmlstanza.rb, line 169
169:     def set_type(v)
170:       add_attribute('type', v)
171:       self
172:     end

get the to attribute

return:[String] the element‘s to attribute

[Source]

    # File lib/xmpp4r/xmlstanza.rb, line 78
78:     def to
79:       (a = attribute('to')).nil? ? a : JID::new(a.value)
80:     end

set the to attribute

v:[String] the value to set

[Source]

    # File lib/xmpp4r/xmlstanza.rb, line 86
86:     def to= (v)
87:       add_attribute('to', v ? v.to_s : nil)
88:     end

get the type attribute

return:[String] the element‘s type attribute

[Source]

     # File lib/xmpp4r/xmlstanza.rb, line 153
153:     def type
154:       (a = attribute('type')).nil? ? a : a.value
155:     end

set the type attribute

v:[String] the value type set

[Source]

     # File lib/xmpp4r/xmlstanza.rb, line 161
161:     def type= (v)
162:       add_attribute('type', v)
163:     end

Add a sub-element

Will be converted to [Error] if named "error"

element:[REXML::Element] to add

[Source]

    # File lib/xmpp4r/xmlstanza.rb, line 45
45:     def typed_add(element)
46:       if element.kind_of?(REXML::Element) && (element.name == 'error')
47:         super(Error::import(element))
48:       else
49:         super(element)
50:       end
51:     end

[Validate]