| Class | Jabber::XMLStanza |
| In: |
lib/xmpp4r/xmlstanza.rb
|
| Parent: | REXML::Element |
root class of all Jabber XML elements
Compose a response by doing the following:
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 |
# 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
Compose a response of this XMLStanza (see XMLStanza.answer)
| result: | [XMLStanza] New constructed stanza |
# File lib/xmpp4r/xmlstanza.rb, line 63
63: def answer(import=true)
64: XMLStanza.answer(self, import)
65: end
Return the first <error/> child
# 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 |
# 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 |
# 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 |
# 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 |
# 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 }
# File lib/xmpp4r/xmlstanza.rb, line 71
71: def normalize
72: end
set the from attribute (chaining-friendly)
| v: | [String] the value from set |
# 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 |
# 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 |
# 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 |
# 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 |
# 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 |
# 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 |
# 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 |
# 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 |
# 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