-- ------------------------------------------------------------

{- |
   Module     : Text.XML.HXT.Arrow.GeneralEntitySubstitution
   Copyright  : Copyright (C) 2005 Uwe Schmidt
   License    : MIT

   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
   Stability  : experimental
   Portability: portable

   general entity substitution

-}

-- ------------------------------------------------------------

module Text.XML.HXT.Arrow.GeneralEntitySubstitution
    ( processGeneralEntities )
where

import Control.Arrow                            -- arrow classes
import Control.Arrow.ArrowList
import Control.Arrow.ArrowIf
import Control.Arrow.ArrowTree

import Text.XML.HXT.DOM.Interface

import Text.XML.HXT.Arrow.XmlArrow
import Text.XML.HXT.Arrow.XmlState

import Text.XML.HXT.Arrow.ParserInterface
    ( parseXmlEntityValueAsAttrValue
    , parseXmlEntityValueAsContent
    )

import Text.XML.HXT.Arrow.Edit
    ( transfCharRef
    )

import Text.XML.HXT.Arrow.DocumentInput
    ( getXmlEntityContents
    )

import qualified Data.Map as M
    ( Map
    , empty
    , lookup
    , insert
    )

-- ------------------------------------------------------------

data GEContext
    = ReferenceInContent
    | ReferenceInAttributeValue
    | ReferenceInEntityValue
    -- or OccursInAttributeValue                                -- not used during substitution but during validation
    -- or ReferenceInDTD                                        -- not used: syntax check detects errors

type GESubstArrow       = GEContext -> RecList -> GEArrow XmlTree XmlTree

type GEArrow b c        = IOStateArrow GEEnv b c

type RecList            = [String]

-- ------------------------------------------------------------

newtype GEEnv   = GEEnv (M.Map String GESubstArrow)

emptyGeEnv      :: GEEnv
emptyGeEnv :: GEEnv
emptyGeEnv      = Map String GESubstArrow -> GEEnv
GEEnv Map String GESubstArrow
forall k a. Map k a
M.empty

lookupGeEnv     :: String -> GEEnv -> Maybe GESubstArrow
lookupGeEnv :: String -> GEEnv -> Maybe GESubstArrow
lookupGeEnv String
k (GEEnv Map String GESubstArrow
env)
    = String -> Map String GESubstArrow -> Maybe GESubstArrow
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup String
k Map String GESubstArrow
env

addGeEntry      :: String -> GESubstArrow -> GEEnv -> GEEnv
addGeEntry :: String -> GESubstArrow -> GEEnv -> GEEnv
addGeEntry String
k GESubstArrow
a (GEEnv Map String GESubstArrow
env)
    = Map String GESubstArrow -> GEEnv
GEEnv (Map String GESubstArrow -> GEEnv)
-> Map String GESubstArrow -> GEEnv
forall a b. (a -> b) -> a -> b
$ String
-> GESubstArrow
-> Map String GESubstArrow
-> Map String GESubstArrow
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert String
k GESubstArrow
a Map String GESubstArrow
env

-- ------------------------------------------------------------

-- |
-- substitution of general entities
--
-- input: a complete document tree including root node

processGeneralEntities  :: IOStateArrow s XmlTree XmlTree
processGeneralEntities :: IOStateArrow s XmlTree XmlTree
processGeneralEntities
    = ( Int -> String -> IOStateArrow s XmlTree XmlTree
forall s b. Int -> String -> IOStateArrow s b b
traceMsg Int
1 String
"processGeneralEntities: collect and substitute general entities"
        IOStateArrow s XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
        GEEnv
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree
forall s1 b c s0. s1 -> IOStateArrow s1 b c -> IOStateArrow s0 b c
withOtherUserState GEEnv
emptyGeEnv (IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) (t :: * -> *) b.
(ArrowTree a, Tree t) =>
a (t b) (t b) -> a (t b) (t b)
processChildren (GESubstArrow
processGeneralEntity GEContext
ReferenceInContent []))
        IOStateArrow s XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
        String -> IOStateArrow s XmlTree XmlTree
forall s. String -> IOStateArrow s XmlTree XmlTree
setDocumentStatusFromSystemState String
"in general entity processing"
        IOStateArrow s XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
        IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
traceTree
        IOStateArrow s XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
        IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
traceSource
      )
      IOStateArrow s XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowIf a => a b b -> a b c -> a b b
`when`
      IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
documentStatusOk


