Class: WirisPlugin::FolderTreeStorageAndCache
- Inherits:
-
Object
- Object
- WirisPlugin::FolderTreeStorageAndCache
- Extended by:
- StorageAndCacheInterface
- Includes:
- Wiris
- Defined in:
- lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb
Constant Summary collapse
- @@backwards_compat =
true
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #codeDigest(content) ⇒ Object
- #decodeDigest(digest) ⇒ Object
- #deleteCache ⇒ Object
- #getAndCheckFolder(key) ⇒ Object
- #getExtension(service) ⇒ Object
- #getFileStore(dir, digest, extension) ⇒ Object
- #getFileStoreWithParent(parent, digest, extension) ⇒ Object
- #getFolderStore(dir, digest) ⇒ Object
- #init(obj, config) ⇒ Object
-
#initialize ⇒ FolderTreeStorageAndCache
constructor
A new instance of FolderTreeStorageAndCache.
- #isFormulaFileName(name) ⇒ Object
- #retreiveData(digest, service) ⇒ Object
- #storeData(digest, service, stream) ⇒ Object
- #updateFoldersStructure ⇒ Object
- #updateFolderStructure(dir) ⇒ Object
Methods included from StorageAndCacheInterface
Constructor Details
#initialize ⇒ FolderTreeStorageAndCache
19 20 21 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 19 def initialize() super() end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
11 12 13 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 11 def config @config end |
Class Method Details
.backwards_compat ⇒ Object
13 14 15 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 13 def self.backwards_compat @@backwards_compat end |
.backwards_compat=(backwards_compat) ⇒ Object
16 17 18 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 16 def self.backwards_compat=(backwards_compat) @@backwards_compat = backwards_compat end |
Instance Method Details
#codeDigest(content) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 25 def codeDigest(content) digest = Md5Tools::encodeString(content) parent = getFolderStore(getAndCheckFolder(ConfigurationKeys::FORMULA_FOLDER),digest) parent::mkdirs() store = getFileStoreWithParent(parent,digest,"ini") store::write(content) return digest end |
#decodeDigest(digest) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 33 def decodeDigest(digest) formula = getAndCheckFolder(ConfigurationKeys::FORMULA_FOLDER) store = getFileStore(formula,digest,"ini") if @@backwards_compat if !store::exists() oldstore = Store::newStore(((formula+"/")+digest)+".ini") parent = store::getParent() parent::mkdirs() oldstore::moveTo(store) end end return store::read() end |
#deleteCache ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 130 def deleteCache() formulaFolder = getAndCheckFolder(ConfigurationKeys::FORMULA_FOLDER) cacheFolder = getAndCheckFolder(ConfigurationKeys::CACHE_FOLDER) includes = Array.new() includes::push("png") includes::push("csv") includes::push("txt") if !(PropertiesTools::getProperty(@config,ConfigurationKeys::SAVE_MODE,"xml")=="image") includes::push("ini") end Store::deleteDirectory(formulaFolder,includes) Store::deleteDirectory(cacheFolder,includes) end |
#getAndCheckFolder(key) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 73 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
80 81 82 83 84 85 86 87 88 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 80 def getExtension(service) if (service=="png") return "png" end if (service=="svg") return "svg" end return service+".txt" end |
#getFileStore(dir, digest, extension) ⇒ Object
95 96 97 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 95 def getFileStore(dir,digest,extension) return getFileStoreWithParent(getFolderStore(dir,digest),digest,extension) end |
#getFileStoreWithParent(parent, digest, extension) ⇒ Object
92 93 94 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 92 def getFileStoreWithParent(parent,digest,extension) return Store::newStoreWithParent(parent,(Std::substr(digest,4).to_s+".")+extension) end |
#getFolderStore(dir, digest) ⇒ Object
89 90 91 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 89 def getFolderStore(dir,digest) return Store::newStore((((dir+"/")+Std::substr(digest,0,2).to_s)+"/")+Std::substr(digest,2,2).to_s) end |
#init(obj, config) ⇒ Object
22 23 24 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 22 def init(obj,config) @config = config end |
#isFormulaFileName(name) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 119 def isFormulaFileName(name) i = name::indexOf(".") if i==-1 return nil end digest = Std::substr(name,0,i) if digest::length()!=32 return nil end return digest end |
#retreiveData(digest, service) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 46 def retreiveData(digest,service) formula = getAndCheckFolder(ConfigurationKeys::CACHE_FOLDER) store = getFileStore(formula,digest,getExtension(service)) if @@backwards_compat if !store::exists() oldstore = Store::newStore((((formula+"/")+digest)+".")+getExtension(service)) if !oldstore::exists() return nil end parent = store::getParent() parent::mkdirs() oldstore::moveTo(store) end else if !store::exists() return nil end end return store::readBinary()::getData() end |
#storeData(digest, service, stream) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 66 def storeData(digest,service,stream) formula = getAndCheckFolder(ConfigurationKeys::CACHE_FOLDER) parent = getFolderStore(formula,digest) parent::mkdirs() store = getFileStoreWithParent(parent,digest,getExtension(service)) store::writeBinary(Bytes::ofData(stream)) end |
#updateFoldersStructure ⇒ Object
98 99 100 101 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 98 def updateFoldersStructure() updateFolderStructure(getAndCheckFolder(ConfigurationKeys::CACHE_FOLDER)) updateFolderStructure(getAndCheckFolder(ConfigurationKeys::FORMULA_FOLDER)) end |
#updateFolderStructure(dir) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/com/wiris/plugin/impl/FolderTreeStorageAndCache.rb', line 102 def updateFolderStructure(dir) folder = Store::newStore(dir) files = folder::list() if files!=nil for i in 0..files::length-1 digest = isFormulaFileName(files[i]) if digest!=nil newFolder = getFolderStore(dir,digest) newFolder::mkdirs() newFile = getFileStoreWithParent(newFolder,digest,Std::substr(files[i],files[i]::indexOf(".")+1)) file = Store::newStoreWithParent(folder,files[i]) file::moveTo(newFile) end i+=1 end end end |