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.



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

def initialize()
    super()
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



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

def config
  @config
end

Instance Method Details

#codeDigest(content) ⇒ Object



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

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



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

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

#deleteCacheObject



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

def deleteCache()
end

#getAndCheckFolder(key) ⇒ Object



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

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



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

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

#init(obj, config, cache, cacheFormula) ⇒ Object



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

def init(obj, config, cache, cacheFormula)
    self.config = config
end

#retreiveData(digest, service) ⇒ Object



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

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



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

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