class WirisPlugin::CacheImpl

Attributes

cacheFolder[RW]
conf[RW]

Public Class Methods

backwards_compat() click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 15
def self.backwards_compat
    @@backwards_compat
end
backwards_compat=(backwards_compat) click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 18
def self.backwards_compat=(backwards_compat)
    @@backwards_compat = backwards_compat
end
new(conf) click to toggle source
Calls superclass method
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 21
def initialize(conf)
    super()
    self.conf = conf
    self.cacheFolder = getAndCheckFolder(ConfigurationKeys::CACHE_FOLDER)
end

Public Instance Methods

delete(key) click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 71
def delete(key)
end
deleteAll() click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 57
def deleteAll()
    formulaFolder = getAndCheckFolder(ConfigurationKeys::FORMULA_FOLDER)
    cacheFolder = getAndCheckFolder(ConfigurationKeys::CACHE_FOLDER)
    includes = Array.new()
    includes::push("svg")
    includes::push("png")
    includes::push("csv")
    includes::push("txt")
    if !(PropertiesTools::getProperty(self.conf,ConfigurationKeys::SAVE_MODE,"xml") == "image")
        includes::push("ini")
    end
    Store::deleteDirectory(formulaFolder,includes)
    Store::deleteDirectory(cacheFolder,includes)
end
get(key) click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 36
def get(key)
    extension = Std::substr(key,key::indexOf("."),key::length() - key::indexOf("."))
    digest = Std::substr(key,0,key::indexOf(extension))
    store = self.getFileStore(@cacheFolder,digest,extension)
    if @@backwards_compat
        if !store::exists()
            oldstore = Store::newStore(((@cacheFolder + "/") + digest) + extension)
            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()
end
getAndCheckFolder(key) click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 73
def getAndCheckFolder(key)
    folder = PropertiesTools::getProperty(self.conf,key)
    if (folder == nil) || (folder::trim()::length() == 0)
        raise Exception,"Missing configuration value: " + key
    end
    return folder
end
getFileStore(dir, digest, extension) click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 83
def getFileStore(dir, digest, extension)
    return getFileStoreWithParent(getFolderStore(dir,digest),digest,extension)
end
getFileStoreWithParent(parent, digest, extension) click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 80
def getFileStoreWithParent(parent, digest, extension)
    return Store::newStoreWithParent(parent,Std::substr(digest,4).to_s + extension)
end
getFolderStore(dir, digest) click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 86
def getFolderStore(dir, digest)
    return Store::newStore((((dir + "/") + Std::substr(digest,0,2).to_s) + "/") + Std::substr(digest,2,2).to_s)
end
isFormulaFileName(name) click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 110
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
set(key, value) click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 26
def set(key, value)
    extension = Std::substr(key,key::indexOf("."),key::length() - key::indexOf("."))
    digest = Std::substr(key,0,key::indexOf(extension))
    parent = getFolderStore(@cacheFolder,digest)
    parent::mkdirs()
    store = getFileStoreWithParent(parent,digest,extension)
    if !store::exists()
        store::writeBinary(value)
    end
end
updateFolderStructure(dir) click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 93
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
updateFoldersStructure() click to toggle source
# File lib/com/wiris/plugin/impl/CacheImpl.rb, line 89
def updateFoldersStructure()
    updateFolderStructure(getAndCheckFolder(ConfigurationKeys::CACHE_FOLDER))
    updateFolderStructure(getAndCheckFolder(ConfigurationKeys::FORMULA_FOLDER))
end