processGeneralEntity    :: GESubstArrow
processGeneralEntity :: GESubstArrow
processGeneralEntity GEContext
context [String]
recl
    = [IfThen
   (IOStateArrow GEEnv XmlTree XmlTree)
   (IOStateArrow GEEnv XmlTree XmlTree)]
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b c d.
ArrowIf a =>
[IfThen (a b c) (a b d)] -> a b d
choiceA [ IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
isElem          IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IfThen
     (IOStateArrow GEEnv XmlTree XmlTree)
     (IOStateArrow GEEnv XmlTree XmlTree)
forall a b. a -> b -> IfThen a b
:-> ( IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
a XmlTree XmlTree -> a XmlTree XmlTree
processAttrl (IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) (t :: * -> *) b.
(ArrowTree a, Tree t) =>
a (t b) (t b) -> a (t b) (t b)
processChildren IOStateArrow GEEnv XmlTree XmlTree
substEntitiesInAttrValue)
                                      IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
                                      IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) (t :: * -> *) b.
(ArrowTree a, Tree t) =>
a (t b) (t b) -> a (t b) (t b)
processChildren (GESubstArrow
processGeneralEntity GEContext
context [String]
recl)
                                    )
              , IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
isEntityRef     IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IfThen
     (IOStateArrow GEEnv XmlTree XmlTree)
     (IOStateArrow GEEnv XmlTree XmlTree)
forall a b. a -> b -> IfThen a b
:-> IOStateArrow GEEnv XmlTree XmlTree
substEntityRef
              , IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *). ArrowDTD a => a XmlTree XmlTree
isDTDDoctype    IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IfThen
     (IOStateArrow GEEnv XmlTree XmlTree)
     (IOStateArrow GEEnv XmlTree XmlTree)
forall a b. a -> b -> IfThen a b
:-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) (t :: * -> *) b.
(ArrowTree a, Tree t) =>
a (t b) (t b) -> a (t b) (t b)
processChildren (GESubstArrow
processGeneralEntity GEContext
context [String]
recl)
              , IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *). ArrowDTD a => a XmlTree XmlTree
isDTDEntity     IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IfThen
     (IOStateArrow GEEnv XmlTree XmlTree)
     (IOStateArrow GEEnv XmlTree XmlTree)
forall a b. a -> b -> IfThen a b
:-> IOStateArrow GEEnv XmlTree XmlTree
addEntityDecl
              , IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *). ArrowDTD a => a XmlTree XmlTree
isDTDAttlist    IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IfThen
     (IOStateArrow GEEnv XmlTree XmlTree)
     (IOStateArrow GEEnv XmlTree XmlTree)
forall a b. a -> b -> IfThen a b
:-> IOStateArrow GEEnv XmlTree XmlTree
substEntitiesInAttrDefaultValue
              , IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b. ArrowList a => a b b
this            IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IfThen
     (IOStateArrow GEEnv XmlTree XmlTree)
     (IOStateArrow GEEnv XmlTree XmlTree)
forall a b. a -> b -> IfThen a b
:-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b. ArrowList a => a b b
this
              ]
    where
    addEntityDecl       :: GEArrow XmlTree XmlTree
    addEntityDecl :: IOStateArrow GEEnv XmlTree XmlTree
addEntityDecl
        = IOSLA (XIOState GEEnv) XmlTree Any
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b c -> a b b
perform ( [IfThen
   (IOStateArrow GEEnv XmlTree XmlTree)
   (IOSLA (XIOState GEEnv) XmlTree Any)]
-> IOSLA (XIOState GEEnv) XmlTree Any
forall (a :: * -> * -> *) b c d.
ArrowIf a =>
[IfThen (a b c) (a b d)] -> a b d
choiceA [ IOStateArrow GEEnv XmlTree XmlTree
isIntern          IOStateArrow GEEnv XmlTree XmlTree
-> IOSLA (XIOState GEEnv) XmlTree Any
-> IfThen
     (IOStateArrow GEEnv XmlTree XmlTree)
     (IOSLA (XIOState GEEnv) XmlTree Any)
forall a b. a -> b -> IfThen a b
:-> IOSLA (XIOState GEEnv) XmlTree Any
forall b. GEArrow XmlTree b
addInternalEntity           -- don't change sequence of cases
                            , IOStateArrow GEEnv XmlTree XmlTree
isExtern          IOStateArrow GEEnv XmlTree XmlTree
-> IOSLA (XIOState GEEnv) XmlTree Any
-> IfThen
     (IOStateArrow GEEnv XmlTree XmlTree)
     (IOSLA (XIOState GEEnv) XmlTree Any)
forall a b. a -> b -> IfThen a b
:-> IOSLA (XIOState GEEnv) XmlTree Any
forall b. GEArrow XmlTree b
addExternalEntity
                            , IOStateArrow GEEnv XmlTree XmlTree
forall b. IOSLA (XIOState GEEnv) b b
isUnparsed        IOStateArrow GEEnv XmlTree XmlTree
-> IOSLA (XIOState GEEnv) XmlTree Any
-> IfThen
     (IOStateArrow GEEnv XmlTree XmlTree)
     (IOSLA (XIOState GEEnv) XmlTree Any)
forall a b. a -> b -> IfThen a b
:-> IOSLA (XIOState GEEnv) XmlTree Any
forall b. GEArrow XmlTree b
addUnparsedEntity
                            ]
                  )
        where
        isIntern :: IOStateArrow GEEnv XmlTree XmlTree
