{-# LANGUAGE Arrows #-}

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

import Control.Arrow.ListArrows ( (>>>), listA, returnA )
import Data.Tree.NTree.TypeDefs ( NTree )
import Text.XML.HXT.Arrow.XmlArrow ( ArrowXml, getAttrValue )
import Text.XML.HXT.DOM.TypeDefs ( XNode )

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= QName -> a (NTree XNode) (NTree XNode)
forall (a :: * -> * -> *).
ArrowXml a =>
QName -> a (NTree XNode) (NTree XNode)
atQTag (String -> QName
opfName String
"item") a (NTree XNode) (NTree XNode)
-> a (NTree XNode) ManifestItem -> a (NTree XNode) ManifestItem
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 <- String -> a (NTree XNode) String
forall (a :: * -> * -> *).
ArrowXml a =>
String -> a (NTree XNode) String
getAttrValue String
"id" -< NTree XNode
x
      String
h <- String -> a (NTree XNode) String
forall (a :: * -> * -> *).
ArrowXml a =>
String -> a (NTree XNode) String
getAttrValue String
"href" -< NTree XNode
x
      String
m <- String -> a (NTree XNode) String
forall (a :: * -> * -> *).
ArrowXml a =>
String -> a (NTree XNode) String
getAttrValue String
"media-type" -< NTree XNode
x
      a ManifestItem ManifestItem
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 = QName -> a (NTree XNode) (NTree XNode)
forall (a :: * -> * -> *).
ArrowXml a =>
QName -> a (NTree XNode) (NTree XNode)
atQTag (String -> QName
opfName String
"manifest") a (NTree XNode) (NTree XNode)
-> a (NTree XNode) Manifest -> a (NTree XNode) 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 <- a (NTree XNode) ManifestItem -> a (NTree XNode) [ManifestItem]
forall b c. a b c -> a b [c]
forall (a :: * -> * -> *) b c. ArrowList a => a b c -> a b [c]
listA a (NTree XNode) ManifestItem
forall (a :: * -> * -> *).
ArrowXml a =>
a (NTree XNode) ManifestItem
manifestItemP -< NTree XNode
x
      a Manifest Manifest
forall (a :: * -> * -> *) b. Arrow a => a b b
returnA -< [ManifestItem] -> Manifest
Manifest [ManifestItem]
l