]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Page.hs
preparation for feed generation
[Rakka.git] / Rakka / Page.hs
index 0affbf52f3b700bceb02e38a1770ad0d19165981..62606b35af111daa344d37d738dfabd4aa273172 100644 (file)
@@ -60,6 +60,7 @@ data Page
     = Redirection {
         redirName       :: !PageName
       , redirDest       :: !PageName
+      , redirIsLocked   :: !Bool
       , redirRevision   :: RevNum
       , redirLastMod    :: UTCTime
       , redirUpdateInfo :: Maybe UpdateInfo
@@ -91,8 +92,8 @@ data UpdateInfo
 
 
 isRedirect :: Page -> Bool
-isRedirect (Redirection _ _ _ _ _) = True
-isRedirect _                       = False
+isRedirect (Redirection _ _ _ _ _ _) = True
+isRedirect _                         = False
 
 
 isEntity :: Page -> Bool
@@ -239,6 +240,7 @@ xmlizePage
                   += ( eelem "page"
                        += sattr "name"     (redirName page)
                        += sattr "redirect" (redirDest page)
+                       += sattr "isLocked" (yesOrNo $ redirIsLocked page)
                        += sattr "revision" (show $ redirRevision page)
                        += sattr "lastModified" (formatW3CDateTime lastMod)
                      )) -<< ()
@@ -297,11 +299,14 @@ parseXmlizedPage
     = proc (name, tree)
     -> do updateInfo <- maybeA parseUpdateInfo -< tree
           redirect   <- maybeA (getXPathTreesInDoc "/page/@redirect/text()" >>> getText) -< tree
+          isLocked   <- (withDefault (getXPathTreesInDoc "/page/@isLocked/text()" >>> getText) "no"
+                         >>> parseYesOrNo) -< tree
           case redirect of
             Nothing   -> parseEntity -< (name, tree)
             Just dest -> returnA     -< (Redirection {
                                            redirName       = name
                                          , redirDest       = dest
+                                         , redirIsLocked   = isLocked
                                          , redirRevision   = undefined
                                          , redirLastMod    = undefined
                                          , redirUpdateInfo = updateInfo
@@ -340,7 +345,7 @@ parseEntity
           let (isBinary, content)
                   = case (textData, binaryData) of
                       (Just text, Nothing    ) -> (False, L.pack $ UTF8.encode text )
-                      (Nothing  , Just binary) -> (True , L.pack $ B64.decode binary)
+                      (Nothing  , Just binary) -> (True , L.pack $ fromJust $ B64.decode $ dropWhitespace binary)
                       _                        -> error "one of textData or binaryData is required"
               mimeType
                   =  if isBinary then
@@ -366,6 +371,14 @@ parseEntity
                       , 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