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.



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

def initialize(raw_body)
  @raw_body=raw_body
end

Instance Attribute Details

#raw_bodyObject (readonly)

Returns the value of attribute raw_body.



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

def raw_body
  @raw_body
end

Instance Method Details

#atom_entryObject



60
61
62
63
64
65
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 60

def atom_entry
  @atom_entry ||= begin
    require 'nokogiri'
    Nokogiri::XML(raw_body)
  end
end

#cmis_object_idObject



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

def cmis_object_id
  #ToDo
  nil
end

#content_elementObject



67
68
69
70
71
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 67

def content_element
  atom_entry.at_xpath("//cmisra:content", {
    'cmisra' => CMIS_REST_ATOM_NAMESPACE
  })
end

#content_streamObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 18

def content_stream
  if content_element
    unless @stream
      base64 = content_element.at_xpath('.//cmisra:base64', {
        'cmisra' => CMIS_REST_ATOM_NAMESPACE
      })&.text
      media_type = content_element.at_xpath('.//cmisra:mediatype', {
        'cmisra' => CMIS_REST_ATOM_NAMESPACE
      })&.text
      @stream = CmisServer::ContentStream.new(base64: base64, media_type: media_type)
    end
    @stream
  else
    nil
  end
end

#object_elementObject



73
74
75
76
77
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 73

def object_element
  atom_entry.at_xpath("//cmisra:object", {
    'cmisra' => CMIS_REST_ATOM_NAMESPACE
  })
end

#object_propertiesObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 79

def object_properties
  unless @properties
    properties_element = object_element&.at_xpath(".//cmis:properties", {
      'cmis' => CMIS_NAMESPACE
    })
    
    if properties_element
      @properties = {}
      # Chercher tous les éléments qui commencent par 'property'
      props = properties_element.xpath(".//cmis:propertyId | .//cmis:propertyString | .//cmis:propertyInteger | .//cmis:propertyBoolean | .//cmis:propertyDateTime | .//cmis:propertyDecimal", {'cmis' => CMIS_NAMESPACE})
      
      props.each do |prop|
        key = prop['propertyDefinitionId']
        value = prop.at_xpath(".//cmis:value", {'cmis' => CMIS_NAMESPACE})&.text
        @properties[key] = value if key
      end
    else
      @properties = {}
    end
  end
  @properties
end

#object_typeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 35

def object_type
  type_id = object_properties["cmis:objectTypeId"]
  
  result = CmisServer::TypeRegistry.get_type(type_id)
  
  # Si le type n'est pas trouvé dans le registry, utiliser les types de base
  if result.nil? && type_id
    case type_id
    when 'cmis:document'
      result = CmisServer::DocumentType.base
    when 'cmis:folder'
      result = CmisServer::FolderType.base
    when 'cmis:item'
      result = CmisServer::ItemType.base
    end
  end
  
  result
end

#parseObject



14
15
16
# File 'lib/cmis_server/atom_pub/entry_parser.rb', line 14

def parse
  object_type.new
end