isIntern        = IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b c
none IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowIf a => a b b -> a b c -> a b b
`when` String -> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowDTD a =>
String -> a XmlTree XmlTree
hasDTDAttr String
k_system
        isExtern :: IOStateArrow GEEnv XmlTree XmlTree
isExtern        = IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b c
none IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowIf a => a b b -> a b c -> a b b
`when` String -> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowDTD a =>
String -> a XmlTree XmlTree
hasDTDAttr String
k_ndata
        isUnparsed :: IOSLA (XIOState GEEnv) b b
isUnparsed      = IOSLA (XIOState GEEnv) b b
forall (a :: * -> * -> *) b. ArrowList a => a b b
this

    addInternalEntity   :: GEArrow XmlTree b
    addInternalEntity :: GEArrow XmlTree b
addInternalEntity
        = String -> String -> GEArrow XmlTree b
forall b c. String -> String -> IOSLA (XIOState GEEnv) b c
insertInternal (String -> String -> GEArrow XmlTree b)
-> IOSLA (XIOState GEEnv) XmlTree (String, String)
-> GEArrow XmlTree b
forall (a :: * -> * -> *) c1 c2 b d.
ArrowList a =>
(c1 -> c2 -> a b d) -> a b (c1, c2) -> a b d
$<<
          ( ( String -> IOSLA (XIOState GEEnv) XmlTree String
forall (a :: * -> * -> *). ArrowDTD a => String -> a XmlTree String
getDTDAttrValue String
a_name
              IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) String String
-> IOSLA (XIOState GEEnv) XmlTree String
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
              Int -> (String -> String) -> IOSLA (XIOState GEEnv) String String
forall b s. Int -> (b -> String) -> IOStateArrow s b b
traceValue Int
2 ((String
"processGeneralEntity: general entity definition for " String -> String -> String
forall a. [a] -> [a] -> [a]
++) (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
forall a. Show a => a -> String
show)
            )
            IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) XmlTree (String, String)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&&
            IOStateArrow GEEnv XmlTree XmlTree
-> IOSLA (XIOState GEEnv) XmlTree String
forall (a :: * -> * -> *) n.
ArrowXml a =>
a n XmlTree -> a n String
xshow (IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) (t :: * -> *) b.
(ArrowTree a, Tree t) =>
a (t b) (t b)
getChildren IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
isText)
          )
        where
        insertInternal :: String -> String -> IOSLA (XIOState GEEnv) b c
insertInternal String
entity String
contents
            = (String -> GESubstArrow) -> String -> GEArrow b b
forall b. (String -> GESubstArrow) -> String -> GEArrow b b
insertEntity (String -> String -> GESubstArrow
substInternal String
contents) String
entity
              GEArrow b b
-> IOSLA (XIOState GEEnv) b c -> IOSLA (XIOState GEEnv) b c
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
              IOSLA (XIOState GEEnv) b c
forall (a :: * -> * -> *) b c. ArrowList a => a b c
none

    addExternalEntity   :: GEArrow XmlTree b
    addExternalEntity :: GEArrow XmlTree b
addExternalEntity
        = String -> String -> GEArrow XmlTree b
forall b c. String -> String -> IOSLA (XIOState GEEnv) b c
insertExternal (String -> String -> GEArrow XmlTree b)
-> IOSLA (XIOState GEEnv) XmlTree (String, String)
-> GEArrow XmlTree b
forall (a :: * -> * -> *) c1 c2 b d.
ArrowList a =>
(c1 -> c2 -> a b d) -> a b (c1, c2) -> a b d
$<<
          ( ( String -> IOSLA (XIOState GEEnv) XmlTree String
forall (a :: * -> * -> *). ArrowDTD a => String -> a XmlTree String
getDTDAttrValue String
a_name
              IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) String String
-> IOSLA (XIOState GEEnv) XmlTree String
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
              Int -> (String -> String) -> IOSLA (XIOState GEEnv) String String
forall b s. Int -> (b -> String) -> IOStateArrow s b b
traceValue Int
2 ((String
"processGeneralEntity: external entity definition for " String -> String -> String
forall a. [a] -> [a] -> [a]
++) (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
forall a. Show a => a -> String
show)
            )
            IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) XmlTree (String, String)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&&
            String -> IOSLA (XIOState GEEnv) XmlTree String
forall (a :: * -> * -> *). ArrowDTD a => String -> a XmlTree String
getDTDAttrValue String
a_url                       -- the absolute URL, not the relative in attr: k_system
          )
        where
        insertExternal :: String -> String -> IOSLA (XIOState GEEnv) b c
insertExternal String
entity String
uri
            = (String -> GESubstArrow) -> String -> GEArrow b b
