Class: Viewpoint::EWS::SOAP::EwsSaxDocument

Inherits:
Nokogiri::XML::SAX::Document
  • Object
show all
Includes:
Viewpoint::EWS, StringUtils
Defined in:
lib/ews/soap/parsers/ews_sax_document.rb

Overview

Parse the incoming response document via a SAX parser instead of the traditional DOM parser. In early benchmarks this was performing about 132% faster than the DOM-based parser for large documents.

Constant Summary

Constants included from StringUtils

StringUtils::DURATION_RE

Constants included from Viewpoint::EWS

ConnectingSID

Instance Attribute Summary collapse

Attributes included from Viewpoint::EWS

#logger

Instance Method Summary collapse

Methods included from StringUtils

included

Methods included from Viewpoint::EWS

#remove_impersonation, root_logger, #set_impersonation

Constructor Details

#initializeEwsSaxDocument

Returns a new instance of EwsSaxDocument.



29
30
31
32
# File 'lib/ews/soap/parsers/ews_sax_document.rb', line 29

def initialize
  @struct = {}
  @elems  = []
end

Instance Attribute Details

#structObject (readonly)

Returns the value of attribute struct.



27
28
29
# File 'lib/ews/soap/parsers/ews_sax_document.rb', line 27

def struct
  @struct
end

Instance Method Details

#characters(string) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ews/soap/parsers/ews_sax_document.rb', line 34

def characters(string)
  # FIXME: Move white space removal to somewhere else.
  # This function can be called multiple times. In this case newlines in Text Bodies get stripped.
  # See: https://github.com/zenchild/Viewpoint/issues/90
  #string.strip!
  return if string.empty?
  if @elems.last[:text]
    @elems.last[:text] += string
  else
    @elems.last[:text] = string
  end
end

#end_element_namespace(name, prefix = nil, uri = nil) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/ews/soap/parsers/ews_sax_document.rb', line 58

def end_element_namespace name, prefix=nil, uri=nil
  name = ruby_case(name).to_sym
  elem = @elems.pop
  if @elems.empty?
    @struct[name] = elem
  else
    @elems.last[:elems] = [] unless @elems.last[:elems].is_a?(Array)
    @elems.last[:elems] << {name => elem}
  end
end

#start_element_namespace(name, attributes = [], prefix = nil, uri = nil, ns = []) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/ews/soap/parsers/ews_sax_document.rb', line 47

def start_element_namespace(name, attributes = [], prefix = nil, uri = nil, ns = [])
  name = ruby_case(name).to_sym
  elem = {}
  unless attributes.empty?
    elem[:attribs] = attributes.collect{|a|
      { ruby_case(a.localname).to_sym => a.value}
    }.inject(&:merge)
  end
  @elems << elem
end