--------------------------------------------------------------------
-- |
-- Module    : Text.Atom.Feed.Export
-- Copyright : (c) Galois, Inc. 2008,
--             (c) Sigbjorn Finne 2009-
-- License   : BSD3
--
-- Maintainer: Sigbjorn Finne <sof@forkIO.com>
-- Stability : provisional
-- Portability:: portable
-- Description: Convert from Atom to XML
--
-- Convert from Atom to XML
--
--------------------------------------------------------------------
module Text.Atom.Feed.Export
  ( atom_prefix
  , atom_thr_prefix
  , atomNS
  , atomThreadNS
  , xmlns_atom
  , xmlns_atom_thread
  , atomName
  , atomAttr
  , atomNode
  , atomLeaf
  , atomThreadName
  , atomThreadAttr
  , atomThreadNode
  , atomThreadLeaf
  , xmlFeed
  , textFeed
  , xmlEntry
  , xmlContent
  , xmlCategory
  , xmlLink
  , xmlSource
  , xmlGenerator
  , xmlAuthor
  , xmlContributor
  , xmlPerson
  , xmlInReplyTo
  , xmlInReplyTotal
  , xmlId
  , xmlIcon
  , xmlLogo
  , xmlUpdated
  , xmlPublished
  , xmlRights
  , xmlTitle
  , xmlSubtitle
  , xmlSummary
  , xmlTextContent
  , mb
  ) where

import Prelude.Compat

import Data.Text (Text, pack)
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Util as U
import Data.XML.Types as XML
import Text.Atom.Feed

atom_prefix :: Maybe Text
atom_prefix :: Maybe Text
atom_prefix = Maybe Text
forall a. Maybe a
Nothing -- Just "atom"

atom_thr_prefix :: Maybe Text
atom_thr_prefix :: Maybe Text
atom_thr_prefix = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"thr"

atomNS :: Text
atomNS :: Text
atomNS = Text
"http://www.w3.org/2005/Atom"

atomThreadNS :: Text
atomThreadNS :: Text
atomThreadNS = Text
"http://purl.org/syndication/thread/1.0"

blank_element :: Name -> [Node] -> XML.Element
blank_element :: Name -> [Node] -> Element
blank_element Name
name = Name -> [(Name, [Content])] -> [Node] -> Element
XML.Element Name
name []

xmlns_atom :: Attr
xmlns_atom :: (Name, [Content])
xmlns_atom = (Name
qn, [Text -> Content
ContentText Text
atomNS])
  where
    qn :: Name
qn =
      case Maybe Text
atom_prefix of
        Maybe Text
Nothing -> Name :: Text -> Maybe Text -> Maybe Text -> Name
Name {nameLocalName :: Text
nameLocalName = Text
"xmlns", nameNamespace :: Maybe Text
nameNamespace = Maybe Text
forall a. Maybe a
Nothing, namePrefix :: Maybe Text
namePrefix = Maybe Text
forall a. Maybe a
Nothing}
        Just Text
s ->
          Name :: Text -> Maybe Text -> Maybe Text -> Name
Name
            { nameLocalName :: Text
nameLocalName = Text
s
            , nameNamespace :: Maybe Text
nameNamespace = Maybe Text
forall a. Maybe a
Nothing -- XXX: is this ok?
            , namePrefix :: Maybe Text
namePrefix = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"xmlns"
            }

xmlns_atom_thread :: Attr
xmlns_atom_thread :: (Name, [Content])
xmlns_atom_thread = (Name
qn, [Text -> Content
ContentText Text
atomThreadNS])
  where
    qn :: Name
qn =
      case Maybe Text
atom_prefix of
        Maybe Text
Nothing -> Name :: Text -> Maybe Text -> Maybe Text -> Name
Name {nameLocalName :: Text
nameLocalName = Text
"xmlns", nameNamespace :: Maybe Text
nameNamespace = Maybe Text
forall a. Maybe a
Nothing, namePrefix :: Maybe Text
namePrefix = Maybe Text
forall a. Maybe a
Nothing}
        Just Text
s ->
          Name :: Text -> Maybe Text -> Maybe Text -> Name
