Module: JREXML::JavaPullParser

Defined in:
lib/jrexml/java_pull_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.factoryObject



34
35
36
37
38
39
40
41
# File 'lib/jrexml/java_pull_parser.rb', line 34

def self.factory
  @factory ||= proc do
    fact = org.xmlpull.v1.XmlPullParserFactory.newInstance
    fact.set_namespace_aware false
    fact.set_validating false
    fact
  end.call     
end

Instance Method Details

#all_eventsObject



84
85
86
87
88
89
90
# File 'lib/jrexml/java_pull_parser.rb', line 84

def all_events
  events = []
  while event = pull
    events << event
  end
  events
end

#empty?Boolean

Returns true if there are no more events

Returns:

  • (Boolean)


49
50
51
# File 'lib/jrexml/java_pull_parser.rb', line 49

def empty?
  event_stack.empty?
end

#has_next?Boolean

Returns true if there are more events. Synonymous with !empty?

Returns:

  • (Boolean)


54
55
56
# File 'lib/jrexml/java_pull_parser.rb', line 54

def has_next?
  !empty?
end

#peek(depth = 0) ⇒ Object



65
66
67
# File 'lib/jrexml/java_pull_parser.rb', line 65

def peek(depth = 0)
  raise "not implemented"
end

#pullObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/jrexml/java_pull_parser.rb', line 69

def pull
  event = event_stack.shift
  unless @first_event_seen
    @first_event_seen = true
    version = @source.getProperty("http://xmlpull.org/v1/doc/properties.html#xmldecl-version")
    if version
      standalone = @source.getProperty("http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone")
      encoding = @source.getInputEncoding
      unshift event
      return [:xmldecl, version, encoding, standalone] 
    end
  end
  convert_event(event)
end

#stream=(source) ⇒ Object



43
44
45
46
# File 'lib/jrexml/java_pull_parser.rb', line 43

def stream=(source)
  @source = JavaPullParser.factory.newPullParser
  @source.setInput java.io.ByteArrayInputStream.new(get_bytes(source)), nil
end

#unshift(event) ⇒ Object

Push an event back on the head of the stream. This method has (theoretically) infinite depth.



60
61
62
63
# File 'lib/jrexml/java_pull_parser.rb', line 60

def unshift(event)
  @event_stack ||= []
  @event_stack.unshift event
end