### Home Classes Methods

### In Files

- lib/xmpp4r/xmppelement.rb

### Parent

REXML::Element

### Methods

- ::class_for_name_xmlns
- ::force_xmlns
- ::force_xmlns?
- ::import
- ::name_xmlns
- ::name_xmlns_for_class
- ::new
- #clone
- #parent=
- #set_xml_lang
- #typed_add
- #xml_lang
- #xml_lang=

### Files

- CHANGELOG
- COPYING
- LICENSE
- README.rdoc
- README_ruby19.txt

### Class/Module Index

Quicksearch

- Jabber
- Jabber::ArgumentError
- Jabber::Bytestreams
- Jabber::Bytestreams::IBB
- Jabber::Bytestreams::IBBInitiator
- Jabber::Bytestreams::IBBQueueItem
- Jabber::Bytestreams::IBBTarget
- Jabber::Bytestreams::IqQueryBytestreams
- Jabber::Bytestreams::IqSi
- Jabber::Bytestreams::IqSiFile
- Jabber::Bytestreams::IqSiFileRange
- Jabber::Bytestreams::SOCKS5Bytestreams
- Jabber::Bytestreams::SOCKS5BytestreamsInitiator
- Jabber::Bytestreams::SOCKS5BytestreamsPeer
- Jabber::Bytestreams::SOCKS5BytestreamsServer
- Jabber::Bytestreams::SOCKS5BytestreamsServerStreamHost
- Jabber::Bytestreams::SOCKS5BytestreamsTarget
- Jabber::Bytestreams::SOCKS5Socket
- Jabber::Bytestreams::StreamHost
- Jabber::Bytestreams::StreamHostUsed
- Jabber::Callback
- Jabber::CallbackList
- Jabber::Caps
- Jabber::Caps::C
- Jabber::Caps::Helper
- Jabber::Client
- Jabber::ClientAuthenticationFailure
- Jabber::Command
- Jabber::Command::IqCommand
- Jabber::Command::Responder
- Jabber::Component
- Jabber::ComponentAuthenticationFailure
- Jabber::Connection
- Jabber::Connection::SSLSocketUTF8
- Jabber::Dataforms
- Jabber::Dataforms::XData
- Jabber::Dataforms::XDataField
- Jabber::Dataforms::XDataInstructions
- Jabber::Dataforms::XDataReported
- Jabber::Dataforms::XDataTitle
- Jabber::Delay
- Jabber::Delay::XDelay
- Jabber::Discovery
- Jabber::Discovery::Feature
- Jabber::Discovery::Helper
- Jabber::Discovery::Identity
- Jabber::Discovery::IqQueryDiscoInfo
- Jabber::Discovery::IqQueryDiscoItems
- Jabber::Discovery::Item
- Jabber::Discovery::Responder
- Jabber::EntityTime
- Jabber::EntityTime::IqTime
- Jabber::EntityTime::Responder
- Jabber::ErrorResponse
- Jabber::FeatureNegotiation
- Jabber::FeatureNegotiation::IqFeature
- Jabber::FileTransfer
- Jabber::FileTransfer::FileSource
- Jabber::FileTransfer::Helper
- Jabber::FileTransfer::TransferSource
- Jabber::Framework
- Jabber::Framework::Base
- Jabber::Framework::Bot
- Jabber::HTTPBinding
- Jabber::HTTPBinding::Client
- Jabber::IdGenerator
- Jabber::InvalidChatState
- Jabber::Iq
- Jabber::IqQuery
- Jabber::JID
- Jabber::JabberError
- Jabber::LastActivity
- Jabber::LastActivity::Helper
- Jabber::LastActivity::IqQueryLastActivity
- Jabber::MUC
- Jabber::MUC::IqQueryMUCAdmin
- Jabber::MUC::IqQueryMUCAdminItem
- Jabber::MUC::IqQueryMUCOwner
- Jabber::MUC::MUCBrowser
- Jabber::MUC::MUCClient
- Jabber::MUC::SimpleMUCClient
- Jabber::MUC::UserItem
- Jabber::MUC::XMUC
- Jabber::MUC::XMUCUser
- Jabber::MUC::XMUCUserInvite
- Jabber::MUC::XMUCUserItem
- Jabber::Message
- Jabber::NoNameXmlnsRegistered
- Jabber::NotConnected
- Jabber::Observable
- Jabber::Observable::Contact
- Jabber::Observable::PubSub
- Jabber::Observable::PubSub::AlreadySet
- Jabber::Observable::PubSub::NoService
- Jabber::Observable::Subscriptions
- Jabber::Presence
- Jabber::PubSub
- Jabber::PubSub::Configuration
- Jabber::PubSub::Event
- Jabber::PubSub::EventItem
- Jabber::PubSub::EventItems
- Jabber::PubSub::IqPubSub
- Jabber::PubSub::IqPubSubOwner
- Jabber::PubSub::Item
- Jabber::PubSub::Items
- Jabber::PubSub::NodeBrowser
- Jabber::PubSub::NodeConfig
- Jabber::PubSub::NodeHelper
- Jabber::PubSub::OAuthPubSubStreamHelper
- Jabber::PubSub::OAuthServiceHelper
- Jabber::PubSub::OwnerNodeConfig
- Jabber::PubSub::Publish
- Jabber::PubSub::Retract
- Jabber::PubSub::ServiceHelper
- Jabber::PubSub::Subscription
- Jabber::PubSub::SubscriptionConfig
- Jabber::PubSub::Unsubscribe
- Jabber::RPC
- Jabber::RPC::Client
- Jabber::RPC::IqQueryRPC
- Jabber::RPC::Server
- Jabber::Reliable
- Jabber::Reliable::Connection
- Jabber::Reliable::Listener
- Jabber::Roster
- Jabber::Roster::Helper
- Jabber::Roster::Helper::RosterItem
- Jabber::Roster::IqQueryRoster
- Jabber::Roster::RosterItem
- Jabber::Roster::RosterX
- Jabber::Roster::RosterXItem
- Jabber::Roster::XRoster
- Jabber::Roster::XRosterItem
- Jabber::SASL
- Jabber::SASL::Anonymous
- Jabber::SASL::Base
- Jabber::SASL::DigestMD5
- Jabber::SASL::Plain
- Jabber::SOCKS5Error
- Jabber::Semaphore
- Jabber::ServerDisconnected
- Jabber::Stream
- Jabber::Stream::ThreadBlock
- Jabber::StreamParser
- Jabber::Test
- Jabber::Test::ListenerMocker
- Jabber::UserLocation
- Jabber::UserLocation::Helper
- Jabber::UserLocation::Location
- Jabber::UserTune
- Jabber::UserTune::Helper
- Jabber::UserTune::Tune
- Jabber::Vcard
- Jabber::Vcard::Helper
- Jabber::Vcard::IqVcard
- Jabber::Version
- Jabber::Version::IqQueryVersion
- Jabber::Version::Responder
- Jabber::Version::SimpleResponder
- Jabber::X
- Jabber::XHTML
- Jabber::XHTML::Body
- Jabber::XHTML::HTML
- Jabber::XMPPElement
- Jabber::XMPPStanza
- Jabber::XParent
- REXML
- REXML::Element
- REXML::IOSource
- XMLRPC
- XMLRPC::Create
- Base64
- ObservableThing
- QObserver
- ThreadStore

