module Text.XML.HXT.Parser.ProtocolHandler
( getProtocolHandler
)
where
import Text.XML.HXT.DOM.XmlState
import Data.Maybe
( fromMaybe
)
import Network.URI
( URI
, uriScheme
)
import Text.XML.HXT.Parser.ProtocolHandlerFile
( getFileContents
)
import Text.XML.HXT.Parser.ProtocolHandlerHttpNativeOrCurl
( getHttpContentsNativeOrWithCurl
)
getProtocolHandler :: String -> (URI -> XmlStateFilter a)
getProtocolHandler proto
= fromMaybe getUnsupported handler
where
handler = lookup proto protocolHandler
getUnsupported :: URI -> XmlStateFilter a
getUnsupported uri
= addFatal ( "unsupported protocol "
++ show (uriScheme uri)
++ " in URI: "
++ show uri
)
protocolHandler :: [(String, URI -> XmlStateFilter a)]
protocolHandler
= [ ("file", getFileContents)
, ("http",
getHttpContentsNativeOrWithCurl
)
]