forall b. (String -> GESubstArrow) -> String -> GEArrow b b
insertEntity (String -> String -> GESubstArrow
substExternalParsed1Time String
uri) String
entity
              GEArrow b b
-> IOSLA (XIOState GEEnv) b c -> IOSLA (XIOState GEEnv) b c
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
              IOSLA (XIOState GEEnv) b c
forall (a :: * -> * -> *) b c. ArrowList a => a b c
none

    addUnparsedEntity   :: GEArrow XmlTree b
    addUnparsedEntity :: GEArrow XmlTree b
addUnparsedEntity
        = String -> IOSLA (XIOState GEEnv) XmlTree String
forall (a :: * -> * -> *). ArrowDTD a => String -> a XmlTree String
getDTDAttrValue String
a_name
          IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) String b -> GEArrow XmlTree b
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          Int -> (String -> String) -> IOSLA (XIOState GEEnv) String String
forall b s. Int -> (b -> String) -> IOStateArrow s b b
traceValue Int
2 ((String
"processGeneralEntity: unparsed entity definition for " String -> String -> String
forall a. [a] -> [a] -> [a]
++) (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
forall a. Show a => a -> String
show)
          IOSLA (XIOState GEEnv) String String
-> IOSLA (XIOState GEEnv) String b
-> IOSLA (XIOState GEEnv) String b
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          IOSLA
  (XIOState GEEnv) String (IOSLA (XIOState GEEnv) String String)
-> IOSLA (XIOState GEEnv) String String
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA ((String -> IOSLA (XIOState GEEnv) String String)
-> IOSLA
     (XIOState GEEnv) String (IOSLA (XIOState GEEnv) String String)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr ((String -> GESubstArrow)
-> String -> IOSLA (XIOState GEEnv) String String
forall b. (String -> GESubstArrow) -> String -> GEArrow b b
insertEntity String -> GESubstArrow
substUnparsed))
          IOSLA (XIOState GEEnv) String String
-> IOSLA (XIOState GEEnv) String b
-> IOSLA (XIOState GEEnv) String b
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          IOSLA (XIOState GEEnv) String b
forall (a :: * -> * -> *) b c. ArrowList a => a b c
none

    insertEntity        :: (String -> GESubstArrow) -> String -> GEArrow b b
    insertEntity :: (String -> GESubstArrow) -> String -> GEArrow b b
insertEntity String -> GESubstArrow
fct String
entity
        = ( IOStateArrow GEEnv b GEEnv
forall s b. IOStateArrow s b s
getUserState
            IOStateArrow GEEnv b GEEnv
-> IOSLA (XIOState GEEnv) GEEnv GEEnv -> IOStateArrow GEEnv b GEEnv
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
            IOSLA (XIOState GEEnv) GEEnv (IOSLA (XIOState GEEnv) GEEnv GEEnv)
-> IOSLA (XIOState GEEnv) GEEnv GEEnv
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA ((GEEnv -> IOSLA (XIOState GEEnv) GEEnv GEEnv)
-> IOSLA
     (XIOState GEEnv) GEEnv (IOSLA (XIOState GEEnv) GEEnv GEEnv)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr GEEnv -> IOSLA (XIOState GEEnv) GEEnv GEEnv
forall s b. GEEnv -> IOSLA (XIOState s) b b
checkDefined)
          )
          IOStateArrow GEEnv b GEEnv -> GEArrow b b -> GEArrow b b
forall (a :: * -> * -> *) b c d.
ArrowIf a =>
a b c -> a b d -> a b d
`guards`
          (String -> GESubstArrow) -> String -> GEArrow b b
forall b. (String -> GESubstArrow) -> String -> GEArrow b b
addEntity String -> GESubstArrow
fct String
entity
        where
        checkDefined :: GEEnv -> IOSLA (XIOState s) b b
checkDefined GEEnv
geEnv
            = IOSLA (XIOState s) b b
-> (GESubstArrow -> IOSLA (XIOState s) b b)
-> Maybe GESubstArrow
-> IOSLA (XIOState s) b b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IOSLA (XIOState s) b b
forall b. IOSLA (XIOState s) b b
ok GESubstArrow -> IOSLA (XIOState s) b b
forall p s b c. p -> IOSLA (XIOState s) b c
alreadyDefined (Maybe GESubstArrow -> IOSLA (XIOState s) b b)
-> (GEEnv -> Maybe GESubstArrow) -> GEEnv -> IOSLA (XIOState s) b b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> GEEnv -> Maybe GESubstArrow
lookupGeEnv String
entity (GEEnv -> IOSLA (XIOState s) b b)
-> GEEnv -> IOSLA (XIOState s) b b
forall a b. (a -> b) -> a -> b
$ GEEnv
geEnv
            where
            ok :: IOSLA (XIOState s) b b
ok  = IOSLA (XIOState s) b b
forall (a :: * -> * -> *) b. ArrowList a => a b b
this
            alreadyDefined :: p -> IOSLA (XIOState s) b c
alreadyDefined p
_
                = String -> IOStateArrow s b b
forall s b. String -> IOStateArrow s b b
issueWarn (String
"entity " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
entity String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" already defined, repeated definition ignored")
                  IOStateArrow s b b
-> IOSLA (XIOState s) b c -> IOSLA (XIOState s) b c
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
                  IOSLA (XIOState s) b c
forall (a :: * -> * -> *) b c. ArrowList a => a b c
none

    addEntity   :: (String -> GESubstArrow) -> String -> GEArrow b b
    addEntity :: (String -> GESubstArrow) -> String -> GEArrow b b
addEntity String -> GESubstArrow
fct String
entity
        = (b -> GEEnv -> GEEnv) -> GEArrow b b
forall b s. (b -> s -> s) -> IOStateArrow s b b
changeUserState b -> GEEnv -> GEEnv
forall p. p -> GEEnv -> GEEnv
ins
        where
        ins :: p -> GEEnv -> GEEnv
ins p
_ GEEnv
geEnv = String -> GESubstArrow -> GEEnv -> GEEnv
addGeEntry String
entity (String -> GESubstArrow
fct String
entity) GEEnv
geEnv

    substEntitiesInAttrDefaultValue     :: GEArrow XmlTree XmlTree
    substEntitiesInAttrDefaultValue :: IOStateArrow GEEnv XmlTree XmlTree
substEntitiesInAttrDefaultValue
        = IOSLA (XIOState GEEnv) XmlTree (IOStateArrow GEEnv XmlTree XmlTree)
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA ( IOStateArrow GEEnv XmlTree XmlTree
-> IOSLA (XIOState GEEnv) XmlTree String
forall (a :: * -> * -> *) n.
ArrowXml a =>
a n XmlTree -> a n String
xshow ( String -> IOSLA (XIOState GEEnv) XmlTree String
forall (a :: * -> * -> *). ArrowDTD a => String -> a XmlTree String
getDTDAttrValue String
a_default                    -- parse the default value
                           IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) String XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>                                          -- substitute entities
                           IOSLA (XIOState GEEnv) String XmlTree
forall (a :: * -> * -> *). ArrowXml a => a String XmlTree
mkText                                       -- and convert value into a string
                           IOSLA (XIOState GEEnv) String XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOSLA (XIOState GEEnv) String XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
                           String -> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> a XmlTree XmlTree
parseXmlEntityValueAsAttrValue String
"default value of attribute"
                           IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>                                         
                           IOStateArrow GEEnv XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
filterErrorMsg
                           IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
                           IOStateArrow GEEnv XmlTree XmlTree
substEntitiesInAttrValue
                         )
                   IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA
     (XIOState GEEnv) String (IOStateArrow GEEnv XmlTree XmlTree)
-> IOSLA
     (XIOState GEEnv) XmlTree (IOStateArrow GEEnv XmlTree XmlTree)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (String -> IOStateArrow GEEnv XmlTree XmlTree)
-> IOSLA
     (XIOState GEEnv) String (IOStateArrow GEEnv XmlTree XmlTree)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (String -> String -> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowDTD a =>
String -> String -> a XmlTree XmlTree
setDTDAttrValue String
a_default)
                 )
          IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowIf a => a b b -> a b c -> a b b
