, pageUpdateInfo
, pageRevision
+ , isSafeChar
, encodePageName
, decodePageName
, mkObjectURI
, mkFragmentURI
, mkAuxiliaryURI
+ , mkFeedURI
, mkRakkaURI
, xmlizePage
)
where
-import qualified Codec.Binary.Base64 as B64
import qualified Codec.Binary.UTF8.String as UTF8
import Control.Arrow
import Control.Arrow.ArrowIO
import Control.Arrow.ArrowList
import qualified Data.ByteString.Lazy as Lazy (ByteString)
import qualified Data.ByteString.Lazy as L hiding (ByteString)
+import qualified Data.ByteString.Lazy.Char8 as L8 hiding (ByteString)
import Data.Char
import Data.Map (Map)
import qualified Data.Map as M
import Data.Time
import Network.HTTP.Lucu hiding (redirect)
import Network.URI hiding (fragment)
+import OpenSSL.EVP.Base64
import Rakka.Utils
import Rakka.W3CDateTime
import Subversion.Types
mkPageURI :: URI -> PageName -> URI
mkPageURI baseURI name
= baseURI {
- uriPath = foldl (</>) "/" [uriPath baseURI, encodePageName name ++ ".html"]
+ uriPath = uriPath baseURI </> encodePageName name <.> "html"
}
mkPageFragmentURI :: URI -> PageName -> String -> URI
mkPageFragmentURI baseURI name fragment
= baseURI {
- uriPath = foldl (</>) "/" [uriPath baseURI, encodePageName name ++ ".html"]
+ uriPath = uriPath baseURI </> encodePageName name <.> "html"
, uriFragment = ('#' : encodeFragment fragment)
}
}
+mkFeedURI :: URI -> PageName -> URI
+mkFeedURI baseURI name
+ = baseURI {
+ uriPath = uriPath baseURI </> encodePageName name <.> "rdf"
+ }
+
+
mkRakkaURI :: PageName -> URI
mkRakkaURI name = URI {
uriScheme = "rakka:"
+= ( eelem "page"
+= sattr "name" (redirName page)
+= sattr "redirect" (redirDest page)
+ += sattr "isLocked" (yesOrNo $ redirIsLocked page)
+= sattr "revision" (show $ redirRevision page)
+= sattr "lastModified" (formatW3CDateTime lastMod)
)) -<< ()
)
+= ( if entityIsBinary page then
( eelem "binaryData"
- += txt (B64.encode $ L.unpack $ entityContent page)
+ += txt (L8.unpack $ encodeBase64LBS $ entityContent page)
)
else
( eelem "textData"
let (isBinary, content)
= case (textData, binaryData) of
- (Just text, Nothing ) -> (False, L.pack $ UTF8.encode text )
- (Nothing , Just binary) -> (True , L.pack $ fromJust $ B64.decode binary)
+ (Just text, Nothing ) -> (False, L.pack $ UTF8.encode text)
+ (Nothing , Just binary) -> (True , L8.pack $ decodeBase64 $ dropWhitespace binary)
_ -> error "one of textData or binaryData is required"
mimeType
= if isBinary then
, entityContent = content
, entityUpdateInfo = updateInfo
}
+ where
+ dropWhitespace :: String -> String
+ dropWhitespace [] = []
+ dropWhitespace (x:xs)
+ | x == ' ' || x == '\t' || x == '\n'
+ = dropWhitespace xs
+ | otherwise
+ = x : dropWhitespace xs
parseUpdateInfo :: (ArrowXml a, ArrowChoice a) => a XmlTree UpdateInfo