Name
            { nameLocalName :: Text
nameLocalName = Text
s
            , nameNamespace :: Maybe Text
nameNamespace = Maybe Text
forall a. Maybe a
Nothing -- XXX: is this ok?
            , namePrefix :: Maybe Text
namePrefix = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"xmlns"
            }

atomName :: Text -> Name
atomName :: Text -> Name
atomName Text
nc = Name :: Text -> Maybe Text -> Maybe Text -> Name
Name {nameLocalName :: Text
nameLocalName = Text
nc, nameNamespace :: Maybe Text
nameNamespace = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
atomNS, namePrefix :: Maybe Text
namePrefix = Maybe Text
atom_prefix}

atomAttr :: Text -> Text -> Attr
atomAttr :: Text -> Text -> (Name, [Content])
atomAttr Text
x Text
y =
  (Name :: Text -> Maybe Text -> Maybe Text -> Name
Name {nameLocalName :: Text
nameLocalName = Text
x, nameNamespace :: Maybe Text
nameNamespace = Maybe Text
forall a. Maybe a
Nothing, namePrefix :: Maybe Text
namePrefix = Maybe Text
atom_prefix}, [Text -> Content
ContentText Text
y])

atomNode :: Text -> [Node] -> XML.Element
atomNode :: Text -> [Node] -> Element
atomNode Text
x = Name -> [Node] -> Element
blank_element (Text -> Name
atomName Text
x)

atomLeaf :: Text -> Text -> XML.Element
atomLeaf :: Text -> Text -> Element
atomLeaf Text
tag Text
txt = Name -> [Node] -> Element
blank_element (Text -> Name
atomName Text
tag) [Content -> Node
NodeContent (Content -> Node) -> Content -> Node
forall a b. (a -> b) -> a -> b
$ Text -> Content
ContentText Text
txt]

atomThreadName :: Text -> Name
atomThreadName :: Text -> Name
atomThreadName Text
nc =
  Name :: Text -> Maybe Text -> Maybe Text -> Name
Name {nameLocalName :: Text
nameLocalName = Text
nc, nameNamespace :: Maybe Text
nameNamespace = Text -> Maybe Text
forall a. a -> Maybe a
Just Text
atomThreadNS, namePrefix :: Maybe Text
namePrefix = Maybe Text
atom_thr_prefix}

atomThreadAttr :: Text -> Text -> Attr
atomThreadAttr :: Text -> Text -> (Name, [Content])
atomThreadAttr Text
x Text
y = (Text -> Name
atomThreadName Text
x, [Text -> Content
ContentText Text
y])

atomThreadNode :: Text -> [Node] -> XML.Element
atomThreadNode :: Text -> [Node] -> Element
atomThreadNode Text
x = Name -> [Node] -> Element
blank_element (Text -> Name
atomThreadName Text
x)

atomThreadLeaf :: Text -> Text -> XML.Element
atomThreadLeaf :: Text -> Text -> Element
atomThreadLeaf Text
tag Text
txt = Name -> [Node] -> Element
blank_element (Text -> Name
atomThreadName Text
tag) [Content -> Node
NodeContent (Content -> Node) -> Content -> Node
forall a b. (a -> b) -> a -> b
$ Text -> Content
ContentText Text
txt]

