Module: RSS::ListenerMixin

Included in:
REXMLListener, XMLParserListener, XMLScanListener
Defined in:
lib/rss/0.9.rb,
lib/rss/1.0.rb,
lib/rss/atom.rb,
lib/rss/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#do_validateObject

Returns the value of attribute do_validate.



284
285
286
# File 'lib/rss/parser.rb', line 284

def do_validate
  @do_validate
end

#ignore_unknown_elementObject

Returns the value of attribute ignore_unknown_element.



283
284
285
# File 'lib/rss/parser.rb', line 283

def ignore_unknown_element
  @ignore_unknown_element
end

#rssObject (readonly)

Returns the value of attribute rss.



281
282
283
# File 'lib/rss/parser.rb', line 281

def rss
  @rss
end

Instance Method Details

#initializeObject



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/rss/parser.rb', line 286

def initialize
  @rss = nil
  @ignore_unknown_element = true
  @do_validate = true
  @ns_stack = [{"xml" => :xml}]
  @tag_stack = [[]]
  @text_stack = ['']
  @proc_stack = []
  @last_element = nil
  @version = @encoding = @standalone = nil
  @xml_stylesheets = []
  @xml_child_mode = false
  @xml_element = nil
  @last_xml_element = nil
end

#instruction(name, content) ⇒ Object



307
308
309
310
311
312
313
314
# File 'lib/rss/parser.rb', line 307

def instruction(name, content)
  if name == "xml-stylesheet"
    params = parse_pi_content(content)
    if params.has_key?("href")
      @xml_stylesheets << XMLStyleSheet.new(params)
    end
  end
end

#tag_end(name) ⇒ Object



369
370
371
372
373
374
375
376
377
378
379
# File 'lib/rss/parser.rb', line 369

def tag_end(name)
  if DEBUG
    p "end tag #{name}"
    p @tag_stack
  end
  text = @text_stack.pop
  tags = @tag_stack.pop
  pr = @proc_stack.pop
  pr.call(text, tags) unless pr.nil?
  @ns_stack.pop
end

#tag_start(name, attributes) ⇒ Object



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/rss/parser.rb', line 316

def tag_start(name, attributes)
  @text_stack.push('')

  ns = @ns_stack.last.dup
  attrs = {}
  attributes.each do |n, v|
    if /\Axmlns(?:\z|:)/ =~ n
      ns[$POSTMATCH] = v
    else
      attrs[n] = v
    end
  end
  @ns_stack.push(ns)

  prefix, local = split_name(name)
  @tag_stack.last.push([_ns(ns, prefix), local])
  @tag_stack.push([])
  if @xml_child_mode
    previous = @last_xml_element
    element_attrs = attributes.dup
    unless previous
      ns.each do |ns_prefix, value|
        next if ns_prefix == "xml"
        key = ns_prefix.empty? ? "xmlns" : "xmlns:#{ns_prefix}"
        element_attrs[key] ||= value
      end
    end
    next_element = XML::Element.new(local,
                                    prefix.empty? ? nil : prefix,
                                    _ns(ns, prefix),
                                    element_attrs)
    previous << next_element if previous
    @last_xml_element = next_element
    pr = Proc.new do |text, tags|
      if previous
        @last_xml_element = previous
      else
        @xml_element = @last_xml_element
        @last_xml_element = nil
      end
    end
    @proc_stack.push(pr)
  else
    if @rss.nil? and respond_to?("initial_start_#{local}", true)
      __send__("initial_start_#{local}", local, prefix, attrs, ns.dup)
    elsif respond_to?("start_#{local}", true)
      __send__("start_#{local}", local, prefix, attrs, ns.dup)
    else
      start_else_element(local, prefix, attrs, ns.dup)
    end
  end
end

#text(data) ⇒ Object



381
382
383
384
385
386
387
# File 'lib/rss/parser.rb', line 381

def text(data)
  if @xml_child_mode
    @last_xml_element << data if @last_xml_element
  else
    @text_stack.last << data
  end
end

#xmldecl(version, encoding, standalone) ⇒ Object

set instance vars for version, encoding, standalone



303
304
305
# File 'lib/rss/parser.rb', line 303

def xmldecl(version, encoding, standalone)
  @version, @encoding, @standalone = version, encoding, standalone
end