aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Odt/Namespaces.hs
blob: 28865182f9c95dbadf7dab94e310d70b3d241ab5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{-# LANGUAGE NoImplicitPrelude #-}
{-
Copyright (C) 2015 Martin Linnemann <theCodingMarlin@googlemail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-}

{- |
   Module      : Text.Pandoc.Reader.Odt.Namespaces
   Copyright   : Copyright (C) 2015 Martin Linnemann
   License     : GNU GPL, version 2 or above

   Maintainer  : Martin Linnemann <theCodingMarlin@googlemail.com>
   Stability   : alpha
   Portability : portable

Namespaces used in odt files.
-}

module Text.Pandoc.Readers.Odt.Namespaces ( Namespace (..)
                                          ) where

import Prelude
import Data.List (isPrefixOf)
import qualified Data.Map as M (empty, insert)
import Data.Maybe (fromMaybe, listToMaybe)

import Text.Pandoc.Readers.Odt.Generic.Namespaces


instance NameSpaceID Namespace where

  getInitialIRImap     = nsIDmap

  getNamespaceID ""  m = Just(m, NsXML)
  getNamespaceID iri m = asPair $ fromMaybe (NsOther iri) (findID iri)
    where asPair nsID = Just (M.insert nsID iri m, nsID)


findID :: NameSpaceIRI -> Maybe Namespace
findID iri = listToMaybe [nsID | (iri',nsID) <- nsIDs, iri' `isPrefixOf` iri]

nsIDmap :: NameSpaceIRIs Namespace
nsIDmap = foldr (uncurry $ flip M.insert) M.empty nsIDs

data Namespace = -- Open Document core
                 NsOffice | NsStyle  | NsText   | NsTable  | NsForm
               | NsDraw   | Ns3D     | NsAnim   | NsChart  | NsConfig
               | NsDB     | NsMeta   | NsNumber | NsScript | NsManifest
               | NsPresentation
                 -- Metadata
               | NsODF
                 -- Compatible elements
               | NsXSL_FO  | NsSVG    | NsSmil
                 -- External standards
               | NsMathML | NsXForms | NsXLink  | NsXHtml  | NsGRDDL
               | NsDublinCore
                 -- Metadata manifest
               | NsPKG
                 -- Others
               | NsOpenFormula
                 -- Core XML (basically only for the 'id'-attribute)
               | NsXML
                 -- Fallback
               | NsOther String
  deriving ( Eq, Ord, Show )

-- | Not the actual iri's, but large prefixes of them - this way there are
-- less versioning problems and the like.
nsIDs :: [(String,Namespace)]
nsIDs = [
  ("urn:oasis:names:tc:opendocument:xmlns:animation"        , NsAnim         ),
  ("urn:oasis:names:tc:opendocument:xmlns:chart"            , NsChart        ),
  ("urn:oasis:names:tc:opendocument:xmlns:config"           , NsConfig       ),
  ("urn:oasis:names:tc:opendocument:xmlns:database"         , NsDB           ),
  ("urn:oasis:names:tc:opendocument:xmlns:dr3d"             , Ns3D           ),
  ("urn:oasis:names:tc:opendocument:xmlns:drawing"          , NsDraw         ),
  ("urn:oasis:names:tc:opendocument:xmlns:form"             , NsForm         ),
  ("urn:oasis:names:tc:opendocument:xmlns:manifest"         , NsManifest     ),
  ("urn:oasis:names:tc:opendocument:xmlns:meta"             , NsMeta         ),
  ("urn:oasis:names:tc:opendocument:xmlns:datastyle"        , NsNumber       ),
  ("urn:oasis:names:tc:opendocument:xmlns:of"               , NsOpenFormula  ),
  ("urn:oasis:names:tc:opendocument:xmlns:office:1.0"       , NsOffice       ),
  ("urn:oasis:names:tc:opendocument:xmlns:presentation"     , NsPresentation ),
  ("urn:oasis:names:tc:opendocument:xmlns:script"           , NsScript       ),
  ("urn:oasis:names:tc:opendocument:xmlns:style"            , NsStyle        ),
  ("urn:oasis:names:tc:opendocument:xmlns:table"            , NsTable        ),
  ("urn:oasis:names:tc:opendocument:xmlns:text"             , NsText         ),
  ("urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible", NsXSL_FO       ),
  ("urn:oasis:names:tc:opendocument:xmlns:smil-compatible"  , NsSmil         ),
  ("urn:oasis:names:tc:opendocument:xmlns:svg-compatible"   , NsSVG          ),
  ("http://docs.oasis-open.org/ns/office/1.2/meta/odf"      , NsODF          ),
  ("http://docs.oasis-open.org/ns/office/1.2/meta/pkg"      , NsPKG          ),
  ("http://purl.org/dc/elements"                            , NsDublinCore   ),
  ("http://www.w3.org/2003/g/data-view"                     , NsGRDDL        ),
  ("http://www.w3.org/1998/Math/MathML"                     , NsMathML       ),
  ("http://www.w3.org/1999/xhtml"                           , NsXHtml        ),
  ("http://www.w3.org/2002/xforms"                          , NsXForms       ),
  ("http://www.w3.org/1999/xlink"                           , NsXLink        )
  ]