Class Jabber::XMPPElement
In: lib/xmpp4r/xmppelement.rb
Parent: REXML::Element
Message Presence XMPPStanza Iq XMPPElement ErrorResponse X IqQuery JabberError ComponentAuthenticationFailure ArgumentError InvalidChatState SOCKS5Error ServerError NoNameXmlnsRegistered ServerDisconnected ClientAuthenticationFailure Connection Client Component Connection Client Singleton IdGenerator Comparable JID Enumerable CallbackList Items Publish StandardError REXML::Element Stream XMPPElement Location IqFeature StreamHost IqSiFile IqSiFileRange IqSi StreamHostUsed XRosterItem RosterItem C Body HTML UserItem XMUCUserInvite Configuration Retract IqPubSub Item IqPubSubOwner Event Subscription Unsubscribe Tune XDataField XDataReported XDataTitle XDataInstructions Feature Item Identity IqVcard PubSub::ServiceHelper Helper Helper SOCKS5Bytestreams SOCKS5BytestreamsTarget SOCKS5BytestreamsInitiator SOCKS5BytestreamsServerStreamHost TCPSocket SOCKS5Socket IqQuery IqQueryBytestreams IqQueryRoster IqQueryVersion IqQueryRPC IqQueryMUCOwner IqQueryMUCAdmin IqQueryDiscoItems IqQueryDiscoInfo IqQueryLastActivity IBB IBBTarget IBBInitiator RosterXItem XRoster RosterX X XDelay XMUC XMUCUser XData Responder SimpleResponder Iq IqCommand XMLRPC::ParserWriterChooseMixin Client Server XMLRPC::ParseContentType XMLRPC::BasicServer MUCClient SimpleMUCClient MUC::UserItem XMUCUserItem IqQueryMUCAdminItem XParent SubscriptionConfig NodeConfig OwnerNodeConfig EventItems ServiceHelper OAuthServiceHelper NodeHelper EventItem Base Anonymous DigestMD5 Plain FileSource Base Bot Callback StreamParser Semaphore SOCKS5BytestreamsPeer SOCKS5BytestreamsServer IBBQueueItem Helper Responder Helper Listener MUCBrowser NodeBrowser ListenerMocker Helper Responder Helper Helper Helper lib/xmpp4r/message.rb lib/xmpp4r/connection.rb lib/xmpp4r/xmppstanza.rb lib/xmpp4r/iq.rb lib/xmpp4r/callbacks.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/stream.rb lib/xmpp4r/client.rb lib/xmpp4r/jid.rb lib/xmpp4r/x.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/semaphore.rb lib/xmpp4r/errors.rb lib/xmpp4r/component.rb lib/xmpp4r/presence.rb lib/xmpp4r/xmppelement.rb lib/xmpp4r/query.rb XParent lib/xmpp4r/location/helper/helper.rb lib/xmpp4r/location/location.rb UserLocation lib/xmpp4r/feature_negotiation/iq/feature.rb FeatureNegotiation lib/xmpp4r/bytestreams/iq/si.rb lib/xmpp4r/bytestreams/helper/ibb/initiator.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/base.rb lib/xmpp4r/bytestreams/iq/bytestreams.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/initiator.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/socks5.rb lib/xmpp4r/bytestreams/helper/ibb/target.rb lib/xmpp4r/bytestreams/helper/socks5bytestreams/server.rb lib/xmpp4r/bytestreams/helper/ibb/base.rb Bytestreams lib/xmpp4r/roster/x/roster.rb lib/xmpp4r/roster/helper/roster.rb lib/xmpp4r/roster/iq/roster.rb Roster lib/xmpp4r/version/helper/responder.rb lib/xmpp4r/version/helper/simpleresponder.rb lib/xmpp4r/version/iq/version.rb Version lib/xmpp4r/command/iq/command.rb lib/xmpp4r/command/helper/responder.rb Command lib/xmpp4r/caps/helper/helper.rb lib/xmpp4r/caps/c.rb Caps lib/xmpp4r/reliable.rb Reliable lib/xmpp4r/delay/x/delay.rb Delay lib/xmpp4r/xhtml/html.rb XHTML lib/xmpp4r/rpc/helper/server.rb lib/xmpp4r/rpc/helper/client.rb lib/xmpp4r/rpc/iq/rpc.rb RPC lib/xmpp4r/muc/iq/mucadminitem.rb lib/xmpp4r/muc/x/muc.rb lib/xmpp4r/muc/item.rb lib/xmpp4r/muc/helper/simplemucclient.rb lib/xmpp4r/muc/iq/mucadmin.rb lib/xmpp4r/muc/helper/mucbrowser.rb lib/xmpp4r/muc/x/mucuseritem.rb lib/xmpp4r/muc/x/mucuserinvite.rb lib/xmpp4r/muc/iq/mucowner.rb lib/xmpp4r/muc/helper/mucclient.rb MUC lib/xmpp4r/pubsub/children/item.rb lib/xmpp4r/pubsub/children/configuration.rb lib/xmpp4r/pubsub/children/subscription.rb lib/xmpp4r/pubsub/helper/servicehelper.rb lib/xmpp4r/pubsub/children/unsubscribe.rb lib/xmpp4r/pubsub/children/publish.rb lib/xmpp4r/pubsub/helper/oauth_service_helper.rb lib/xmpp4r/pubsub/children/event.rb lib/xmpp4r/pubsub/iq/pubsub.rb lib/xmpp4r/pubsub/children/retract.rb lib/xmpp4r/pubsub/helper/nodebrowser.rb lib/xmpp4r/pubsub/helper/nodehelper.rb lib/xmpp4r/pubsub/children/items.rb lib/xmpp4r/pubsub/children/subscription_config.rb lib/xmpp4r/pubsub/children/node_config.rb OAuthPubSubStreamHelper PubSub lib/xmpp4r/httpbinding/client.rb HTTPBinding lib/xmpp4r/tune/helper/helper.rb lib/xmpp4r/tune/tune.rb UserTune lib/xmpp4r/sasl.rb SASL lib/xmpp4r/test/listener_mocker.rb Test lib/xmpp4r/dataforms/x/data.rb Dataforms lib/xmpp4r/discovery/helper/helper.rb lib/xmpp4r/discovery/iq/discoinfo.rb lib/xmpp4r/discovery/helper/responder.rb lib/xmpp4r/discovery/iq/discoitems.rb Discovery lib/xmpp4r/bytestreams/helper/filetransfer.rb TransferSource FileTransfer lib/xmpp4r/last/helper/helper.rb lib/xmpp4r/last/iq/last.rb LastActivity lib/xmpp4r/framework/base.rb lib/xmpp4r/framework/bot.rb Framework lib/xmpp4r/vcard/helper/vcard.rb lib/xmpp4r/vcard/iq/vcard.rb Vcard Jabber dot/m_110_0.png