--------------------------------------------------------------------------------
xmlFeed :: Feed -> XML.Element
xmlFeed :: Feed -> Element
xmlFeed Feed
f =
  (Text -> [Node] -> Element
atomNode Text
"feed" ([Node] -> Element) -> [Node] -> Element
forall a b. (a -> b) -> a -> b
$
   (Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map Element -> Node
NodeElement ([Element] -> [Node]) -> [Element] -> [Node]
forall a b. (a -> b) -> a -> b
$
   [TextContent -> Element
xmlTitle (Feed -> TextContent
feedTitle Feed
f)] [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   [Text -> Element
xmlId (Feed -> Text
feedId Feed
f)] [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   [Text -> Element
xmlUpdated (Feed -> Text
feedUpdated Feed
f)] [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Link -> Element) -> [Link] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Link -> Element
xmlLink (Feed -> [Link]
feedLinks Feed
f) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Person -> Element) -> [Person] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Person -> Element
xmlAuthor (Feed -> [Person]
feedAuthors Feed
f) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Category -> Element) -> [Category] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Category -> Element
xmlCategory (Feed -> [Category]
feedCategories Feed
f) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Person -> Element) -> [Person] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Person -> Element
xmlContributor (Feed -> [Person]
feedContributors Feed
f) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Generator -> Element) -> Maybe Generator -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb Generator -> Element
xmlGenerator (Feed -> Maybe Generator
feedGenerator Feed
f) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb Text -> Element
xmlIcon (Feed -> Maybe Text
feedIcon Feed
f) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb Text -> Element
xmlLogo (Feed -> Maybe Text
feedLogo Feed
f) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (TextContent -> Element) -> Maybe TextContent -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb TextContent -> Element
xmlRights (Feed -> Maybe TextContent
feedRights Feed
f) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (TextContent -> Element) -> Maybe TextContent -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb TextContent -> Element
xmlSubtitle (Feed -> Maybe TextContent
feedSubtitle Feed
f) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++ (Entry -> Element) -> [Entry] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Entry -> Element
xmlEntry (Feed -> [Entry]
feedEntries Feed
f) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++ Feed -> [Element]
feedOther Feed
f)
    {elementAttributes :: [(Name, [Content])]
elementAttributes = [(Name, [Content])
xmlns_atom]}

textFeed :: Feed -> Maybe TL.Text
textFeed :: Feed -> Maybe Text
textFeed = (Feed -> Element) -> Feed -> Maybe Text
forall a. (a -> Element) -> a -> Maybe Text
U.renderFeed Feed -> Element
xmlFeed

xmlEntry :: Entry -> XML.Element
xmlEntry :: Entry -> Element
xmlEntry Entry
e =
  (Text -> [Node] -> Element
atomNode Text
"entry" ([Node] -> Element) -> [Node] -> Element
forall a b. (a -> b) -> a -> b
$
   (Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map Element -> Node
NodeElement ([Element] -> [Node]) -> [Element] -> [Node]
forall a b. (a -> b) -> a -> b
$
   [Text -> Element
xmlId (Entry -> Text
entryId Entry
e)] [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   [TextContent -> Element
xmlTitle (Entry -> TextContent
entryTitle Entry
e)] [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   [Text -> Element
xmlUpdated (Entry -> Text
entryUpdated Entry
e)] [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Person -> Element) -> [Person] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Person -> Element
xmlAuthor (Entry -> [Person]
entryAuthors Entry
e) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Category -> Element) -> [Category] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Category -> Element
xmlCategory (Entry -> [Category]
entryCategories Entry
e) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (EntryContent -> Element) -> Maybe EntryContent -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb EntryContent -> Element
xmlContent (Entry -> Maybe EntryContent
entryContent Entry
e) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Person -> Element) -> [Person] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Person -> Element
xmlContributor (Entry -> [Person]
entryContributor Entry
e) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Link -> Element) -> [Link] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Link -> Element
xmlLink (Entry -> [Link]
entryLinks Entry
e) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb Text -> Element
xmlPublished (Entry -> Maybe Text
entryPublished Entry
e) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (TextContent -> Element) -> Maybe TextContent -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb TextContent -> Element
xmlRights (Entry -> Maybe TextContent
entryRights Entry
e) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (Source -> Element) -> Maybe Source -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb Source -> Element
xmlSource (Entry -> Maybe Source
entrySource Entry
e) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (TextContent -> Element) -> Maybe TextContent -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb TextContent -> Element
xmlSummary (Entry -> Maybe TextContent
entrySummary Entry
e) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
   (InReplyTo -> Element) -> Maybe InReplyTo -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb InReplyTo -> Element
xmlInReplyTo (Entry -> Maybe InReplyTo
entryInReplyTo Entry
e) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++ (InReplyTotal -> Element) -> Maybe InReplyTotal -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb InReplyTotal -> Element
xmlInReplyTotal (Entry -> Maybe InReplyTotal
entryInReplyTotal Entry
e) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++ Entry -> [Element]
entryOther Entry
e)
    {elementAttributes :: [(Name, [Content])]
elementAttributes = Entry -> [(Name, [Content])]
entryAttrs Entry
e}

