, pageName
, pageUpdateInfo
+ , pageRevision
, encodePageName
, decodePageName
where
import qualified Codec.Binary.Base64 as B64
-import Codec.Binary.UTF8.String
+import qualified Codec.Binary.UTF8.String as UTF8
import Control.Arrow
import Control.Arrow.ArrowIO
import Control.Arrow.ArrowList
pageName p
| isRedirect p = redirName p
| isEntity p = entityName p
- | otherwise = fail "neither redirection nor entity"
+ | otherwise = error "neither redirection nor entity"
pageUpdateInfo :: Page -> Maybe UpdateInfo
pageUpdateInfo p
| isRedirect p = redirUpdateInfo p
| isEntity p = entityUpdateInfo p
- | otherwise = fail "neither redirection nor entity"
+ | otherwise = error "neither redirection nor entity"
+
+
+pageRevision :: Page -> RevNum
+pageRevision p
+ | isRedirect p = redirRevision p
+ | isEntity p = entityRevision p
+ | otherwise = error "neither redirection nor entity"
-- UTF-8 に encode してから 0x20 - 0x7E の範圍を除いて URI escape する。
encodePageName :: PageName -> FilePath
-encodePageName = escapeURIString isSafeChar . encodeString . fixPageName
+encodePageName = escapeURIString isSafeChar . UTF8.encodeString . fixPageName
where
fixPageName :: PageName -> PageName
fixPageName = (\ (x:xs) -> toUpper x : xs) . map (\ c -> if c == ' ' then '_' else c)
-- URI unescape して UTF-8 から decode する。
decodePageName :: FilePath -> PageName
-decodePageName = decodeString . unEscapeString
+decodePageName = UTF8.decodeString . unEscapeString
encodeFragment :: String -> String
-encodeFragment = escapeURIString isSafeChar . encodeString
+encodeFragment = escapeURIString isSafeChar . UTF8.encodeString
entityFileName' :: Page -> String
)
else
( eelem "textData"
- += txt (decode $ L.unpack $ entityContent page)
+ += txt (UTF8.decode $ L.unpack $ entityContent page)
)
)
)) -<< ()
= proc (name, tree)
-> do updateInfo <- maybeA parseUpdateInfo -< tree
- mimeType <- (getXPathTreesInDoc "/page/@type/text()" >>> getText
- >>> arr read) -< tree
+ mimeTypeStr <- withDefault (getXPathTreesInDoc "/page/@type/text()" >>> getText) "" -< tree
lang <- maybeA (getXPathTreesInDoc "/page/@lang/text()" >>> getText) -< tree
fileName <- maybeA (getXPathTreesInDoc "/page/@filename/text()" >>> getText) -< tree
let (isBinary, content)
= case (textData, binaryData) of
- (Just text, Nothing ) -> (False, L.pack $ encode text )
+ (Just text, Nothing ) -> (False, L.pack $ UTF8.encode text )
(Nothing , Just binary) -> (True , L.pack $ B64.decode binary)
_ -> error "one of textData or binaryData is required"
+ mimeType
+ = if isBinary then
+ if null mimeTypeStr then
+ guessMIMEType content
+ else
+ read mimeTypeStr
+ else
+ read mimeTypeStr
returnA -< Entity {
entityName = name