`when` String -> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowDTD a =>
String -> a XmlTree XmlTree
hasDTDAttr String
a_default

    substEntitiesInAttrValue    :: GEArrow XmlTree XmlTree
    substEntitiesInAttrValue :: IOStateArrow GEEnv XmlTree XmlTree
substEntitiesInAttrValue
        = ( GESubstArrow
processGeneralEntity GEContext
ReferenceInAttributeValue [String]
recl
            IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowIf a => a b b -> a b c -> a b b
`when`
            IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
isEntityRef
          )
          IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          (String -> String) -> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
(String -> String) -> a XmlTree XmlTree
changeText String -> String
normalizeWhiteSpace
          IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
transfCharRef
        where
        normalizeWhiteSpace :: String -> String
normalizeWhiteSpace = (Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map ( \Char
c -> if Char
c Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
"\n\t\r" then Char
' ' else Char
c )


    substEntityRef      :: GEArrow XmlTree XmlTree
    substEntityRef :: IOStateArrow GEEnv XmlTree XmlTree
substEntityRef
        = IOSLA (XIOState GEEnv) XmlTree (IOStateArrow GEEnv XmlTree XmlTree)
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA ( ( ( IOSLA (XIOState GEEnv) XmlTree String
forall (a :: * -> * -> *). ArrowXml a => a XmlTree String
getEntityRef                             -- get the entity name and the env
                       IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) String String
-> IOSLA (XIOState GEEnv) XmlTree String
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>                                      -- and compute the arrow to be applied
                       Int -> (String -> String) -> IOSLA (XIOState GEEnv) String String
forall b s. Int -> (b -> String) -> IOStateArrow s b b
traceValue Int
2 ((String
"processGeneralEntity: entity reference for entity " String -> String -> String
forall a. [a] -> [a] -> [a]
++) (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
forall a. Show a => a -> String
show)
                       IOSLA (XIOState GEEnv) String String
-> IOSLA (XIOState GEEnv) String String
-> IOSLA (XIOState GEEnv) String String
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
                       Int -> String -> IOSLA (XIOState GEEnv) String String
forall s b. Int -> String -> IOStateArrow s b b
traceMsg Int
3 (String
"recursion list = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ [String] -> String
forall a. Show a => a -> String
show [String]
recl)
                     )
                     IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) XmlTree GEEnv
-> IOSLA (XIOState GEEnv) XmlTree (String, GEEnv)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&&
                     IOSLA (XIOState GEEnv) XmlTree GEEnv
forall s b. IOStateArrow s b s
getUserState
                   ) IOSLA (XIOState GEEnv) XmlTree (String, GEEnv)
-> IOSLA
     (XIOState GEEnv)
     (String, GEEnv)
     (IOStateArrow GEEnv XmlTree XmlTree)
-> IOSLA
     (XIOState GEEnv) XmlTree (IOStateArrow GEEnv XmlTree XmlTree)
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
                   (String -> GEEnv -> IOStateArrow GEEnv XmlTree XmlTree)
-> IOSLA
     (XIOState GEEnv)
     (String, GEEnv)
     (IOStateArrow GEEnv XmlTree XmlTree)
forall (a :: * -> * -> *) b1 b2 c.
ArrowList a =>
(b1 -> b2 -> c) -> a (b1, b2) c
arr2 String -> GEEnv -> IOStateArrow GEEnv XmlTree XmlTree
substA
                 )
          where
          substA        :: String -> GEEnv -> GEArrow XmlTree XmlTree
          substA :: String -> GEEnv -> IOStateArrow GEEnv XmlTree XmlTree