xmlContent :: EntryContent -> XML.Element
xmlContent :: EntryContent -> Element
xmlContent EntryContent
cont =
  case EntryContent
cont of
    TextContent Text
t -> (Text -> Text -> Element
atomLeaf Text
"content" Text
t) {elementAttributes :: [(Name, [Content])]
elementAttributes = [Text -> Text -> (Name, [Content])
atomAttr Text
"type" Text
"text"]}
    HTMLContent Text
t -> (Text -> Text -> Element
atomLeaf Text
"content" Text
t) {elementAttributes :: [(Name, [Content])]
elementAttributes = [Text -> Text -> (Name, [Content])
atomAttr Text
"type" Text
"html"]}
    XHTMLContent Element
x ->
      (Text -> [Node] -> Element
atomNode Text
"content" [Element -> Node
NodeElement Element
x]) {elementAttributes :: [(Name, [Content])]
elementAttributes = [Text -> Text -> (Name, [Content])
atomAttr Text
"type" Text
"xhtml"]}
    MixedContent Maybe Text
mbTy [Node]
cs -> (Text -> [Node] -> Element
atomNode Text
"content" [Node]
cs) {elementAttributes :: [(Name, [Content])]
elementAttributes = (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomAttr Text
"type") Maybe Text
mbTy}
    ExternalContent Maybe Text
mbTy Text
src ->
      (Text -> [Node] -> Element
atomNode Text
"content" []) {elementAttributes :: [(Name, [Content])]
elementAttributes = Text -> Text -> (Name, [Content])
atomAttr Text
"src" Text
src (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
forall a. a -> [a] -> [a]
: (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomAttr Text
"type") Maybe Text
mbTy}

xmlCategory :: Category -> XML.Element
xmlCategory :: Category -> Element
xmlCategory Category
c =
  (Text -> [Node] -> Element
atomNode Text
"category" ((Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map Element -> Node
NodeElement (Category -> [Element]
catOther Category
c)))
    { elementAttributes :: [(Name, [Content])]
elementAttributes =
        [Text -> Text -> (Name, [Content])
atomAttr Text
"term" (Category -> Text
catTerm Category
c)] [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomAttr Text
"scheme") (Category -> Maybe Text
catScheme Category
c) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++ (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomAttr Text
"label") (Category -> Maybe Text
catLabel Category
c)
    }

xmlLink :: Link -> XML.Element
xmlLink :: Link -> Element
xmlLink Link
l =
  (Text -> [Node] -> Element
atomNode Text
"link" ((Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map Element -> Node
NodeElement (Link -> [Element]
linkOther Link
l)))
    { elementAttributes :: [(Name, [Content])]
elementAttributes =
        [Text -> Text -> (Name, [Content])
atomAttr Text
"href" (Link -> Text
linkHref Link
l)] [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++
        (Either Text Text -> (Name, [Content]))
-> Maybe (Either Text Text) -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomAttr Text
"rel" (Text -> (Name, [Content]))
-> (Either Text Text -> Text)
-> Either Text Text
-> (Name, [Content])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Text) -> (Text -> Text) -> Either Text Text -> Text
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either Text -> Text
forall a. a -> a
id Text -> Text
forall a. a -> a
id) (Link -> Maybe (Either Text Text)
linkRel Link
l) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomAttr Text
"type") (Link -> Maybe Text
linkType Link
l) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomAttr Text
"hreflang") (Link -> Maybe Text
linkHrefLang Link
l) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomAttr Text
"title") (Link -> Maybe Text
linkTitle Link
l) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++ (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomAttr Text
"length") (Link -> Maybe Text
linkLength Link
l) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++ Link -> [(Name, [Content])]
linkAttrs Link
l
    }

xmlSource :: Source -> Element
xmlSource :: Source -> Element
xmlSource Source
s =
  Text -> [Node] -> Element
