{-# LANGUAGE TypeOperators , UnicodeSyntax #-} module Rakka.Attachment ( Attachment(..) ) where import Control.Arrow import Control.Arrow.ArrowList import Control.Arrow.ListArrow import Control.Arrow.Unicode import System.IO.Unsafe import Text.XML.HXT.Arrow.ReadDocument import Text.XML.HXT.Arrow.WriteDocument import Text.XML.HXT.Arrow.XmlArrow import Text.XML.HXT.Arrow.XmlState import Text.XML.HXT.DOM.TypeDefs class Attachment τ where serializeToXmlTree ∷ (ArrowChoice (⇝), ArrowXml (⇝)) ⇒ τ ⇝ XmlTree deserializeFromXmlTree ∷ (ArrowChoice (⇝), ArrowXml (⇝)) ⇒ XmlTree ⇝ τ -- FIXME: String? Am I okay with that? serializeToString ∷ τ → String serializeToString attachment = do [xmlStr] ← runLA ( constA attachment ⋙ serializeToXmlTree ⋙ writeDocumentToString [ withIndent yes ] ) () return xmlStr deserializeFromString ∷ String → τ deserializeFromString source = unsafePerformIO $ do [ret] ← runX ( setErrorMsgHandler False fail ⋙ readString [ withValidate no , withCheckNamespaces yes , withRemoveWS yes ] source ⋙ deserializeFromXmlTree ) return ret