{-# LANGUAGE Arrows #-}

-- | Parsing for the manifest section of the OPF Package XML Document
module Codec.Epub.Parse.Manifest
   ( manifestP
   )
   where

import Control.Arrow.ListArrows
import Data.Tree.NTree.TypeDefs ( NTree )
import Text.XML.HXT.Arrow.XmlArrow
import Text.XML.HXT.DOM.TypeDefs

import Codec.Epub.Data.Manifest
import Codec.Epub.Parse.Util


manifestItemP :: (ArrowXml a) => a (NTree XNode) ManifestItem
manifestItemP :: forall (a :: * -> * -> *).
ArrowXml a =>
a (NTree XNode) ManifestItem
manifestItemP= forall (a :: * -> * -> *).
ArrowXml a =>
QName -> a (NTree XNode) (NTree XNode)
atQTag (String -> QName
opfName String
"item") forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
   proc NTree XNode
x -> do
      String
i <- forall (a :: * -> * -> *).
ArrowXml a =>
String -> a (NTree XNode) String
getAttrValue String
"id" -< NTree XNode
x
      String
h <- forall (a :: * -> * -> *).
ArrowXml a =>
String -> a (NTree XNode) String
getAttrValue String
"href" -< NTree XNode
x
      String
m <- forall (a :: * -> * -> *).
ArrowXml a =>
String -> a (NTree XNode) String
getAttrValue String
"media-type" -< NTree XNode
x
      forall (a :: * -> * -> *) b. Arrow a => a b b
returnA -< String -> String -> String -> ManifestItem
ManifestItem String
i String
h String
m


manifestP :: (ArrowXml a) => a (NTree XNode) Manifest
manifestP :: forall (a :: * -> * -> *). ArrowXml a => a (NTree XNode) Manifest
manifestP = forall (a :: * -> * -> *).
ArrowXml a =>
QName -> a (NTree XNode) (NTree XNode)
atQTag (String -> QName
opfName String
"manifest") forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
   proc NTree XNode
x -> do     
      [ManifestItem]
l <- forall (a :: * -> * -> *) b c. ArrowList a => a b c -> a b [c]
listA forall (a :: * -> * -> *).
ArrowXml a =>
a (NTree XNode) ManifestItem
manifestItemP -< NTree XNode
x
      forall (a :: * -> * -> *) b. Arrow a => a b b
returnA -< [ManifestItem] -> Manifest
Manifest [ManifestItem]
l