substA String
entity GEEnv
geEnv
              = IOStateArrow GEEnv XmlTree XmlTree
-> (GESubstArrow -> IOStateArrow GEEnv XmlTree XmlTree)
-> Maybe GESubstArrow
-> IOStateArrow GEEnv XmlTree XmlTree
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IOStateArrow GEEnv XmlTree XmlTree
forall s b. IOStateArrow s b b
entityNotFound GESubstArrow -> IOStateArrow GEEnv XmlTree XmlTree
forall s b.
(GEContext -> [String] -> IOStateArrow s b b) -> IOStateArrow s b b
entityFound (Maybe GESubstArrow -> IOStateArrow GEEnv XmlTree XmlTree)
-> (GEEnv -> Maybe GESubstArrow)
-> GEEnv
-> IOStateArrow GEEnv XmlTree XmlTree
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> GEEnv -> Maybe GESubstArrow
lookupGeEnv String
entity (GEEnv -> IOStateArrow GEEnv XmlTree XmlTree)
-> GEEnv -> IOStateArrow GEEnv XmlTree XmlTree
forall a b. (a -> b) -> a -> b
$ GEEnv
geEnv
              where
              errMsg :: String -> IOStateArrow s b b
errMsg String
msg
                  = String -> IOStateArrow s b b
forall s b. String -> IOStateArrow s b b
issueErr String
msg

              entityNotFound :: IOStateArrow s b b
entityNotFound
                  = String -> IOStateArrow s b b
forall s b. String -> IOStateArrow s b b
errMsg (String
"general entity reference \"&" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
entity String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
";\" not processed, no definition found, (forward reference?)")

              entityFound :: (GEContext -> [String] -> IOStateArrow s b b) -> IOStateArrow s b b
entityFound GEContext -> [String] -> IOStateArrow s b b
fct
                  | String
entity String -> [String] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [String]
recl
                      = String -> IOStateArrow s b b
forall s b. String -> IOStateArrow s b b
errMsg (String
"general entity reference \"&" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
entity String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
";\" not processed, cyclic definition")
                  | Bool
otherwise
                      = GEContext -> [String] -> IOStateArrow s b b
fct GEContext
context [String]
recl

    substExternalParsed1Time                            :: String -> String -> GESubstArrow
    substExternalParsed1Time :: String -> String -> GESubstArrow
substExternalParsed1Time String
uri String
entity GEContext
cx [String]
rl
        = IOSLA (XIOState GEEnv) XmlTree String
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b c -> a b b
perform ( Int -> String -> IOStateArrow GEEnv XmlTree XmlTree
forall s b. Int -> String -> IOStateArrow s b b
traceMsg Int
2 (String
"substExternalParsed1Time: read and parse external parsed entity " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
entity)
                    IOStateArrow GEEnv XmlTree XmlTree
-> IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) XmlTree String
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
                    IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) XmlTree String
