Class: ActiveCMIS::Rendition

Inherits:
Object
  • Object
show all
Defined in:
lib/active_cmis/rendition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, link) ⇒ Rendition

Returns a new instance of Rendition.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_cmis/rendition.rb', line 13

def initialize(repository, link)
  @repository = repository

  @rel = link['rel'] == "alternate"
  @rendition_kind = link['renditionKind'] if rendition?
  @format = link['type']
  if link['href']
    @url = URI(link['href'])
  else # For inline content streams
    @data = link['data']
  end
  @size = link['length'] ? link['length'].to_i : nil


  @link = link # FIXME: For debugging purposes only, remove
end

Instance Attribute Details

#formatString? (readonly)

Returns The format is equal to the mime type, but may be unset or misleading.

Returns:

  • (String, nil)

    The format is equal to the mime type, but may be unset or misleading



10
11
12
# File 'lib/active_cmis/rendition.rb', line 10

def format
  @format
end

#rendition_kindString? (readonly)

Returns:

  • (String, nil)


8
9
10
# File 'lib/active_cmis/rendition.rb', line 8

def rendition_kind
  @rendition_kind
end

#repositoryRepository (readonly)

Returns:



4
5
6
# File 'lib/active_cmis/rendition.rb', line 4

def repository
  @repository
end

#sizeNumeric? (readonly)

Returns Size of the rendition, may not be given or misleading.

Returns:

  • (Numeric, nil)

    Size of the rendition, may not be given or misleading



6
7
8
# File 'lib/active_cmis/rendition.rb', line 6

def size
  @size
end

Instance Method Details

#get_file(file_name) ⇒ Hash

Returns a hash with the name of the file to which was written, the lenthe, and the content type

WARNING: this loads the complete file in memory and dumps it at once, this should be fixed

Parameters:

  • filename (String)

    Location to store the content.

Returns:

  • (Hash)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/active_cmis/rendition.rb', line 44

def get_file(file_name)
  if @url
    response = repository.conn.get_response(@url)
    status = response.code.to_i
    if 200 <= status && status < 300
      data = response.body 
    else
      raise HTTPError.new("Problem downloading rendition: status: #{status}, message: #{response.body}")
    end
    content_type = response.content_type
    content_lenth = response.content_length || response.body.length # In case content encoding is chunked? ??
  else
    data = @data
    content_type = @format
    content_length = @data.length
  end
  File.open(file_name, "w") {|f| f.syswrite data }

  {:file => file_name, :content_type => content_type, :content_length => content_length}
end

#primary?Boolean

Used to differentiate between rendition and primary content

Returns:

  • (Boolean)


35
36
37
# File 'lib/active_cmis/rendition.rb', line 35

def primary?
  @rel.nil?
end

#rendition?Boolean

Used to differentiate between rendition and primary content

Returns:

  • (Boolean)


31
32
33
# File 'lib/active_cmis/rendition.rb', line 31

def rendition?
  @rel == "alternate"
end