class WirisPlugin::Store

Attributes

file[RW]

Public Class Methods

deleteDirectory(folder, included) click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 101
def self.deleteDirectory(folder, included)
    if (folder == nil) || !FileSystem::exists(folder)
        return 
    end
    path = FileSystem::fullPath(folder)
    files = FileSystem::readDirectory(folder)
    i = 0
    for i in 0..files::length - 1
        file = files[i]
        file = (path + '/'.to_s) + file
        if FileSystem::isDirectory(file)
            Store.deleteDirectory(file,included)
        else 
            includedIterator = included::iterator()
            if included != nil
                while includedIterator::hasNext()
                    if StringTools::endsWith(file,includedIterator::next())
                        FileSystem::deleteFile(file)
                    end
                end
            else 
                FileSystem::deleteFile(file)
            end
        end
        i+=1
    end
    files = FileSystem::readDirectory(folder)
    if files::length == 0
        FileSystem::deleteDirectory(folder)
    end
end
getCurrentPath() click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 55
def self.getCurrentPath()
    return FileSystem::fullPath(".")
end
new() click to toggle source
Calls superclass method
# File lib/com/wiris/util/sys/Store.rb, line 8
def initialize()
    super()
end
newStore(folder) click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 11
def self.newStore(folder)
    s = Store.new()
    s::file = folder
    return s
end
newStoreWithParent(store, str) click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 46
def self.newStoreWithParent(store, str)
    return Store.newStore((store::getFile() + "/") + str)
end

Public Instance Methods

append(str) click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 37
def append(str)
    output = File::append(@file,true)
    output::writeString(str)
    output::flush()
    output::close()
end
copyTo(dest) click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 70
def copyTo(dest)
    b = readBinary()
    dest::writeBinary(b)
end
delete() click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 77
def delete()
    if FileSystem::isDirectory(self.file)
        FileSystem::deleteDirectory(self.file)
    else 
        FileSystem::deleteFile(self.file)
    end
end
deleteFolderContents() click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 84
def deleteFolderContents()
    if self.exists() && FileSystem::isDirectory(self.getFile())
        files = self.list()
        for i in 0..files::length - 1
            if !((files[i] == ".") || (files[i] == ".."))
                f = Store::newStoreWithParent(self,files[i])
                if FileSystem::isDirectory(f::getFile())
                    f::deleteFolderContents()
                    FileSystem::deleteDirectory(f::getFile())
                else 
                    FileSystem::deleteFile(f::getFile())
                end
            end
            i+=1
        end
    end
end
exists() click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 52
def exists()
    return FileSystem::exists(@file)
end
getFile() click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 49
def getFile()
    return @file
end
getParent() click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 58
def getParent()
    parent = FileSystem::fullPath(@file)
    if parent == nil
        parent = @file
    end
    i = WInteger::max(parent::lastIndexOf("/"),parent::lastIndexOf("\\"))
    if i < 0
        return Store.newStore(".")
    end
    parent = Std::substr(parent,0,i)
    return Store.newStore(parent)
end
list() click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 16
def list()
    return FileSystem::readDirectory(@file)
end
mkdirs() click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 19
def mkdirs()
    parent = getParent()
    if !parent::exists() && !((parent::getFile() == self.file))
        parent::mkdirs()
    end
    if !exists()
        FileSystem::createDirectory(@file)
    end
end
moveTo(dest) click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 74
def moveTo(dest)
    FileSystem::rename(self.file,dest::getFile())
end
read() click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 43
def read()
    return File::getContent(@file)
end
readBinary() click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 34
def readBinary()
    return File::getBytes(@file)
end
write(str) click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 28
def write(str)
    File::saveContent(@file,str)
end
writeBinary(bs) click to toggle source
# File lib/com/wiris/util/sys/Store.rb, line 31
def writeBinary(bs)
    File::saveBytes(@file,bs)
end