Class Jabber::StreamParser
In: lib/xmpp4r/streamparser.rb
Parent: Object
X XDelay XMuc XRoster XMucUser REXML::Element XRosterItem IqQuery XMLStanza IqVcard DiscoIdentity XMucUserItem DiscoItem Error RosterItem DiscoFeature IqQueryRoster IqQueryVersion IqQueryDiscoItems IqQueryDiscoInfo Message Presence Iq Singleton IdGenerator Connection Client Component Comparable JID RuntimeError ErrorException AuthenticationFailure RosterItem Stream StreamParser Roster Vcard Version lib/xmpp4r/authenticationfailure.rb lib/xmpp4r/iq/query/roster.rb lib/xmpp4r/idgenerator.rb lib/xmpp4r/iq/query/version.rb lib/xmpp4r/connection.rb lib/xmpp4r/x/mucuseritem.rb lib/xmpp4r/x/roster.rb lib/xmpp4r/iq.rb lib/xmpp4r/jid.rb lib/xmpp4r/iq/query.rb lib/xmpp4r/xmlstanza.rb lib/xmpp4r/x/delay.rb lib/xmpp4r/errorexception.rb lib/xmpp4r/client.rb lib/xmpp4r/stream.rb lib/xmpp4r/x/muc.rb lib/xmpp4r/streamparser.rb lib/xmpp4r/x.rb lib/xmpp4r/iq/vcard.rb lib/xmpp4r/iq/query/discoinfo.rb lib/xmpp4r/error.rb lib/xmpp4r/component.rb lib/xmpp4r/message.rb lib/xmpp4r/iq/query/discoitems.rb lib/xmpp4r/presence.rb lib/xmpp4r/helpers/roster.rb lib/xmpp4r/helpers/vcard.rb lib/xmpp4r/helpers/version.rb Helpers Jabber Module: Jabber

The REXMLJabberParser uses REXML to parse the incoming XML stream of the Jabber protocol and fires XMLStanzas at the Connection instance.

Methods

new   parse  

Attributes

started  [R]  status if the parser is started

Public Class methods

Constructs a parser for the supplied stream (socket input)

stream:[IO] Socket input stream
listener:[Object.receive(XMLStanza)] The listener (usually a Jabber::Protocol::Connection instance

[Source]

    # File lib/xmpp4r/streamparser.rb, line 26
26:     def initialize(stream, listener)
27:       @stream = stream
28:       # this hack fixes REXML version "2.7.3"
29:       if REXML::Version=="2.7.3"
30:         def @stream.read(len=nil)
31:           len = 100 unless len
32:           super(len)
33:         end
34:       end
35:       @listener = listener
36:       @current = nil
37:     end

Public Instance methods

Begins parsing the XML stream and does not return until the stream closes.

[Source]

    # File lib/xmpp4r/streamparser.rb, line 43
43:     def  parseparse
44:       @started = false
45:       begin
46:         parser = REXML::Parsers::SAX2Parser.new @stream 
47:         parser.listen( :start_element ) do |uri, localname, qname, attributes|
48:           if @current.nil?
49:             @current = REXML::Element::new(qname)
50:           else
51:             e = REXML::Element::new(qname)
52:             @current = @current.add_element(e)
53:           end
54:           @current.add_attributes attributes
55:           if @current.name == 'stream'
56:             @listener.receive(@current)
57:             @started = true
58:           end
59:         end
60:         parser.listen( :end_element ) do  |uri, localname, qname|
61:           case qname
62:           when "stream:stream"
63:             @started = false
64:           else
65:             @listener.receive(@current) if @current.parent.name == 'stream'
66:             @current = @current.parent
67:           end
68:         end
69:         parser.listen( :characters ) do | text |
70:           @current.text = (@current.text.nil? ? '' : @current.text) + text
71:         end
72:         parser.listen( :cdata ) do | text |
73:           raise "Not implemented !"
74:         end
75:         parser.parse
76:       rescue REXML::ParseException
77:         @listener.parse_failure
78:       end
79:     end

[Validate]