Class: CmisServer::EntryParser

Inherits:
Object
  • Object
show all
Defined in:
lib/cmis_server/atom_pub/entry_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_body) ⇒ EntryParser

Returns a new instance of EntryParser.



5
6
7
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 5

def initialize(raw_body)
  @raw_body=raw_body
end

Instance Attribute Details

#raw_bodyObject (readonly)

Returns the value of attribute raw_body.



3
4
5
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 3

def raw_body
  @raw_body
end

Instance Method Details

#atom_entryObject



35
36
37
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 35

def atom_entry
  @atom_entry||=Atom::Entry.parse(raw_body)
end

#cmis_namespace_nameObject



55
56
57
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 55

def cmis_namespace_name
  object_element.namespaces.find{|_k,v|v==CMIS_NAMESPACE}[0]
end

#cmis_object_idObject



30
31
32
33
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 30

def cmis_object_id
  #ToDo
  nil
end

#cmis_rest_atom_namespace_nameObject



59
60
61
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 59

def cmis_rest_atom_namespace_name
  object_element.namespaces.find{|_k,v|v==CMIS_REST_ATOM_NAMESPACE}[0]
end

#content_elementObject



39
40
41
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 39

def content_element
  atom_entry.extensions.find{|e| e.namespace==CMIS_REST_ATOM_NAMESPACE&&e.local_name=='content'}
end

#content_streamObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 13

def content_stream
  if content_element
    unless @stream
      base64=content_element.get_elements('cmisra:base64').first&.text
      media_type=content_element.get_elements('cmisra:mediatype').first&.text
      @stream=CmisServer::ContentStream.new(base64: base64, media_type: media_type)
    end
    @stream
  else
    nil
  end
end

#object_elementObject



43
44
45
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 43

def object_element
  atom_entry.extensions.find{|e| e.namespace==CMIS_REST_ATOM_NAMESPACE&&e.local_name=='object'}
end

#object_propertiesObject



47
48
49
50
51
52
53
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 47

def object_properties
  unless @properties
    properties_element=object_element.get_elements("#{cmis_namespace_name}:properties").first
    @properties=properties_element.elements.each_with_object(Hash.new){|p,h| h.merge!(parse_property(p))}
  end
  @properties
end

#object_typeObject



26
27
28
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 26

def object_type
  TypeAdapter.find!(object_properties["cmis:objectTypeId"])
end

#parseObject



9
10
11
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 9

def parse
  object_type.new
end

#parse_property(property_element) ⇒ Object



63
64
65
66
67
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 63

def parse_property(property_element)
  {
      property_element.attributes['propertyDefinitionId'] => property_element.get_elements("#{cmis_namespace_name}:value").first&.text
  }
end