module Text.XML.HXT.Arrow.DocumentInput
( getXmlContents
, getXmlEntityContents
, getEncoding
, getTextEncoding
, decodeDocument
, addInputError
)
where
import Control.Arrow
import Control.Arrow.ArrowIf
import Control.Arrow.ArrowIO
import Control.Arrow.ArrowList
import Control.Arrow.ArrowTree
import Control.Arrow.ListArrow
import Data.List (isPrefixOf)
import Data.String.Unicode (getDecodingFct,
guessEncoding,
normalizeNL)
import System.FilePath (takeExtension)
import qualified Text.XML.HXT.IO.GetFILE as FILE
import Text.XML.HXT.DOM.Interface
import Text.XML.HXT.Arrow.ParserInterface (parseXmlDocEncodingSpec, parseXmlEntityEncodingSpec,
removeEncodingSpec)
import Text.XML.HXT.Arrow.XmlArrow
import Text.XML.HXT.Arrow.XmlState
import Text.XML.HXT.Arrow.XmlState.TypeDefs
protocolHandlers :: AssocList String (IOStateArrow s XmlTree XmlTree)
protocolHandlers :: AssocList String (IOStateArrow s XmlTree XmlTree)
protocolHandlers
= [ (String
"file", IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
getFileContents)
, (String
"http", IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
getHttpContents)
, (String
"https", IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
getHttpContents)
, (String
"stdin", IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
getStdinContents)
]
getProtocolHandler :: IOStateArrow s String (IOStateArrow s XmlTree XmlTree)
getProtocolHandler :: IOStateArrow s String (IOStateArrow s XmlTree XmlTree)
getProtocolHandler
= (String -> IOStateArrow s XmlTree XmlTree)
-> IOStateArrow s String (IOStateArrow s XmlTree XmlTree)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (\ String
s -> IOStateArrow s XmlTree XmlTree
-> String
-> AssocList String (IOStateArrow s XmlTree XmlTree)
-> IOStateArrow s XmlTree XmlTree
forall k v. Eq k => v -> k -> AssocList k v -> v
lookupDef IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
getUnsupported String
s AssocList String (IOStateArrow s XmlTree XmlTree)
forall s. AssocList String (IOStateArrow s XmlTree XmlTree)
protocolHandlers)
getUnsupported :: IOStateArrow s XmlTree XmlTree
getUnsupported :: IOStateArrow s XmlTree XmlTree
getUnsupported
= IOSLA (XIOState s) XmlTree String -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b c -> a b b
perform ( String -> IOSLA (XIOState s) XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
a_source
IOSLA (XIOState s) XmlTree String
-> IOSLA (XIOState s) String String
-> IOSLA (XIOState 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
>>>
(String -> String) -> IOSLA (XIOState s) String String
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr ((String
"unsupported protocol in URI " 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 s) String String
-> IOSLA (XIOState s) String String
-> IOSLA (XIOState s) String 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) String (IOSLA (XIOState s) String String)
-> IOSLA (XIOState s) String String
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA ((String -> IOSLA (XIOState s) String String)
-> IOSLA (XIOState s) String (IOSLA (XIOState s) String String)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr String -> IOSLA (XIOState s) String String
forall s b. String -> IOStateArrow s b b
issueFatal)
)
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
"accessing documents"
getStringContents :: IOStateArrow s XmlTree XmlTree
getStringContents :: IOStateArrow s XmlTree XmlTree
getStringContents
= String -> IOStateArrow s XmlTree XmlTree
forall (cat :: * -> * -> *).
ArrowXml cat =>
String -> cat XmlTree XmlTree
setCont (String -> IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) XmlTree String
-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) c b d.
ArrowList a =>
(c -> a b d) -> a b c -> a b d
$< String -> IOSLA (XIOState s) XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
a_source
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 -> String -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr String
transferMessage String
"OK"
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 -> String -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr String
transferStatus String
"200"
where
setCont :: String -> cat XmlTree XmlTree
setCont String
contents
= cat XmlTree XmlTree -> cat XmlTree XmlTree
forall (a :: * -> * -> *) (t :: * -> *) b.
(ArrowTree a, Tree t) =>
a (t b) (t b) -> a (t b) (t b)
replaceChildren (String -> cat XmlTree XmlTree
forall (a :: * -> * -> *) n. ArrowXml a => String -> a n XmlTree
txt String
contents')
cat XmlTree XmlTree -> cat XmlTree XmlTree -> cat 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 -> cat XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr String
transferURI (Int -> String -> String
forall a. Int -> [a] -> [a]
take Int
7 String
contents)
cat XmlTree XmlTree -> cat XmlTree XmlTree -> cat 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 -> cat XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr String
a_source (String -> String
forall a. Show a => a -> String
show (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> String -> String
prefix Int
48 (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String
contents')
where
contents' :: String
contents' = Int -> String -> String
forall a. Int -> [a] -> [a]
drop (String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
stringProtocol) String
contents
prefix :: Int -> String -> String
prefix Int
l String
s
| String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
s' Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
l = Int -> String -> String
forall a. Int -> [a] -> [a]
take (Int
l Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
3) String
s' String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"..."
| Bool
otherwise = String
s'
where
s' :: String
s' = Int -> String -> String
forall a. Int -> [a] -> [a]
take (Int
l Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) String
s
getFileContents :: IOStateArrow s XmlTree XmlTree
getFileContents :: IOStateArrow s XmlTree XmlTree
getFileContents
= IOSLA (XIOState s) XmlTree (IOStateArrow s XmlTree XmlTree)
-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA ( ( Selector XIOSysState Bool -> IOStateArrow s XmlTree Bool
forall c s b. Selector XIOSysState c -> IOStateArrow s b c
getSysVar Selector XIOSysState Bool
theStrictInput
IOStateArrow s XmlTree Bool
-> IOSLA (XIOState s) XmlTree String
-> IOSLA (XIOState s) XmlTree (Bool, String)
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&&
( String -> IOSLA (XIOState s) XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
transferURI
IOSLA (XIOState s) XmlTree String
-> IOSLA (XIOState s) String String
-> IOSLA (XIOState 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) String String
forall (a :: * -> * -> *). ArrowList a => a String String
getPathFromURI
)
)
IOSLA (XIOState s) XmlTree (Bool, String)
-> IOSLA
(XIOState s) (Bool, String) (IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) 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
>>>
Int
-> ((Bool, String) -> String)
-> IOStateArrow s (Bool, String) (Bool, String)
forall b s. Int -> (b -> String) -> IOStateArrow s b b
traceValue Int
2 (\ (Bool
b, String
f) -> String
"read file " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
f String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" (strict input = " String -> String -> String
forall a. [a] -> [a] -> [a]
++ Bool -> String
forall a. Show a => a -> String
show Bool
b String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
")")
IOStateArrow s (Bool, String) (Bool, String)
-> IOSLA
(XIOState s) (Bool, String) (IOStateArrow s XmlTree XmlTree)
-> IOSLA
(XIOState s) (Bool, String) (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
>>>
((Bool, String)
-> IO (Either ([(String, String)], String) ByteString))
-> IOSLA
(XIOState s)
(Bool, String)
(Either ([(String, String)], String) ByteString)
forall (a :: * -> * -> *) b c. ArrowIO a => (b -> IO c) -> a b c
arrIO ((Bool
-> String -> IO (Either ([(String, String)], String) ByteString))
-> (Bool, String)
-> IO (Either ([(String, String)], String) ByteString)
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Bool
-> String -> IO (Either ([(String, String)], String) ByteString)
FILE.getCont)
IOSLA
(XIOState s)
(Bool, String)
(Either ([(String, String)], String) ByteString)
-> IOSLA
(XIOState s)
(Either ([(String, String)], String) ByteString)
(IOStateArrow s XmlTree XmlTree)
-> IOSLA
(XIOState s) (Bool, String) (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, String)], String) -> IOStateArrow s XmlTree XmlTree)
-> IOSLA
(XIOState s)
([(String, String)], String)
(IOStateArrow s XmlTree XmlTree)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (([(String, String)] -> String -> IOStateArrow s XmlTree XmlTree)
-> ([(String, String)], String) -> IOStateArrow s XmlTree XmlTree
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry [(String, String)] -> String -> IOStateArrow s XmlTree XmlTree
forall s.
[(String, String)] -> String -> IOStateArrow s XmlTree XmlTree
addInputError)
IOSLA
(XIOState s)
([(String, String)], String)
(IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) ByteString (IOStateArrow s XmlTree XmlTree)
-> IOSLA
(XIOState s)
(Either ([(String, String)], String) ByteString)
(IOStateArrow s XmlTree XmlTree)
forall (a :: * -> * -> *) b d c.
ArrowChoice a =>
a b d -> a c d -> a (Either b c) d
|||
(ByteString -> IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) ByteString (IOStateArrow s XmlTree XmlTree)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr ByteString -> IOStateArrow s XmlTree XmlTree
forall s. ByteString -> IOStateArrow s XmlTree XmlTree
addTxtContent
)
)
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
addMimeType
getStdinContents :: IOStateArrow s XmlTree XmlTree
getStdinContents :: IOStateArrow s XmlTree XmlTree
getStdinContents
= IOSLA (XIOState s) XmlTree (IOStateArrow s XmlTree XmlTree)
-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA ( Selector XIOSysState Bool -> IOStateArrow s XmlTree Bool
forall c s b. Selector XIOSysState c -> IOStateArrow s b c
getSysVar Selector XIOSysState Bool
theStrictInput
IOStateArrow s XmlTree Bool
-> IOSLA (XIOState s) Bool (IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) 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
>>>
(Bool -> IO (Either ([(String, String)], String) ByteString))
-> IOSLA
(XIOState s) Bool (Either ([(String, String)], String) ByteString)
forall (a :: * -> * -> *) b c. ArrowIO a => (b -> IO c) -> a b c
arrIO Bool -> IO (Either ([(String, String)], String) ByteString)
FILE.getStdinCont
IOSLA
(XIOState s) Bool (Either ([(String, String)], String) ByteString)
-> IOSLA
(XIOState s)
(Either ([(String, String)], String) ByteString)
(IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) Bool (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, String)], String) -> IOStateArrow s XmlTree XmlTree)
-> IOSLA
(XIOState s)
([(String, String)], String)
(IOStateArrow s XmlTree XmlTree)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr (([(String, String)] -> String -> IOStateArrow s XmlTree XmlTree)
-> ([(String, String)], String) -> IOStateArrow s XmlTree XmlTree
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry [(String, String)] -> String -> IOStateArrow s XmlTree XmlTree
forall s.
[(String, String)] -> String -> IOStateArrow s XmlTree XmlTree
addInputError)
IOSLA
(XIOState s)
([(String, String)], String)
(IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) ByteString (IOStateArrow s XmlTree XmlTree)
-> IOSLA
(XIOState s)
(Either ([(String, String)], String) ByteString)
(IOStateArrow s XmlTree XmlTree)
forall (a :: * -> * -> *) b d c.
ArrowChoice a =>
a b d -> a c d -> a (Either b c) d
|||
(ByteString -> IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) ByteString (IOStateArrow s XmlTree XmlTree)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr ByteString -> IOStateArrow s XmlTree XmlTree
forall s. ByteString -> IOStateArrow s XmlTree XmlTree
addTxtContent
)
)
addInputError :: Attributes -> String -> IOStateArrow s XmlTree XmlTree
addInputError :: [(String, String)] -> String -> IOStateArrow s XmlTree XmlTree
addInputError [(String, String)]
al String
e
= String -> IOStateArrow s XmlTree XmlTree
forall s b. String -> IOStateArrow s b b
issueFatal String
e
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] -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b. ArrowList a => [a b b] -> a b b
seqA (((String, String) -> IOStateArrow s XmlTree XmlTree)
-> [(String, String)] -> [IOStateArrow s XmlTree XmlTree]
forall a b. (a -> b) -> [a] -> [b]
map ((String -> String -> IOStateArrow s XmlTree XmlTree)
-> (String, String) -> IOStateArrow s XmlTree XmlTree
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry String -> String -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr) [(String, String)]
al)
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
"accessing documents"
addMimeType :: IOStateArrow s XmlTree XmlTree
addMimeType :: IOStateArrow s XmlTree XmlTree
addMimeType
= String -> IOStateArrow s XmlTree XmlTree
forall (cat :: * -> * -> *).
ArrowXml cat =>
String -> cat XmlTree XmlTree
addMime (String -> IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) XmlTree String
-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) c b d.
ArrowList a =>
(c -> a b d) -> a b c -> a b d
$< ( ( Selector XIOSysState String -> IOSLA (XIOState s) XmlTree String
forall c s b. Selector XIOSysState c -> IOStateArrow s b c
getSysVar Selector XIOSysState String
theFileMimeType
IOSLA (XIOState s) XmlTree String
-> IOSLA (XIOState s) String String
-> IOSLA (XIOState 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
>>>
(String -> Bool) -> IOSLA (XIOState s) String String
forall (a :: * -> * -> *) b. ArrowList a => (b -> Bool) -> a b b
isA (Bool -> Bool
not (Bool -> Bool) -> (String -> Bool) -> String -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null)
)
IOSLA (XIOState s) XmlTree String
-> IOSLA (XIOState s) XmlTree String
-> IOSLA (XIOState s) XmlTree String
forall (a :: * -> * -> *) b c. ArrowIf a => a b c -> a b c -> a b c
`orElse`
( String -> IOSLA (XIOState s) XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
transferURI
IOSLA (XIOState s) XmlTree String
-> IOSLA (XIOState s) String String
-> IOSLA (XIOState 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
>>>
( MimeTypeTable -> IOSLA (XIOState s) String String
forall (a :: * -> * -> *).
Arrow a =>
MimeTypeTable -> a String String
uriToMime (MimeTypeTable -> IOSLA (XIOState s) String String)
-> IOSLA (XIOState s) String MimeTypeTable
-> IOSLA (XIOState s) String String
forall (a :: * -> * -> *) c b d.
ArrowList a =>
(c -> a b d) -> a b c -> a b d
$< IOSLA (XIOState s) String MimeTypeTable
forall s b. IOStateArrow s b MimeTypeTable
getMimeTypeTable )
)
)
where
addMime :: String -> a XmlTree XmlTree
addMime String
mt
= String -> String -> a XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr String
transferMimeType String
mt
uriToMime :: MimeTypeTable -> a String String
uriToMime MimeTypeTable
mtt
= (String -> String) -> a String String
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr ((String -> String) -> a String String)
-> (String -> String) -> a String String
forall a b. (a -> b) -> a -> b
$ ( \ String
uri -> String -> MimeTypeTable -> String
extensionToMimeType (Int -> String -> String
forall a. Int -> [a] -> [a]
drop Int
1 (String -> String) -> (String -> String) -> String -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> String
takeExtension (String -> String) -> String -> String
forall a b. (a -> b) -> a -> b
$ String
uri) MimeTypeTable
mtt )
addTxtContent :: Blob -> IOStateArrow s XmlTree XmlTree
addTxtContent :: ByteString -> IOStateArrow s XmlTree XmlTree
addTxtContent ByteString
bc
= IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) (t :: * -> *) b.
(ArrowTree a, Tree t) =>
a (t b) (t b) -> a (t b) (t b)
replaceChildren (ByteString -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) n.
ArrowXml a =>
ByteString -> a n XmlTree
blb ByteString
bc)
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 -> String -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr String
transferMessage String
"OK"
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 -> String -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr String
transferStatus String
"200"
getHttpContents :: IOStateArrow s XmlTree XmlTree
getHttpContents :: IOStateArrow s XmlTree XmlTree
getHttpContents
= IOSArrow XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall b c s0. IOSArrow b c -> IOStateArrow s0 b c
withoutUserState (IOSArrow XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree)
-> IOSArrow XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall a b. (a -> b) -> a -> b
$ IOSLA (XIOState ()) XmlTree (IOSArrow XmlTree XmlTree)
-> IOSArrow XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA (IOSLA (XIOState ()) XmlTree (IOSArrow XmlTree XmlTree)
-> IOSArrow XmlTree XmlTree)
-> IOSLA (XIOState ()) XmlTree (IOSArrow XmlTree XmlTree)
-> IOSArrow XmlTree XmlTree
forall a b. (a -> b) -> a -> b
$ Selector XIOSysState (IOSArrow XmlTree XmlTree)
-> IOSLA (XIOState ()) XmlTree (IOSArrow XmlTree XmlTree)
forall c s b. Selector XIOSysState c -> IOStateArrow s b c
getSysVar Selector XIOSysState (IOSArrow XmlTree XmlTree)
theHttpHandler
getContentsFromString :: IOStateArrow s XmlTree XmlTree
getContentsFromString :: IOStateArrow s XmlTree XmlTree
getContentsFromString
= ( String -> IOSLA (XIOState s) XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
a_source
IOSLA (XIOState s) XmlTree String
-> IOSLA (XIOState s) String String
-> IOSLA (XIOState 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
>>>
(String -> Bool) -> IOSLA (XIOState s) String String
forall (a :: * -> * -> *) b. ArrowList a => (b -> Bool) -> a b b
isA (String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf String
stringProtocol)
)
IOSLA (XIOState s) XmlTree String
-> IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b c d.
ArrowIf a =>
a b c -> a b d -> a b d
`guards`
IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
getStringContents
getContentsFromDoc :: IOStateArrow s XmlTree XmlTree
getContentsFromDoc :: IOStateArrow s XmlTree XmlTree
getContentsFromDoc
= ( ( String -> IOStateArrow s XmlTree XmlTree
forall (cat :: * -> * -> *).
ArrowXml cat =>
String -> cat XmlTree XmlTree
addTransferURI (String -> IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) XmlTree String
-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) c b d.
ArrowList a =>
(c -> a b d) -> a b c -> a b d
$< IOSLA (XIOState s) XmlTree String
forall s b. IOStateArrow s b String
getBaseURI
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
getCont
)
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`
( String -> IOStateArrow s XmlTree XmlTree
forall s b. String -> IOStateArrow s b b
setAbsURI (String -> IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) XmlTree String
-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) c b d.
ArrowList a =>
(c -> a b d) -> a b c -> a b d
$< ( String -> IOSLA (XIOState s) XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
a_source
IOSLA (XIOState s) XmlTree String
-> (String -> String) -> IOSLA (XIOState s) XmlTree String
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^
( \ String
src-> (if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
src then String
"stdin:" else String
src) )
)
)
)
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
"getContentsFromDoc"
where
setAbsURI :: String -> IOSLA (XIOState s) d d
setAbsURI String
src
= IOSLA (XIOState s) d String
-> IOSLA (XIOState s) d d
-> IOSLA (XIOState s) d d
-> IOSLA (XIOState s) d d
forall (a :: * -> * -> *) b c d.
ArrowIf a =>
a b c -> a b d -> a b d -> a b d
ifA ( String -> IOSLA (XIOState s) d String
forall (a :: * -> * -> *) c b. ArrowList a => c -> a b c
constA String
src IOSLA (XIOState s) d String
-> IOSLA (XIOState s) String String -> IOSLA (XIOState s) d 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) String String
forall s. IOStateArrow s String String
changeBaseURI )
IOSLA (XIOState s) d d
forall (a :: * -> * -> *) b. ArrowList a => a b b
this
( String -> IOSLA (XIOState s) d d
forall s b. String -> IOStateArrow s b b
issueFatal (String
"illegal URI : " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
src) )
addTransferURI :: String -> a XmlTree XmlTree
addTransferURI String
uri
= String -> String -> a XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr String
transferURI String
uri
getCont :: IOSLA (XIOState s) XmlTree XmlTree
getCont
= IOSLA (XIOState s) XmlTree (IOSLA (XIOState s) XmlTree XmlTree)
-> IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA ( IOStateArrow s XmlTree String
forall s b. IOStateArrow s b String
getBaseURI
IOStateArrow s XmlTree String
-> IOSLA (XIOState s) String (IOSLA (XIOState s) XmlTree XmlTree)
-> IOSLA (XIOState s) 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
>>>
Int -> (String -> String) -> IOStateArrow s String String
forall b s. Int -> (b -> String) -> IOStateArrow s b b
traceValue Int
2 ((String
"getContentsFromDoc: reading " 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)
IOStateArrow s String String
-> IOSLA (XIOState s) String (IOSLA (XIOState s) XmlTree XmlTree)
-> IOSLA (XIOState s) String (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
>>>
IOStateArrow s String String
forall (a :: * -> * -> *). ArrowList a => a String String
getSchemeFromURI
IOStateArrow s String String
-> IOSLA (XIOState s) String (IOSLA (XIOState s) XmlTree XmlTree)
-> IOSLA (XIOState s) String (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) String (IOSLA (XIOState s) XmlTree XmlTree)
forall s. IOStateArrow s String (IOStateArrow s XmlTree XmlTree)
getProtocolHandler
)
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`
IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *) b. ArrowList a => a b b
this
setBaseURIFromDoc :: IOStateArrow s XmlTree XmlTree
setBaseURIFromDoc :: IOStateArrow s XmlTree XmlTree
setBaseURIFromDoc
= IOSLA (XIOState s) XmlTree String -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b c -> a b b
perform ( String -> IOSLA (XIOState s) XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
transferURI
IOSLA (XIOState s) XmlTree String
-> IOSLA (XIOState s) String String
-> IOSLA (XIOState 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
>>>
(String -> Bool) -> IOSLA (XIOState s) String String
forall (a :: * -> * -> *) b. ArrowList a => (b -> Bool) -> a b b
isA (String -> String -> Bool
forall a. Eq a => [a] -> [a] -> Bool
isPrefixOf String
stringProtocol)
IOSLA (XIOState s) String String
-> IOSLA (XIOState s) String String
-> IOSLA (XIOState s) String 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) String String
forall s. IOStateArrow s String String
setBaseURI
)
getXmlContents :: IOStateArrow s XmlTree XmlTree
getXmlContents :: IOStateArrow s XmlTree XmlTree
getXmlContents
= IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall s.
IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
getXmlContents' IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
parseXmlDocEncodingSpec
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
setBaseURIFromDoc
getXmlEntityContents :: IOStateArrow s XmlTree XmlTree
getXmlEntityContents :: IOStateArrow s XmlTree XmlTree
getXmlEntityContents
= Int -> String -> IOStateArrow s XmlTree XmlTree
forall s b. Int -> String -> IOStateArrow s b b
traceMsg Int
2 String
"getXmlEntityContents"
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 -> String -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr String
transferMimeType String
text_xml_external_parsed_entity
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 -> IOStateArrow s XmlTree XmlTree
forall s.
IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
getXmlContents' IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
parseXmlEntityEncodingSpec
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 -> String -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr String
transferMimeType String
text_xml_external_parsed_entity
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 -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) (t :: * -> *) b.
(ArrowTree a, Tree t) =>
a (t b) (t b) -> a (t b) (t b)
processChildren
( IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
removeEncodingSpec
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 -> String) -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
(String -> String) -> a XmlTree XmlTree
changeText String -> String
normalizeNL
)
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
setBaseURIFromDoc
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
>>>
Int -> String -> IOStateArrow s XmlTree XmlTree
forall s b. Int -> String -> IOStateArrow s b b
traceMsg Int
2 String
"getXmlEntityContents done"
getXmlContents' :: IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
getXmlContents' :: IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
getXmlContents' IOStateArrow s XmlTree XmlTree
parseEncodingSpec
= ( IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
getContentsFromString
IOStateArrow s XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowIf a => a b c -> a b c -> a b c
`orElse`
( IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
getContentsFromDoc
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
>>>
[IfThen
(IOStateArrow s XmlTree XmlTree) (IOStateArrow s XmlTree XmlTree)]
-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b c d.
ArrowIf a =>
[IfThen (a b c) (a b d)] -> a b d
choiceA
[ IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
isXmlHtmlDoc IOStateArrow s XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree
-> IfThen
(IOStateArrow s XmlTree XmlTree) (IOStateArrow s XmlTree XmlTree)
forall a b. a -> b -> IfThen a b
:-> ( IOStateArrow s XmlTree XmlTree
parseEncodingSpec
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
filterErrorMsg
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
decodeDocument
)
, IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
isTextDoc IOStateArrow s XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree
-> IfThen
(IOStateArrow s XmlTree XmlTree) (IOStateArrow s XmlTree XmlTree)
forall a b. a -> b -> IfThen a b
:-> IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
decodeDocument
, IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b. ArrowList a => a b b
this IOStateArrow s XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree
-> IfThen
(IOStateArrow s XmlTree XmlTree) (IOStateArrow s XmlTree XmlTree)
forall a b. a -> b -> IfThen a b
:-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b. ArrowList a => a b b
this
]
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
>>>
IOSLA (XIOState s) XmlTree String -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b c -> a b b
perform ( String -> IOSLA (XIOState s) XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
transferURI
IOSLA (XIOState s) XmlTree String
-> IOSLA (XIOState s) String String
-> IOSLA (XIOState 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
>>>
Int -> (String -> String) -> IOSLA (XIOState s) String String
forall b s. Int -> (b -> String) -> IOStateArrow s b b
traceValue Int
1 ((String
"getXmlContents: content read and decoded 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)
)
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
traceDoc String
"getXmlContents'"
)
)
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
isRoot
isMimeDoc :: (String -> Bool) -> IOStateArrow s XmlTree XmlTree
isMimeDoc :: (String -> Bool) -> IOStateArrow s XmlTree XmlTree
isMimeDoc String -> Bool
isMT = LA XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => LA b c -> a b c
fromLA (LA XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree)
-> LA XmlTree XmlTree -> IOStateArrow s XmlTree XmlTree
forall a b. (a -> b) -> a -> b
$
( ( String -> LA XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
transferMimeType LA XmlTree String -> (String -> String) -> LA XmlTree String
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> (c -> d) -> a b d
>>^ String -> String
stringToLower )
LA XmlTree String -> LA String String -> LA XmlTree String
forall k (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
(String -> Bool) -> LA String String
forall (a :: * -> * -> *) b. ArrowList a => (b -> Bool) -> a b b
isA (\ String
t -> String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
t Bool -> Bool -> Bool
|| String -> Bool
isMT String
t)
)
LA XmlTree String -> LA XmlTree XmlTree -> LA XmlTree XmlTree
forall (a :: * -> * -> *) b c d.
ArrowIf a =>
a b c -> a b d -> a b d
`guards` LA XmlTree XmlTree
forall (a :: * -> * -> *) b. ArrowList a => a b b
this
isTextDoc, isXmlHtmlDoc :: IOStateArrow s XmlTree XmlTree
isTextDoc :: IOStateArrow s XmlTree XmlTree
isTextDoc = (String -> Bool) -> IOStateArrow s XmlTree XmlTree
forall s. (String -> Bool) -> IOStateArrow s XmlTree XmlTree
isMimeDoc String -> Bool
isTextMimeType
isXmlHtmlDoc :: IOStateArrow s XmlTree XmlTree
isXmlHtmlDoc = (String -> Bool) -> IOStateArrow s XmlTree XmlTree
forall s. (String -> Bool) -> IOStateArrow s XmlTree XmlTree
isMimeDoc (\ String
mt -> String -> Bool
isHtmlMimeType String
mt Bool -> Bool -> Bool
|| String -> Bool
isXmlMimeType String
mt)
getEncoding :: IOStateArrow s XmlTree String
getEncoding :: IOStateArrow s XmlTree String
getEncoding
= [IOStateArrow s XmlTree String] -> IOStateArrow s XmlTree String
forall (a :: * -> * -> *) b c. ArrowList a => [a b c] -> a b c
catA [ 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
IOStateArrow s XmlTree String
-> IOSLA (XIOState s) String 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
>>>
(String -> String) -> IOSLA (XIOState s) String String
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr String -> String
guessEncoding
, String -> IOStateArrow s XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
transferEncoding
, String -> IOStateArrow s XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
a_encoding
, Selector XIOSysState String -> IOStateArrow s XmlTree String
forall c s b. Selector XIOSysState c -> IOStateArrow s b c
getSysVar Selector XIOSysState String
theInputEncoding
, String -> IOStateArrow s XmlTree String
forall (a :: * -> * -> *) c b. ArrowList a => c -> a b c
constA String
utf8
]
IOStateArrow s XmlTree String
-> ([String] -> String) -> IOStateArrow s XmlTree String
forall (a :: * -> * -> *) b c d.
ArrowList a =>
a b c -> ([c] -> d) -> a b d
>. ([String] -> String
forall a. [a] -> a
head ([String] -> String)
-> ([String] -> [String]) -> [String] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> Bool) -> [String] -> [String]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (String -> Bool) -> String -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null))
getTextEncoding :: IOStateArrow s XmlTree String
getTextEncoding :: IOStateArrow s XmlTree String
getTextEncoding
= [IOStateArrow s XmlTree String] -> IOStateArrow s XmlTree String
forall (a :: * -> * -> *) b c. ArrowList a => [a b c] -> a b c
catA [ String -> IOStateArrow s XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
transferEncoding
, String -> IOStateArrow s XmlTree String
forall (a :: * -> * -> *). ArrowXml a => String -> a XmlTree String
getAttrValue String
a_encoding
, Selector XIOSysState String -> IOStateArrow s XmlTree String
forall c s b. Selector XIOSysState c -> IOStateArrow s b c
getSysVar Selector XIOSysState String
theInputEncoding
, String -> IOStateArrow s XmlTree String
forall (a :: * -> * -> *) c b. ArrowList a => c -> a b c
constA String
isoLatin1
]
IOStateArrow s XmlTree String
-> ([String] -> String) -> IOStateArrow s XmlTree String
forall (a :: * -> * -> *) b c d.
ArrowList a =>
a b c -> ([c] -> d) -> a b d
>. ([String] -> String
forall a. [a] -> a
head ([String] -> String)
-> ([String] -> [String]) -> [String] -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> Bool) -> [String] -> [String]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (String -> Bool) -> String -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null))
decodeDocument :: IOStateArrow s XmlTree XmlTree
decodeDocument :: IOStateArrow s XmlTree XmlTree
decodeDocument
= [IfThen
(IOStateArrow s XmlTree XmlTree) (IOStateArrow s XmlTree XmlTree)]
-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b c d.
ArrowIf a =>
[IfThen (a b c) (a b d)] -> a b d
choiceA
[ ( IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
isRoot 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
isXmlHtmlDoc ) IOStateArrow s XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree
-> IfThen
(IOStateArrow s XmlTree XmlTree) (IOStateArrow s XmlTree XmlTree)
forall a b. a -> b -> IfThen a b
:-> ( Bool -> IOStateArrow s XmlTree XmlTree
forall s. Bool -> IOStateArrow s XmlTree XmlTree
decodeX (Bool -> IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) XmlTree Bool
-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) c b d.
ArrowList a =>
(c -> a b d) -> a b c -> a b d
$< Selector XIOSysState Bool -> IOSLA (XIOState s) XmlTree Bool
forall c s b. Selector XIOSysState c -> IOStateArrow s b c
getSysVar Selector XIOSysState Bool
theExpat)
, ( IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *). ArrowXml a => a XmlTree XmlTree
isRoot 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
isTextDoc ) IOStateArrow s XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree
-> IfThen
(IOStateArrow s XmlTree XmlTree) (IOStateArrow s XmlTree XmlTree)
forall a b. a -> b -> IfThen a b
:-> ( String -> IOStateArrow s XmlTree XmlTree
forall s. String -> IOStateArrow s XmlTree XmlTree
decodeArr (String -> IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) XmlTree String
-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) c b d.
ArrowList a =>
(c -> a b d) -> a b c -> a b d
$< IOSLA (XIOState s) XmlTree String
forall s. IOStateArrow s XmlTree String
getTextEncoding )
, IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b. ArrowList a => a b b
this IOStateArrow s XmlTree XmlTree
-> IOStateArrow s XmlTree XmlTree
-> IfThen
(IOStateArrow s XmlTree XmlTree) (IOStateArrow s XmlTree XmlTree)
forall a b. a -> b -> IfThen a b
:-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) b. ArrowList a => a b b
this
]
where
decodeX :: Bool -> IOStateArrow s XmlTree XmlTree
decodeX :: Bool -> IOStateArrow s XmlTree XmlTree
decodeX Bool
False = String -> IOStateArrow s XmlTree XmlTree
forall s. String -> IOStateArrow s XmlTree XmlTree
decodeArr (String -> IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) XmlTree String
-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) c b d.
ArrowList a =>
(c -> a b d) -> a b c -> a b d
$< IOSLA (XIOState s) XmlTree String
forall s. IOStateArrow s XmlTree String
getEncoding
decodeX Bool
True = String -> IOStateArrow s XmlTree XmlTree
forall s. String -> IOStateArrow s XmlTree XmlTree
noDecode (String -> IOStateArrow s XmlTree XmlTree)
-> IOSLA (XIOState s) XmlTree String
-> IOStateArrow s XmlTree XmlTree
forall (a :: * -> * -> *) c b d.
ArrowList a =>
(c -> a b d) -> a b c -> a b d
$< IOSLA (XIOState s) XmlTree String
forall s. IOStateArrow s XmlTree String
getEncoding
noDecode :: String -> IOSLA (XIOState s) XmlTree XmlTree
noDecode String
enc = Int -> String -> IOSLA (XIOState s) XmlTree XmlTree
forall s b. Int -> String -> IOStateArrow s b b
traceMsg Int
2 (String
"no decoding (done by expat): encoding is " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
enc)
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
>>>
String -> String -> IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr String
transferEncoding String
enc
decodeArr :: String -> IOStateArrow s XmlTree XmlTree
decodeArr :: String -> IOStateArrow s XmlTree XmlTree
decodeArr String
enc
= IOStateArrow s XmlTree XmlTree
-> ((String -> (String, [String]))
-> IOStateArrow s XmlTree XmlTree)
-> Maybe (String -> (String, [String]))
-> IOStateArrow s XmlTree XmlTree
forall b a. b -> (a -> b) -> Maybe a -> b
maybe IOStateArrow s XmlTree XmlTree
forall s. IOStateArrow s XmlTree XmlTree
notFound (String -> (String, [String])) -> IOStateArrow s XmlTree XmlTree
forall s.
(String -> (String, [String]))
-> IOSLA (XIOState s) XmlTree XmlTree
found (Maybe (String -> (String, [String]))
-> IOStateArrow s XmlTree XmlTree)
-> (String -> Maybe (String -> (String, [String])))
-> String
-> IOStateArrow s XmlTree XmlTree
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Maybe (String -> (String, [String]))
getDecodingFct (String -> IOStateArrow s XmlTree XmlTree)
-> String -> IOStateArrow s XmlTree XmlTree
forall a b. (a -> b) -> a -> b
$ String
enc
where
found :: (String -> (String, [String]))
-> IOSLA (XIOState s) XmlTree XmlTree
found String -> (String, [String])
df
= Int -> String -> IOSLA (XIOState s) XmlTree XmlTree
forall s b. Int -> String -> IOStateArrow s b b
traceMsg Int
2 (String
"decodeDocument: encoding is " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
enc)
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
>>>
( (String -> (String, [String]))
-> Bool -> IOSLA (XIOState s) XmlTree XmlTree
forall s.
(String -> (String, [String]))
-> Bool -> IOSLA (XIOState s) XmlTree XmlTree
decodeText String -> (String, [String])
df (Bool -> IOSLA (XIOState s) XmlTree XmlTree)
-> IOSLA (XIOState s) XmlTree Bool
-> IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *) c b d.
ArrowList a =>
(c -> a b d) -> a b c -> a b d
$< Selector XIOSysState Bool -> IOSLA (XIOState s) XmlTree Bool
forall c s b. Selector XIOSysState c -> IOStateArrow s b c
getSysVar Selector XIOSysState Bool
theEncodingErrors )
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
>>>
String -> String -> IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *).
ArrowXml a =>
String -> String -> a XmlTree XmlTree
addAttr String
transferEncoding String
enc
notFound :: IOSLA (XIOState s) XmlTree XmlTree
notFound
= String -> IOSLA (XIOState s) XmlTree XmlTree
forall s b. String -> IOStateArrow s b b
issueFatal (String
"encoding scheme not supported: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> String
forall a. Show a => a -> String
show String
enc)
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
>>>
String -> IOSLA (XIOState s) XmlTree XmlTree
forall s. String -> IOStateArrow s XmlTree XmlTree
setDocumentStatusFromSystemState String
"decoding document"
decodeText :: (String -> (String, [String]))
-> Bool -> IOSLA (XIOState s) XmlTree XmlTree
decodeText String -> (String, [String])
df Bool
withEncErrors
= IOSLA (XIOState s) XmlTree XmlTree
-> IOSLA (XIOState s) XmlTree XmlTree
forall (a :: * -> * -> *) (t :: * -> *) b.
(ArrowTree a, Tree t) =>
a (t b) (t b) -> a (t b) (t b)
processChildren
( IOSLA (XIOState s) XmlTree String
forall (a :: * -> * -> *). ArrowXml a => a XmlTree String
getText
IOSLA (XIOState s) XmlTree String
-> IOSLA (XIOState s) String 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
>>> (String -> (String, [String]))
-> IOSLA (XIOState s) String (String, [String])
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr String -> (String, [String])
df
IOSLA (XIOState s) String (String, [String])
-> IOSLA (XIOState s) (String, [String]) XmlTree
-> IOSLA (XIOState s) 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, [String]) -> String
forall a b. (a, b) -> a
fst ((String, [String]) -> String)
-> IOSLA (XIOState s) String XmlTree
-> IOSLA (XIOState s) (String, [String]) XmlTree
forall (a :: * -> * -> *) b c d.
Arrow a =>
(b -> c) -> a c d -> a b d
^>> IOSLA (XIOState s) String XmlTree
forall (a :: * -> * -> *). ArrowXml a => a String XmlTree
mkText )
IOSLA (XIOState s) (String, [String]) XmlTree
-> IOSLA (XIOState s) (String, [String]) XmlTree
-> IOSLA (XIOState s) (String, [String]) XmlTree
forall (a :: * -> * -> *) b c.
ArrowPlus a =>
a b c -> a b c -> a b c
<+>
( if Bool
withEncErrors
then
( ((String, [String]) -> [String])
-> IOSLA (XIOState s) (String, [String]) String
forall (a :: * -> * -> *) b c. ArrowList a => (b -> [c]) -> a b c
arrL (String, [String]) -> [String]
forall a b. (a, b) -> b
snd
IOSLA (XIOState s) (String, [String]) String
-> IOSLA (XIOState s) String XmlTree
-> IOSLA (XIOState s) (String, [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 -> String) -> IOSLA (XIOState s) String String
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr ((String
enc 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
" encoding error" String -> String -> String
forall a. [a] -> [a] -> [a]
++))
IOSLA (XIOState s) String String
-> IOSLA (XIOState s) String XmlTree
-> IOSLA (XIOState s) String 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) String (IOSLA (XIOState s) String String)
-> IOSLA (XIOState s) String String
forall (a :: * -> * -> *) b c. ArrowList a => a b (a b c) -> a b c
applyA ((String -> IOSLA (XIOState s) String String)
-> IOSLA (XIOState s) String (IOSLA (XIOState s) String String)
forall (a :: * -> * -> *) b c. Arrow a => (b -> c) -> a b c
arr String -> IOSLA (XIOState s) String String
forall s b. String -> IOStateArrow s b b
issueErr)
IOSLA (XIOState s) String String
-> IOSLA (XIOState s) String XmlTree
-> IOSLA (XIOState s) String 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) String XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b c
none
)
else IOSLA (XIOState s) (String, [String]) XmlTree
forall (a :: * -> * -> *) b c. ArrowList a => a b c
none
)
)
)