Class: RUtilAnts::URLAccess::URLHandlers::DataImage

Inherits:
Object
  • Object
show all
Defined in:
lib/rUtilAnts/URLHandlers/DataImage.rb

Overview

Handler of data:image URIs

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(iURL) ⇒ DataImage

Constructor

Parameters
  • iURL (String): The URL that this handler will manage



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rUtilAnts/URLHandlers/DataImage.rb', line 24

def initialize(iURL)
  @URL = iURL
  lMatchData = @URL.match(/data:image\/(.*);base64,(.*)/)
  if (lMatchData == nil)
    log_bug "URL #{iURL[0..23]}... was identified as a data:image like, but it appears to be false."
  else
    @Ext = lMatchData[1]
    if (@Ext == 'x-icon')
      @Ext = 'ico'
    end
    @Data = lMatchData[2]
  end
end

Class Method Details

.get_matching_regexpsObject

Get a list of regexps matching the URL to get to this handler

Return
  • list<Regexp>: The list of regexps matching URLs from this handler



14
15
16
17
18
# File 'lib/rUtilAnts/URLHandlers/DataImage.rb', line 14

def self.get_matching_regexps
  return [
    /^data:image.*$/
  ]
end

Instance Method Details

#get_content(iFollowRedirections) ⇒ Object

Get the content of the URL

Parameters
  • iFollowRedirections (Boolean): Do we follow redirections while accessing the content ?

Return
  • Integer: Type of content returned

  • Object: The content, depending on the type previously returned:

    • Exception if CONTENT_ERROR: The corresponding error

    • String if CONTENT_REDIRECT: The new URL

    • String if CONTENT_STRING: The real content

    • String if CONTENT_LOCALFILENAME: The name of the local file name storing the content

    • String if CONTENT_LOCALFILENAME_TEMPORARY: The name of the temporary local file name storing the content



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/rUtilAnts/URLHandlers/DataImage.rb', line 77

def get_content(iFollowRedirections)
  rContentFormat = nil
  rContent = nil

  # Here we unpack the string in a base64 encoding.
  if (@Data.empty?)
    rContent = RuntimeError.new("Empty URI to decode: #{@URL}")
    rContentFormat = CONTENT_ERROR
  else
    rContent = @Data.unpack('m')[0]
    rContentFormat = CONTENT_STRING
  end

  return rContentFormat, rContent
end

#get_corresponding_file_base_nameObject

Get a corresponding file base name. This method has to make sure file extensions are respected, as it can be used for further processing.

Return
  • String: The file name



61
62
63
# File 'lib/rUtilAnts/URLHandlers/DataImage.rb', line 61

def get_corresponding_file_base_name
  return "DataImage.#{@Ext}"
end

#get_crcObject

Get the current CRC of the URL

Return
  • Integer: The CRC



50
51
52
53
54
# File 'lib/rUtilAnts/URLHandlers/DataImage.rb', line 50

def get_crc
  # As the content is in the URL, it will be natural to not find it anymore in the cache when it is changed.
  # Therefore there is no need to return a CRC.
  return 0
end

#get_server_idObject

Get the server ID

Return
  • String: The server ID



42
43
44
# File 'lib/rUtilAnts/URLHandlers/DataImage.rb', line 42

def get_server_id
  return nil
end