This class represents an XML element and provides functionality for automatic casting of XML element classes according to their element name and namespace.

Deriving classes must met these criteria:

  • The element name and namespace must be specified by calling the name_xmlns class method
  • The class constructor must be callable with no mandatory parameter

Methods

Public Class methods

Find a class for given name and namespace

name:[String]
xmlns:[String]
result:A descendant of XMPPElement or REXML::Element

[Source]

    # File lib/xmpp4r/xmppelement.rb, line 70
70:     def self.class_for_name_xmlns(name, xmlns)
71:       if @@name_xmlns_classes.has_key? [name, xmlns]
72:         @@name_xmlns_classes[[name, xmlns]]
73:       elsif @@name_xmlns_classes.has_key? [name, nil]
74:         @@name_xmlns_classes[[name, nil]]
75:       else
76:         REXML::Element
77:       end
78:     end

Set whether this element is always built with an xmlns attribute

[Source]

    # File lib/xmpp4r/xmppelement.rb, line 35
35:     def self.force_xmlns(force)
36:       @@force_xmlns = force
37:     end

Whether this element is always built with an xmlns attribute

[Source]

    # File lib/xmpp4r/xmppelement.rb, line 41
41:     def self.force_xmlns?
42:       @@force_xmlns
43:     end

Import another REXML::Element descendant to:

  • Either an element class that registered with name and xmlns before
  • Or if none was found to the class itself (you may call this class method on a deriving class)

