Class: WirisPlugin::FileStorageAndCache
- Inherits:
-
Object
- Object
- WirisPlugin::FileStorageAndCache
- Extended by:
- StorageAndCacheInterface
- Includes:
- Wiris
- Defined in:
- lib/com/wiris/plugin/impl/FileStorageAndCache.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #codeDigest(content) ⇒ Object
- #decodeDigest(digest) ⇒ Object
- #deleteCache ⇒ Object
- #getAndCheckFolder(key) ⇒ Object
- #getExtension(service) ⇒ Object
- #init(obj, config) ⇒ Object
-
#initialize ⇒ FileStorageAndCache
constructor
A new instance of FileStorageAndCache.
- #retreiveData(digest, service) ⇒ Object
- #storeData(digest, service, stream) ⇒ Object
Methods included from StorageAndCacheInterface
Constructor Details
#initialize ⇒ FileStorageAndCache
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
#config ⇒ Object
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 |
#deleteCache ⇒ Object
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 |