class Wiris::Storage

Constants

TYPE_FILE
TYPE_RESOURCE
TYPE_URL

Public Class Methods

getResourcesDir() click to toggle source
# File lib/src-generic/Storage.rb, line 126
def self.getResourcesDir()
        if @@resourcesDir.nil?
                setResourcesDir()
        end
        return @@resourcesDir
end
new(location=nil) click to toggle source
# File lib/src-generic/Storage.rb, line 43
def initialize(location=nil)
        if location != nil
                @location = location
        end
end
newResourceStorage(name) click to toggle source
# File lib/src-generic/Storage.rb, line 74
def self.newResourceStorage(name)
        s = Storage.new(File.join(getResourcesDir,name))
        s.type = TYPE_RESOURCE
        return s;
end
newStorage(name) click to toggle source
# File lib/src-generic/Storage.rb, line 49
def self.newStorage(name)
        s = Storage.new(name)
        s.type = TYPE_FILE
        return s
end
newStorageWithParent(parent, name) click to toggle source
# File lib/src-generic/Storage.rb, line 55
    def self.newStorageWithParent(parent, name)
    s = Storage.new(parent.location)
    s.type = parent.type;
    if (parent.type == TYPE_FILE)
        # @file = File.new(File.join(parent.location, name), "w+")
        # @file.close
        s.location = File.join(parent.location, name)
    elsif (parent.type == TYPE_RESOURCE)
        s.resourceName = parent.resourceName;
        if (s.resourceName.length() > 0 && !s.resourceName.endsWith("/")) 
            s.resourceName += "/"
        end
        s.resourceName += name
    elsif (parent.type == TYPE_URL)
        url = Url.new(Url.new(parent.url),name).toExternalForm()
    end
    return s
end
resourcesDir() click to toggle source
# File lib/src-generic/Storage.rb, line 39
def self.resourcesDir
        @@resourcesDir
end
resourcesDir=(resourcesDir) click to toggle source
# File lib/src-generic/Storage.rb, line 36
def self.resourcesDir=(resourcesDir)
        @@resourcesDir = resourcesDir
end
setResourcesDir() click to toggle source
# File lib/src-generic/Storage.rb, line 133
def self.setResourcesDir()
        @@resourcesDir = File.dirname(__FILE__)
end

Public Instance Methods

exists() click to toggle source
# File lib/src-generic/Storage.rb, line 111
def exists()
        return File.exists?(location)
end
file() click to toggle source
# File lib/src-generic/Storage.rb, line 18
def file
        @file
end
file=(file) click to toggle source
# File lib/src-generic/Storage.rb, line 15
def file=(file)
        @file = file
end
location() click to toggle source
# File lib/src-generic/Storage.rb, line 28
def location
        @location
end
location=(location) click to toggle source
# File lib/src-generic/Storage.rb, line 32
def location=(location)
        @location = location
end
mkdirs() click to toggle source
# File lib/src-generic/Storage.rb, line 115
def mkdirs()
if (@type == TYPE_RESOURCE)
    notImplemented()
end
if (@type == TYPE_URL)
    notImplemented()
end        
Dir.mkdir(@location)

end
notImplemented() click to toggle source
# File lib/src-generic/Storage.rb, line 137
def notImplemented()
         raise Exception,'Error: Operation not available on this Storage'
end
read() click to toggle source
# File lib/src-generic/Storage.rb, line 80
def read()
        return File.read(location)
end
readBinary() click to toggle source
# File lib/src-generic/Storage.rb, line 84
def readBinary()              
        s = File.binread(location)
        return s.bytes.to_a
end
resourceName() click to toggle source
# File lib/src-generic/Storage.rb, line 21
def resourceName
        @resourceName
end
resourceName=(resourceName) click to toggle source
# File lib/src-generic/Storage.rb, line 24
def resourceName=(resourceName)
        @resourceName = resourceName
end
toString() click to toggle source
# File lib/src-generic/Storage.rb, line 141
def toString()
        if type == TYPE_FILE
                return location.to_s
        elsif type == TYPE_RESOURCE
                return resourceName
        elsif type == TYPE_URL
                return url
        else
                return nil
        end
end
type() click to toggle source
# File lib/src-generic/Storage.rb, line 12
def type
        @type
end
type=(type) click to toggle source
# File lib/src-generic/Storage.rb, line 9
def type=(type)
        @type = type
end
write(str) click to toggle source
# File lib/src-generic/Storage.rb, line 89
def write(str)
        writeOrAppend(str, false)
end
writeBinary(bs) click to toggle source
# File lib/src-generic/Storage.rb, line 93
def writeBinary(bs)
        File.open(location, 'wb' ) do |output|
               output.write bs.pack("C*")
       end
end
writeOrAppend(str, append) click to toggle source
# File lib/src-generic/Storage.rb, line 99
def writeOrAppend(str, append)
        if (@type == TYPE_RESOURCE)
                notImplemented()
        end
        if (@type == TYPE_URL)
                notImplemented()
        end
        @file = File.new(@location, "w")
        @file.write(str)
        @file.close
end