[Source]

    # File lib/xmpp4r/xmppelement.rb, line 86
86:     def self.import(element)
87:       klass = class_for_name_xmlns(element.name, element.namespace)
88:       if klass != self and klass.ancestors.include?(self)
89:         klass.new.import(element)
90:       else
91:         self.new.import(element)
92:       end
93:     end

Specify XML element name and xmlns for a deriving class, this pair and the class will be added to a global pool

If the namespace is nil the class is a "wildcard class" matching elements with any xmlns if no other class with that namespace was defined

[Source]

    # File lib/xmpp4r/xmppelement.rb, line 29
29:     def self.name_xmlns(name, xmlns=nil)
30:       @@name_xmlns_classes[[name, xmlns]] = self
31:     end

Find the name and namespace for a given class. This class must have registered these two values by calling name_xmlns at definition time.

Raises an exception if none was found

klass:[Class]
result:[String, String] name and namespace

[Source]

    # File lib/xmpp4r/xmppelement.rb, line 53
53:     def self.name_xmlns_for_class(klass)
54:       klass.ancestors.each do |klass1|
55:         @@name_xmlns_classes.each do |name_xmlns,k|
56:           if klass1 == k
57:             return name_xmlns
58:           end
59:         end
60:       end
61: 
62:       raise NoNameXmlnsRegistered.new(klass)
63:     end

Initialize this element, which will then be initialized with the name registered with name_xmlns.

[Source]

     # File lib/xmpp4r/xmppelement.rb, line 98
 98:     def initialize(*arg)
 99:       if arg.empty?
100:         name, xmlns = self.class::name_xmlns_for_class(self.class)
101:         super(name)
102:         if self.class::force_xmlns?
103:           add_namespace(xmlns)
104:         end
105:       else
106:         super
107:       end
108:     end

Public Instance methods

[Source]

     # File lib/xmpp4r/xmppelement.rb, line 140
140:     def clone
141:       cloned = self.class.new
142:       cloned.add_attributes self.attributes.clone
143:       cloned.context = @context
144:       cloned
145:     end

[Source]

     # File lib/xmpp4r/xmppelement.rb, line 128
128:     def parent=(new_parent)
129:       if parent and parent.namespace('') == namespace('') and attributes['xmlns'].nil?
130:         add_namespace parent.namespace('')
131:       end
132: 
133:       super
134: 
135:       if new_parent and new_parent.namespace('') == namespace('')
136:         delete_namespace
137:       end
138:     end

Set XML language attribute (chainable)

[Source]

     # File lib/xmpp4r/xmppelement.rb, line 162
162:     def set_xml_lang(l)
163:       self.xml_lang = l
164:       self
165:     end

Add a child element which will be imported according to the child‘s name and xmlns

element:[REXML::Element] Child
result:[REXML::Element or descendant of XMPPElement] New child

[Source]

     # File lib/xmpp4r/xmppelement.rb, line 115
115:     def typed_add(element)
116:       if element.kind_of? REXML::Element
117:         element_ns = (element.namespace.to_s == '') ? namespace : element.namespace
118: 
119:         klass = XMPPElement::class_for_name_xmlns(element.name, element_ns)
120:         if klass != element.class
121:           element = klass.import(element)
122:         end
123:       end
124: 
125:       super(element)
126:     end

Generic XML attribute ‘xml:lang’ (REXML provides no shortcut)

[Source]

     # File lib/xmpp4r/xmppelement.rb, line 150
150:     def xml_lang
151:       attributes['xml:lang']
152:     end

Set XML language attribute

[Source]

     # File lib/xmpp4r/xmppelement.rb, line 156
156:     def xml_lang=(l)
157:       attributes['xml:lang'] = l
158:     end

[Validate]