-------------------------------------------------------------------------------- -- Title: LWBrowserService.lua -- Description: Like a square peg in a round hole -- Author: Raphaël Szwarc http://alt.textdrive.com/lua/ -- Creation Date: February 1, 2005 -- Legal: Copyright (C) 2005 Raphaël Szwarc -------------------------------------------------------------------------------- -- import dependencies local LWObjectService = require( "LWObjectService" ) local LWBrowserPage = require( "LWBrowserPage" ) local LFSFile = require( "LFSFile" ) local LUMap = require( "LUMap" ) -- define the class local super = LWObjectService local self = super() -- initialization method function self:init( aPrefix, aPath, anAuthenticator ) super.init( self, aPrefix, nil, anAuthenticator ) self._path = aPath return self end -- method to access this service directory function self:directory() if self._directory == nil then self._directory = LFSFile( self:path() ) end return self._directory end -- method to access this service path function self:path() return self._path end -- method to define an object for a given path function self:objectWithPath( aPath, aContext ) if aPath ~= nil then local someComponents = LFSFile:pathComponents( self:path() ) someComponents:addAll( LUString:components( aPath, "/" ) ) local aName = someComponents:last() local aPath = LFSFile:separator() .. someComponents:removeLast():join( LFSFile:separator() ) local aFile = LFSFile( aPath, aName ) if aFile:exists() == true then return aFile end else return self:directory() end return nil end -- method to define a path for a given a object function self:pathWithObject( anObject, aContext ) if anObject ~= nil then local aServicePath = self:path() local aPath = anObject:path() aPath = aPath:sub( aServicePath:len() + 1 ) aPath = self:prefix() .. aPath:sub( 2 ) if anObject:isDirectory() == true then aPath = aPath .. "/" end aPath = aPath:gsub( "%" .. LFSFile:separator(), "%/" ) return aPath end return self:prefix() end -- method to define a value for a given a object function self:valueWithObject( anObject, aContext ) return anObject:toString() end -- method to define a title for given a object function self:titleWithObject( anObject, aContext ) return nil end -- method to define a component for given a object function self:componentWithObject( anObject, aContext ) local someBindings = LUMap() someBindings:put( "object", anObject ) local aComponent = LWBrowserPage( aContext, nil, someBindings ) return aComponent end return self