No matching classes.

# Jabber::XMPPElement

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

### Public Class Methods

class_for_name_xmlns(name, xmlns) click to toggle source

Find a class for given name and namespace

name

String

xmlns

String

result | A descendant of XMPPElement or REXML::Element

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

force_xmlns(force) click to toggle source

Set whether this element is always built with an xmlns attribute

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

force_xmlns?() click to toggle source

Whether this element is always built with an xmlns attribute

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

import(element) click to toggle source

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)

    # File lib/xmpp4r/xmppelement.rb, line 86
    def self.import(element)
      klass = class_for_name_xmlns(element.name, element.namespace)
      if klass != self and klass.ancestors.include?(self)
        klass.new.import(element)
      else
        self.new.import(element)
      end
    end

name_xmlns(name, xmlns=nil) click to toggle source

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

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

name_xmlns_for_class(klass) click to toggle source

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

    # File lib/xmpp4r/xmppelement.rb, line 53
    def self.name_xmlns_for_class(klass)
      klass.ancestors.each do |klass1|
        @@name_xmlns_classes.each do |name_xmlns,k|
          if klass1 == k
            return name_xmlns
          end
        end
      end

      raise NoNameXmlnsRegistered.new(klass)
    end

new(*arg) click to toggle source

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

    # File lib/xmpp4r/xmppelement.rb, line 98
    def initialize(*arg)
      if arg.empty?
        name, xmlns = self.class::name_xmlns_for_class(self.class)
        super(name)
        if self.class::force_xmlns?
          add_namespace(xmlns)
        end
      else
        super
      end
    end

### Public Instance Methods

clone() click to toggle source

    # File lib/xmpp4r/xmppelement.rb, line 140
    def clone
      cloned = self.class.new
      cloned.add_attributes self.attributes.clone
      cloned.context = @context
      cloned
    end

parent=(new_parent) click to toggle source

    # File lib/xmpp4r/xmppelement.rb, line 128
    def parent=(new_parent)
      if parent and parent.namespace('') == namespace('') and attributes['xmlns'].nil?
        add_namespace parent.namespace('')
      end

      super

      if new_parent and new_parent.namespace('') == namespace('')
        delete_namespace
      end
    end

set_xml_lang(l) click to toggle source

Set XML language attribute (chainable)

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

typed_add(element) click to toggle source

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

    # File lib/xmpp4r/xmppelement.rb, line 115
    def typed_add(element)
      if element.kind_of? REXML::Element
        element_ns = (element.namespace.to_s == '') ? namespace : element.namespace

        klass = XMPPElement::class_for_name_xmlns(element.name, element_ns)
        if klass != element.class
          element = klass.import(element)
        end
      end

      super(element)
    end

xml_lang() click to toggle source

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

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

xml_lang=(l) click to toggle source

Set XML language attribute

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.