atomNode Text
"source" ([Node] -> Element) -> [Node] -> Element
forall a b. (a -> b) -> a -> b
$
  (Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map Element -> Node
NodeElement ([Element] -> [Node]) -> [Element] -> [Node]
forall a b. (a -> b) -> a -> b
$
  Source -> [Element]
sourceOther Source
s [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
  (Person -> Element) -> [Person] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Person -> Element
xmlAuthor (Source -> [Person]
sourceAuthors Source
s) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
  (Category -> Element) -> [Category] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Category -> Element
xmlCategory (Source -> [Category]
sourceCategories Source
s) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
  (Generator -> Element) -> Maybe Generator -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb Generator -> Element
xmlGenerator (Source -> Maybe Generator
sourceGenerator Source
s) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
  (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb Text -> Element
xmlIcon (Source -> Maybe Text
sourceIcon Source
s) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
  (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb Text -> Element
xmlId (Source -> Maybe Text
sourceId Source
s) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
  (Link -> Element) -> [Link] -> [Element]
forall a b. (a -> b) -> [a] -> [b]
map Link -> Element
xmlLink (Source -> [Link]
sourceLinks Source
s) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
  (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb Text -> Element
xmlLogo (Source -> Maybe Text
sourceLogo Source
s) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
  (TextContent -> Element) -> Maybe TextContent -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb TextContent -> Element
xmlRights (Source -> Maybe TextContent
sourceRights Source
s) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
  (TextContent -> Element) -> Maybe TextContent -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb TextContent -> Element
xmlSubtitle (Source -> Maybe TextContent
sourceSubtitle Source
s) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
  (TextContent -> Element) -> Maybe TextContent -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb TextContent -> Element
xmlTitle (Source -> Maybe TextContent
sourceTitle Source
s) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++ (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb Text -> Element
xmlUpdated (Source -> Maybe Text
sourceUpdated Source
s)

xmlGenerator :: Generator -> Element
xmlGenerator :: Generator -> Element
xmlGenerator Generator
g =
  (Text -> Text -> Element
atomLeaf Text
"generator" (Generator -> Text
genText Generator
g))
    {elementAttributes :: [(Name, [Content])]
elementAttributes = (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomAttr Text
"uri") (Generator -> Maybe Text
genURI Generator
g) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++ (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomAttr Text
"version") (Generator -> Maybe Text
genVersion Generator
g)}

xmlAuthor :: Person -> XML.Element
xmlAuthor :: Person -> Element
xmlAuthor Person
p = Text -> [Node] -> Element
atomNode Text
"author" (Person -> [Node]
xmlPerson Person
p)

xmlContributor :: Person -> XML.Element
xmlContributor :: Person -> Element
xmlContributor Person
c = Text -> [Node] -> Element
atomNode Text
"contributor" (Person -> [Node]
xmlPerson Person
c)

xmlPerson :: Person -> [XML.Node]
xmlPerson :: Person -> [Node]
xmlPerson Person
p =
  (Element -> Node) -> [Element] -> [Node]
forall a b. (a -> b) -> [a] -> [b]
map Element -> Node
NodeElement ([Element] -> [Node]) -> [Element] -> [Node]
forall a b. (a -> b) -> a -> b
$
  [Text -> Text -> Element
atomLeaf Text
"name" (Person -> Text
personName Person
p)] [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++
  (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
atomLeaf Text
"uri") (Person -> Maybe Text
personURI Person
p) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++ (Text -> Element) -> Maybe Text -> [Element]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> Element
atomLeaf Text
"email") (Person -> Maybe Text
personEmail Person
p) [Element] -> [Element] -> [Element]
forall a. [a] -> [a] -> [a]
++ Person -> [Element]
personOther Person
p

xmlInReplyTo :: InReplyTo -> XML.Element
xmlInReplyTo :: InReplyTo -> Element
xmlInReplyTo InReplyTo
irt =
  (Text -> [Node] -> Element
atomThreadNode Text
"in-reply-to" (InReplyTo -> [Node]
replyToContent InReplyTo
irt))
    { elementAttributes :: [(Name, [Content])]
elementAttributes =
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomThreadAttr Text
"ref") (Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Text -> Maybe Text
forall a b. (a -> b) -> a -> b
$ InReplyTo -> Text
replyToRef InReplyTo
irt) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomThreadAttr Text
"href") (InReplyTo -> Maybe Text
replyToHRef InReplyTo
irt) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomThreadAttr Text
"type") (InReplyTo -> Maybe Text
replyToType InReplyTo
irt) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++
        (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
forall a b. (a -> b) -> Maybe a -> [b]
mb (Text -> Text -> (Name, [Content])
atomThreadAttr Text
"source") (InReplyTo -> Maybe Text
replyToSource InReplyTo
irt) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
forall a. [a] -> [a] -> [a]
++ InReplyTo -> [(Name, [Content])]
replyToOther InReplyTo
irt
    }

xmlInReplyTotal :: InReplyTotal -> XML.Element
xmlInReplyTotal :: InReplyTotal -> Element
xmlInReplyTotal InReplyTotal
irt =
  (Text -> Text -> Element
atomThreadLeaf Text
"total" (String -> Text
pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Integer -> String
forall a. Show a => a -> String
show (Integer -> String) -> Integer -> String
forall a b. (a -> b) -> a -> b
$ InReplyTotal -> Integer
replyToTotal InReplyTotal
irt))
    {elementAttributes :: [(Name, [Content])]
elementAttributes = InReplyTotal -> [(Name, [Content])]
replyToTotalOther InReplyTotal
irt}

xmlId :: Text -> XML.Element
xmlId :: Text -> Element
xmlId = Text -> Text -> Element
atomLeaf Text
"id"

xmlIcon :: URI -> XML.Element
xmlIcon :: Text -> Element
xmlIcon = Text -> Text -> Element
atomLeaf Text
"icon"

xmlLogo :: URI -> XML.Element
 = Text -> Text -> Element
atomLeaf Text
"logo"

xmlUpdated :: Date -> XML.Element
xmlUpdated :: Text -> Element
xmlUpdated = Text -> Text -> Element
atomLeaf Text
"updated"

xmlPublished :: Date -> XML.Element
xmlPublished :: Text -> Element
xmlPublished = Text -> Text -> Element
atomLeaf Text
"published"

xmlRights :: TextContent -> XML.Element
xmlRights :: TextContent -> Element
xmlRights = Text -> TextContent -> Element
xmlTextContent Text
"rights"

xmlTitle :: TextContent -> XML.Element
xmlTitle :: TextContent -> Element
xmlTitle = Text -> TextContent -> Element
xmlTextContent Text
"title"

xmlSubtitle :: TextContent -> XML.Element
xmlSubtitle :: TextContent -> Element
xmlSubtitle = Text -> TextContent -> Element
xmlTextContent Text
"subtitle"

xmlSummary :: TextContent -> XML.Element
xmlSummary :: TextContent -> Element
xmlSummary = Text -> TextContent -> Element
xmlTextContent Text
"summary"

xmlTextContent :: Text -> TextContent -> XML.Element
xmlTextContent :: Text -> TextContent -> Element
xmlTextContent Text
tg TextContent
t =
  case TextContent
t of
    TextString Text
s -> (Text -> Text -> Element
atomLeaf Text
tg Text
s) {elementAttributes :: [(Name, [Content])]
elementAttributes = [Text -> Text -> (Name, [Content])
atomAttr Text
"type" Text
"text"]}
    HTMLString Text
s -> (Text -> Text -> Element
atomLeaf Text
tg Text
s) {elementAttributes :: [(Name, [Content])]
elementAttributes = [Text -> Text -> (Name, [Content])
atomAttr Text
"type" Text
"html"]}
    XHTMLString Element
e ->
      (Text -> [Node] -> Element
atomNode Text
tg [Element -> Node
XML.NodeElement Element
e]) {elementAttributes :: [(Name, [Content])]
elementAttributes = [Text -> Text -> (Name, [Content])
atomAttr Text
"type" Text
"xhtml"]}

--------------------------------------------------------------------------------
mb :: (a -> b) -> Maybe a -> [b]
mb :: (a -> b) -> Maybe a -> [b]
mb a -> b
_ Maybe a
Nothing = []
mb a -> b
f (Just a
x) = [a -> b
f a
x]