Class: WirisPlugin::FileStorageAndCache

Inherits:
Object
  • Object
show all
Extended by:
StorageAndCacheInterface
Includes:
Wiris
Defined in:
lib/com/wiris/plugin/impl/FileStorageAndCache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StorageAndCacheInterface

StorageAndCache

Constructor Details

#initializeFileStorageAndCache

Returns a new instance of FileStorageAndCache.



12
13
14
# File 'lib/com/wiris/plugin/impl/FileStorageAndCache.rb', line 12

def initialize()
  super()
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



11
12
13
# File 'lib/com/wiris/plugin/impl/FileStorageAndCache.rb', line 11

def config
  @config
end

Instance Method Details

#codeDigest(content) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/com/wiris/plugin/impl/FileStorageAndCache.rb', line 18

def codeDigest(content)
  formula = getAndCheckFolder(ConfigurationKeys::FORMULA_FOLDER)
  digest = Md5Tools::encodeString(content)
  store = Store::newStoreWithParent(Store::newStore(formula),digest+".ini")
  store::write(content)
  return digest
end

#decodeDigest(digest) ⇒ Object



25
26
27
28
29
# File 'lib/com/wiris/plugin/impl/FileStorageAndCache.rb', line 25

def decodeDigest(digest)
  formula = getAndCheckFolder(ConfigurationKeys::FORMULA_FOLDER)
  store = Store::newStoreWithParent(Store::newStore(formula),digest+".ini")
  return store::read()
end

#deleteCacheObject



56
57
# File 'lib/com/wiris/plugin/impl/FileStorageAndCache.rb', line 56

def deleteCache()
end

#getAndCheckFolder(key) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/com/wiris/plugin/impl/FileStorageAndCache.rb', line 43

def getAndCheckFolder(key)
  folder = PropertiesTools::getProperty(@config,key)
  if (folder==nil)||(folder::trim()::length()==0)
    raise Exception,"Missing configuration value: "+key
  end
  return folder
end

#getExtension(service) ⇒ Object



50
51
52
53
54
55
# File 'lib/com/wiris/plugin/impl/FileStorageAndCache.rb', line 50

def getExtension(service)
  if (service=="png")
    return ".png"
  end
  return ("."+service)+".txt"
end

#init(obj, config) ⇒ Object



15
16
17
# File 'lib/com/wiris/plugin/impl/FileStorageAndCache.rb', line 15

def init(obj,config)
  @config = config
end

#retreiveData(digest, service) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/com/wiris/plugin/impl/FileStorageAndCache.rb', line 30

def retreiveData(digest,service)
  formula = getAndCheckFolder(ConfigurationKeys::CACHE_FOLDER)
  store = Store::newStoreWithParent(Store::newStore(formula),digest+getExtension(service))
  if !store::exists()
    return nil
  end
  return store::readBinary()::getData()
end

#storeData(digest, service, stream) ⇒ Object



38
39
40
41
42
# File 'lib/com/wiris/plugin/impl/FileStorageAndCache.rb', line 38

def storeData(digest,service,stream)
  formula = getAndCheckFolder(ConfigurationKeys::CACHE_FOLDER)
  store = Store::newStoreWithParent(Store::newStore(formula),digest+getExtension(service))
  store::writeBinary(Bytes::ofData(stream))
end