forall s b c. IOStateArrow s b c -> IOStateArrow s b c
runInLocalURIContext ( [IOStateArrow GEEnv XmlTree XmlTree]
-> [IOStateArrow GEEnv XmlTree XmlTree]
-> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) n.
ArrowXml a =>
[a n XmlTree] -> [a n XmlTree] -> a n XmlTree
root [String -> String -> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) n.
ArrowXml a =>
String -> String -> a n XmlTree
sattr String
a_source String
uri] []         -- uri must be an absolute uri
                                           IOStateArrow GEEnv XmlTree XmlTree
-> IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) XmlTree String
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>                                  -- abs uri is computed during parameter entity handling
                                           IOStateArrow GEEnv XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
getXmlEntityContents
                                           IOStateArrow GEEnv XmlTree XmlTree
-> IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) XmlTree String
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
                                           IOSLA (XIOState GEEnv) XmlTree String
forall s. IOStateArrow s XmlTree String
processExternalEntityContents
                                         )
                    IOSLA (XIOState GEEnv) XmlTree String
-> IOSLA (XIOState GEEnv) String String
-> IOSLA (XIOState GEEnv) XmlTree String
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
                    IOSLA
  (XIOState GEEnv) String (IOSLA (XIOState GEEnv) String String)
-> IOSLA (XIOState GEEnv) String String
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA ( (String -> IOSLA (XIOState GEEnv) String String)
-> IOSLA
     (XIOState GEEnv) String (IOSLA (XIOState GEEnv) String String)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr ((String -> IOSLA (XIOState GEEnv) String String)
 -> IOSLA
      (XIOState GEEnv) String (IOSLA (XIOState GEEnv) String String))
-> (String -> IOSLA (XIOState GEEnv) String String)
-> IOSLA
     (XIOState GEEnv) String (IOSLA (XIOState GEEnv) String String)
forall a b. (a -> b) -> a -> b
$ \ String
s -> (String -> GESubstArrow)
-> String -> IOSLA (XIOState GEEnv) String String
forall b. (String -> GESubstArrow) -> String -> GEArrow b b
addEntity (String -> String -> GESubstArrow
substExternalParsed String
s) String
entity )
                  )
          IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          GESubstArrow
processGeneralEntity GEContext
cx [String]
rl
        where
        processExternalEntityContents   :: IOStateArrow s XmlTree String
        processExternalEntityContents :: IOStateArrow s XmlTree String
processExternalEntityContents
            = ( ( ( IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
documentStatusOk                              -- reading entity succeeded
                    IOSLA (XIOState s) XmlTree XmlTree
-> IOSLA (XIOState s) XmlTree XmlTree
-> IOSLA (XIOState s) XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>                                           -- with content stored in a text node
                    (IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *) (t :: * -> *) b.
(ArrowTree a, Tree t) =>
a (t b) (t b)
getChildren IOSLA (XIOState s) XmlTree XmlTree
-> IOSLA (XIOState s) XmlTree XmlTree
-> IOSLA (XIOState s) XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
isText)
                  )
                  IOSLA (XIOState s) XmlTree XmlTree
-> IOSLA (XIOState s) XmlTree XmlTree
-> IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *) b c d.
ArrowIf a =>
a b c -> a b d -> a b d
`guards`
                  IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *) b. ArrowList a => a b b
this
                )
                IOSLA (XIOState s) XmlTree XmlTree
-> IOSLA (XIOState s) XmlTree XmlTree
-> IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowIf a => a b c -> a b c -> a b c
`orElse`
                String -> IOSLA (XIOState s) XmlTree XmlTree
forall s b. String -> IOStateArrow s b b
issueErr (String
"illegal value for external parsed entity " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
entity)
              )
              IOSLA (XIOState s) XmlTree XmlTree
-> IOStateArrow s XmlTree String -> IOStateArrow s XmlTree String
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
              IOSLA (XIOState s) XmlTree XmlTree -> IOStateArrow s XmlTree String
forall (a :: * -> * -> *) n.
ArrowXml a =>
a n XmlTree -> a n String
xshow (IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *) (t :: * -> *) b.
(ArrowTree a, Tree t) =>
a (t b) (t b)
getChildren IOSLA (XIOState s) XmlTree XmlTree
-> IOSLA (XIOState s) XmlTree XmlTree
-> IOSLA (XIOState s) XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
isText)


    substExternalParsed                                 :: String -> String -> GESubstArrow
    substExternalParsed :: String -> String -> GESubstArrow
substExternalParsed String
s String
entity GEContext
ReferenceInContent [String]
rl  = String -> [String] -> String -> IOStateArrow GEEnv XmlTree XmlTree
includedIfValidating String
s [String]
rl String
entity
    substExternalParsed String
