Class: WirisPlugin::Store

Inherits:
Object
  • Object
show all
Includes:
Wiris
Defined in:
lib/com/wiris/util/sys/Store.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



8
9
10
# File 'lib/com/wiris/util/sys/Store.rb', line 8

def initialize()
    super()
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



7
8
9
# File 'lib/com/wiris/util/sys/Store.rb', line 7

def file
  @file
end

Class Method Details

.deleteDirectory(folder, included) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# 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

.getCurrentPathObject



55
56
57
# File 'lib/com/wiris/util/sys/Store.rb', line 55

def self.getCurrentPath()
    return FileSystem::fullPath(".")
end

.newStore(folder) ⇒ Object



11
12
13
14
15
# 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) ⇒ Object



46
47
48
# File 'lib/com/wiris/util/sys/Store.rb', line 46

def self.newStoreWithParent(store, str)
    return Store.newStore((store::getFile() + "/") + str)
end

Instance Method Details

#append(str) ⇒ Object



37
38
39
40
41
42
# 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) ⇒ Object



70
71
72
73
# File 'lib/com/wiris/util/sys/Store.rb', line 70

def copyTo(dest)
    b = readBinary()
    dest::writeBinary(b)
end

#deleteObject



77
78
79
80
81
82
83
# 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

#deleteFolderContentsObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# 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

#existsObject



52
53
54
# File 'lib/com/wiris/util/sys/Store.rb', line 52

def exists()
    return FileSystem::exists(@file)
end

#getFileObject



49
50
51
# File 'lib/com/wiris/util/sys/Store.rb', line 49

def getFile()
    return @file
end

#getParentObject



58
59
60
61
62
63
64
65
66
67
68
69
# 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

#listObject



16
17
18
# File 'lib/com/wiris/util/sys/Store.rb', line 16

def list()
    return FileSystem::readDirectory(@file)
end

#mkdirsObject



19
20
21
22
23
24
25
26
27
# 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) ⇒ Object



74
75
76
# File 'lib/com/wiris/util/sys/Store.rb', line 74

def moveTo(dest)
    FileSystem::rename(self.file,dest::getFile())
end

#readObject



43
44
45
# File 'lib/com/wiris/util/sys/Store.rb', line 43

def read()
    return File::getContent(@file)
end

#readBinaryObject



34
35
36
# File 'lib/com/wiris/util/sys/Store.rb', line 34

def readBinary()
    return File::getBytes(@file)
end

#write(str) ⇒ Object



28
29
30
# File 'lib/com/wiris/util/sys/Store.rb', line 28

def write(str)
    File::saveContent(@file,str)
end

#writeBinary(bs) ⇒ Object



31
32
33
# File 'lib/com/wiris/util/sys/Store.rb', line 31

def writeBinary(bs)
    File::saveBytes(@file,bs)
end