-------------------------------------------------------------------------------- -- Title: MIMEType.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 LUObject = require( "LUObject" ) local LUBundle = require( "LUBundle" ) local LUMap = require( "LUMap" ) -- define the class local super = LUObject local self = super() -- class variable(s) local _types = nil -- method to access the types function self:types() if _types == nil then local aBundle = LUBundle:bundleWithObject( self ) local aFile = aBundle:fileWithName( self:className(), "txt" ) _types = LUMap():load( aFile ) end return _types end -- method to guess a type given its extension function self:typeWithExtension( anExtension ) if anExtension ~= nil then local aType = self:types():get( anExtension:lower() ) if aType ~= nil then return aType end end return self:types():get( "*" ) end return self