{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Readers.Odt.Namespaces ( Namespace (..)
) where
import qualified Data.Map as M (empty, insert)
import Data.Maybe (fromMaybe, listToMaybe)
import Data.Text (Text)
import qualified Data.Text as T
import Text.Pandoc.Readers.Odt.Generic.Namespaces
instance NameSpaceID Namespace where
getInitialIRImap :: NameSpaceIRIs Namespace
getInitialIRImap = NameSpaceIRIs Namespace
nsIDmap
getNamespaceID :: NameSpaceIRI
-> NameSpaceIRIs Namespace
-> Maybe (NameSpaceIRIs Namespace, Namespace)
getNamespaceID NameSpaceIRI
"" NameSpaceIRIs Namespace
m = (NameSpaceIRIs Namespace, Namespace)
-> Maybe (NameSpaceIRIs Namespace, Namespace)
forall a. a -> Maybe a
Just(NameSpaceIRIs Namespace
m, Namespace
NsXML)
getNamespaceID NameSpaceIRI
iri NameSpaceIRIs Namespace
m = Namespace -> Maybe (NameSpaceIRIs Namespace, Namespace)
asPair (Namespace -> Maybe (NameSpaceIRIs Namespace, Namespace))
-> Namespace -> Maybe (NameSpaceIRIs Namespace, Namespace)
forall a b. (a -> b) -> a -> b
$ Namespace -> Maybe Namespace -> Namespace
forall a. a -> Maybe a -> a
fromMaybe (NameSpaceIRI -> Namespace
NsOther NameSpaceIRI
iri) (NameSpaceIRI -> Maybe Namespace
findID NameSpaceIRI
iri)
where asPair :: Namespace -> Maybe (NameSpaceIRIs Namespace, Namespace)
asPair Namespace
nsID = (NameSpaceIRIs Namespace, Namespace)
-> Maybe (NameSpaceIRIs Namespace, Namespace)
forall a. a -> Maybe a
Just (Namespace
-> NameSpaceIRI
-> NameSpaceIRIs Namespace
-> NameSpaceIRIs Namespace
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Namespace
nsID NameSpaceIRI
iri NameSpaceIRIs Namespace
m, Namespace
nsID)
findID :: NameSpaceIRI -> Maybe Namespace
findID :: NameSpaceIRI -> Maybe Namespace
findID NameSpaceIRI
iri = [Namespace] -> Maybe Namespace
forall a. [a] -> Maybe a
listToMaybe [Namespace
nsID | (NameSpaceIRI
iri',Namespace
nsID) <- [(NameSpaceIRI, Namespace)]
nsIDs, NameSpaceIRI
iri' NameSpaceIRI -> NameSpaceIRI -> Bool
`T.isPrefixOf` NameSpaceIRI
iri]
nsIDmap :: NameSpaceIRIs Namespace
nsIDmap :: NameSpaceIRIs Namespace
nsIDmap = ((NameSpaceIRI, Namespace)
-> NameSpaceIRIs Namespace -> NameSpaceIRIs Namespace)
-> NameSpaceIRIs Namespace
-> [(NameSpaceIRI, Namespace)]
-> NameSpaceIRIs Namespace
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((NameSpaceIRI
-> Namespace -> NameSpaceIRIs Namespace -> NameSpaceIRIs Namespace)
-> (NameSpaceIRI, Namespace)
-> NameSpaceIRIs Namespace
-> NameSpaceIRIs Namespace
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((NameSpaceIRI
-> Namespace -> NameSpaceIRIs Namespace -> NameSpaceIRIs Namespace)
-> (NameSpaceIRI, Namespace)
-> NameSpaceIRIs Namespace
-> NameSpaceIRIs Namespace)
-> (NameSpaceIRI
-> Namespace -> NameSpaceIRIs Namespace -> NameSpaceIRIs Namespace)
-> (NameSpaceIRI, Namespace)
-> NameSpaceIRIs Namespace
-> NameSpaceIRIs Namespace
forall a b. (a -> b) -> a -> b
$ (Namespace
-> NameSpaceIRI
-> NameSpaceIRIs Namespace
-> NameSpaceIRIs Namespace)
-> NameSpaceIRI
-> Namespace
-> NameSpaceIRIs Namespace
-> NameSpaceIRIs Namespace
forall a b c. (a -> b -> c) -> b -> a -> c
flip Namespace
-> NameSpaceIRI
-> NameSpaceIRIs Namespace
-> NameSpaceIRIs Namespace
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert) NameSpaceIRIs Namespace
forall k a. Map k a
M.empty [(NameSpaceIRI, Namespace)]
nsIDs
data Namespace =
NsOffice | NsStyle | NsText | NsTable | NsForm
| NsDraw | Ns3D | NsAnim | NsChart | NsConfig
| NsDB | NsMeta | NsNumber | NsScript | NsManifest
| NsPresentation
| NsODF
| NsXSL_FO | NsSVG | NsSmil
| NsMathML | NsXForms | NsXLink | NsXHtml | NsGRDDL
| NsDublinCore
| NsPKG
| NsOpenFormula
| NsXML
| NsOther Text
deriving ( Namespace -> Namespace -> Bool
(Namespace -> Namespace -> Bool)
-> (Namespace -> Namespace -> Bool) -> Eq Namespace
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Namespace -> Namespace -> Bool
$c/= :: Namespace -> Namespace -> Bool
== :: Namespace -> Namespace -> Bool
$c== :: Namespace -> Namespace -> Bool
Eq, Eq Namespace
Eq Namespace
-> (Namespace -> Namespace -> Ordering)
-> (Namespace -> Namespace -> Bool)
-> (Namespace -> Namespace -> Bool)
-> (Namespace -> Namespace -> Bool)
-> (Namespace -> Namespace -> Bool)
-> (Namespace -> Namespace -> Namespace)
-> (Namespace -> Namespace -> Namespace)
-> Ord Namespace
Namespace -> Namespace -> Bool
Namespace -> Namespace -> Ordering
Namespace -> Namespace -> Namespace
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Namespace -> Namespace -> Namespace
$cmin :: Namespace -> Namespace -> Namespace
max :: Namespace -> Namespace -> Namespace
$cmax :: Namespace -> Namespace -> Namespace
>= :: Namespace -> Namespace -> Bool
$c>= :: Namespace -> Namespace -> Bool
> :: Namespace -> Namespace -> Bool
$c> :: Namespace -> Namespace -> Bool
<= :: Namespace -> Namespace -> Bool
$c<= :: Namespace -> Namespace -> Bool
< :: Namespace -> Namespace -> Bool
$c< :: Namespace -> Namespace -> Bool
compare :: Namespace -> Namespace -> Ordering
$ccompare :: Namespace -> Namespace -> Ordering
$cp1Ord :: Eq Namespace
Ord, Int -> Namespace -> ShowS
[Namespace] -> ShowS
Namespace -> String
(Int -> Namespace -> ShowS)
-> (Namespace -> String)
-> ([Namespace] -> ShowS)
-> Show Namespace
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Namespace] -> ShowS
$cshowList :: [Namespace] -> ShowS
show :: Namespace -> String
$cshow :: Namespace -> String
showsPrec :: Int -> Namespace -> ShowS
$cshowsPrec :: Int -> Namespace -> ShowS
Show )
nsIDs :: [(Text, Namespace)]
nsIDs :: [(NameSpaceIRI, Namespace)]
nsIDs = [
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:animation" , Namespace
NsAnim ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:chart" , Namespace
NsChart ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:config" , Namespace
NsConfig ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:database" , Namespace
NsDB ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:dr3d" , Namespace
Ns3D ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:drawing" , Namespace
NsDraw ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:form" , Namespace
NsForm ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:manifest" , Namespace
NsManifest ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:meta" , Namespace
NsMeta ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:datastyle" , Namespace
NsNumber ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:of" , Namespace
NsOpenFormula ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:office:1.0" , Namespace
NsOffice ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:presentation" , Namespace
NsPresentation ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:script" , Namespace
NsScript ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:style" , Namespace
NsStyle ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:table" , Namespace
NsTable ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:text" , Namespace
NsText ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible", Namespace
NsXSL_FO ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:smil-compatible" , Namespace
NsSmil ),
(NameSpaceIRI
"urn:oasis:names:tc:opendocument:xmlns:svg-compatible" , Namespace
NsSVG ),
(NameSpaceIRI
"http://docs.oasis-open.org/ns/office/1.2/meta/odf" , Namespace
NsODF ),
(NameSpaceIRI
"http://docs.oasis-open.org/ns/office/1.2/meta/pkg" , Namespace
NsPKG ),
(NameSpaceIRI
"http://purl.org/dc/elements" , Namespace
NsDublinCore ),
(NameSpaceIRI
"http://www.w3.org/2003/g/data-view" , Namespace
NsGRDDL ),
(NameSpaceIRI
"http://www.w3.org/1998/Math/MathML" , Namespace
NsMathML ),
(NameSpaceIRI
"http://www.w3.org/1999/xhtml" , Namespace
NsXHtml ),
(NameSpaceIRI
"http://www.w3.org/2002/xforms" , Namespace
NsXForms ),
(NameSpaceIRI
"http://www.w3.org/1999/xlink" , Namespace
NsXLink )
]