mirror of https://github.com/koreader/koreader
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
972 B
Lua
36 lines
972 B
Lua
11 years ago
|
--[[
|
||
|
This is a registry for document providers
|
||
|
]]--
|
||
|
local DocumentRegistry = {
|
||
|
providers = { }
|
||
|
}
|
||
|
|
||
|
function DocumentRegistry:addProvider(extension, mimetype, provider)
|
||
|
table.insert(self.providers, { extension = extension, mimetype = mimetype, provider = provider })
|
||
|
end
|
||
|
|
||
|
function DocumentRegistry:getProvider(file)
|
||
|
-- TODO: some implementation based on mime types?
|
||
|
local extension = string.lower(string.match(file, ".+%.([^.]+)") or "")
|
||
|
for _, provider in ipairs(self.providers) do
|
||
|
if extension == provider.extension then
|
||
|
return provider.provider
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function DocumentRegistry:openDocument(file)
|
||
|
local provider = self:getProvider(file)
|
||
|
if provider ~= nil then
|
||
|
return provider:new{file = file}
|
||
|
end
|
||
|
end
|
||
|
|
||
|
-- load implementations:
|
||
|
|
||
|
require("document/pdfdocument"):register(DocumentRegistry)
|
||
|
require("document/djvudocument"):register(DocumentRegistry)
|
||
|
require("document/credocument"):register(DocumentRegistry)
|
||
|
|
||
|
return DocumentRegistry
|