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



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/com/wiris/util/sys/Store.rb', line 77

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)
        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 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

#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 self.class.newStore(".")
  end
  parent = Std::substr(parent,0,i)
  return self.class.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::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(@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