_ String
entity GEContext
ReferenceInAttributeValue [String]
_
                                                        = String -> String -> String -> IOStateArrow GEEnv XmlTree XmlTree
forbidden String
entity String
"external parsed general" String
"in attribute value"
    substExternalParsed String
_ String
_      GEContext
ReferenceInEntityValue [String]
_
                                                        = IOStateArrow GEEnv XmlTree XmlTree
bypassed

    substInternal                                       :: String -> String -> GESubstArrow
    substInternal :: String -> String -> GESubstArrow
substInternal String
s String
entity GEContext
ReferenceInContent [String]
rl        = String -> [String] -> String -> IOStateArrow GEEnv XmlTree XmlTree
included          String
s [String]
rl String
entity
    substInternal String
s String
entity GEContext
ReferenceInAttributeValue [String]
rl = String -> [String] -> String -> IOStateArrow GEEnv XmlTree XmlTree
includedInLiteral String
s [String]
rl String
entity
    substInternal String
_ String
_      GEContext
ReferenceInEntityValue [String]
_     = IOStateArrow GEEnv XmlTree XmlTree
bypassed

    substUnparsed                                       :: String -> GESubstArrow
    substUnparsed :: String -> GESubstArrow
substUnparsed String
entity GEContext
ReferenceInContent        [String]
_    = String -> String -> String -> IOStateArrow GEEnv XmlTree XmlTree
forbidden String
entity String
"unparsed" String
"content"
    substUnparsed String
entity GEContext
ReferenceInAttributeValue [String]
_    = String -> String -> String -> IOStateArrow GEEnv XmlTree XmlTree
forbidden String
entity String
"unparsed" String
"attribute value"
    substUnparsed String
entity GEContext
ReferenceInEntityValue    [String]
_    = String -> String -> String -> IOStateArrow GEEnv XmlTree XmlTree
forbidden String
entity String
"unparsed" String
"entity value"

                                                                        -- XML 1.0 chapter 4.4.2
    included            :: String -> RecList -> String -> GEArrow XmlTree XmlTree
    included :: String -> [String] -> String -> IOStateArrow GEEnv XmlTree XmlTree
included String
s [String]
rl String
entity
        = Int -> String -> IOStateArrow GEEnv XmlTree XmlTree
forall s b. Int -> String -> IOStateArrow s b b
traceMsg Int
3 (String
"substituting general entity " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
entity String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" with value " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
s)
          IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          String -> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) n. ArrowXml a => String -> a n XmlTree
txt String
s
          IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          String -> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> a XmlTree XmlTree
parseXmlEntityValueAsContent (String
"substituting general entity " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
entity String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" in contents")
          IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          IOStateArrow GEEnv XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
filterErrorMsg
          IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          GESubstArrow
processGeneralEntity GEContext
context (String
entity String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
rl)

                                                                        -- XML 1.0 chapter 4.4.3
    includedIfValidating                :: String -> RecList -> String -> GEArrow XmlTree XmlTree
    includedIfValidating :: String -> [String] -> String -> IOStateArrow GEEnv XmlTree XmlTree
includedIfValidating
        = String -> [String] -> String -> IOStateArrow GEEnv XmlTree XmlTree
included
                                                                        -- XML 1.0 chapter 4.4.4
    forbidden           :: String -> String -> String -> GEArrow XmlTree XmlTree
    forbidden :: String -> String -> String -> IOStateArrow GEEnv XmlTree XmlTree
forbidden String
entity String
msg String
cx
        = String -> IOStateArrow GEEnv XmlTree XmlTree
forall s b. String -> IOStateArrow s b b
issueErr (String
"reference of " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
msg String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
entity String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" forbidden in " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
cx)

                                                                        -- XML 1.0 chapter 4.4.5
    includedInLiteral           :: String -> RecList -> String -> GEArrow XmlTree XmlTree
    includedInLiteral :: String -> [String] -> String -> IOStateArrow GEEnv XmlTree XmlTree
includedInLiteral String
s [String]
rl String
entity
        = String -> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) n. ArrowXml a => String -> a n XmlTree
txt String
s
          IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          String -> IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> a XmlTree XmlTree
parseXmlEntityValueAsAttrValue (String
"substituting general entity " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
entity String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" in attribute value")
          IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          IOStateArrow GEEnv XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
filterErrorMsg
          IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
-> IOStateArrow GEEnv XmlTree XmlTree
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
          GESubstArrow
processGeneralEntity GEContext
context (String
entity String -> [String] -> [String]
forall a. a -> [a] -> [a]
: [String]
rl)
                                                                        -- XML 1.0 chapter 4.4.7
    bypassed            :: GEArrow XmlTree XmlTree
    bypassed :: IOStateArrow GEEnv XmlTree XmlTree
bypassed
        = IOStateArrow GEEnv XmlTree XmlTree
forall (a :: * -> * -> *) b. ArrowList a => a b b
this

-- ------------------------------------------------------------