., tests
Other-Modules:
WikiParserTest
+ Extensions:
+ Arrows
GHC-Options:
-Wall -Werror
\ No newline at end of file
, mkFragmentURI
, mkAuxiliaryURI
, mkRakkaURI
+
+ , xmlizePage
+ , parseXmlizedPage
)
where
+import qualified Codec.Binary.Base64 as B64
import Codec.Binary.UTF8.String
+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 Data.Char
import Data.Map (Map)
+import qualified Data.Map as M
import Data.Maybe
import Data.Time
-import Network.HTTP.Lucu
+import Network.HTTP.Lucu hiding (redirect)
import Network.URI hiding (fragment)
+import Rakka.Utils
+import Rakka.W3CDateTime
import Subversion.Types
import System.FilePath.Posix
+import Text.XML.HXT.Arrow.XmlArrow
+import Text.XML.HXT.Arrow.XmlNodeSet
+import Text.XML.HXT.DOM.TypeDefs
type PageName = String
= Redirection {
redirName :: !PageName
, redirDest :: !PageName
- , redirRevision :: !(Maybe RevNum)
- , redirLastMod :: !UTCTime
+ , redirRevision :: RevNum
+ , redirLastMod :: UTCTime
}
| Entity {
pageName :: !PageName
, pageIsLocked :: !Bool
, pageIsBoring :: !Bool
, pageIsBinary :: !Bool
- , pageRevision :: !RevNum
- , pageLastMod :: !UTCTime
+ , pageRevision :: RevNum
+ , pageLastMod :: UTCTime
, pageSummary :: !(Maybe String)
, pageOtherLang :: !(Map LanguageTag PageName)
, pageContent :: !Lazy.ByteString
, uriQuery = ""
, uriFragment = ""
}
+
+
+{-
+ <page name="Foo/Bar"
+ type="text/x-rakka"
+ lang="ja" -- 存在しない場合もある
+ fileName="bar.rakka" -- 存在しない場合もある
+ isTheme="no" -- text/css の場合のみ存在
+ isFeed="no" -- text/x-rakka の場合のみ存在
+ isLocked="no"
+ isBinary="no"
+ revision="112"> -- デフォルトでない場合のみ存在
+ lastModified="2000-01-01T00:00:00">
+
+ <summary>
+ blah blah...
+ </summary> -- 存在しない場合もある
+
+ <otherLang> -- 存在しない場合もある
+ <link lang="ja" page="Bar/Baz" />
+ </otherLang>
+
+ <!-- 何れか一方のみ -->
+ <textData>
+ blah blah...
+ </textData>
+ <binaryData>
+ SKJaHKS8JK/DH8KS43JDK2aKKaSFLLS...
+ </binaryData>
+ </page>
+-}
+xmlizePage :: (ArrowXml a, ArrowChoice a, ArrowIO a) => a Page XmlTree
+xmlizePage
+ = proc page
+ -> do lastMod <- arrIO (utcToLocalZonedTime . pageLastMod) -< page
+ ( eelem "/"
+ += ( eelem "page"
+ += sattr "name" (pageName page)
+ += sattr "type" (show $ pageType page)
+ += ( case pageLanguage page of
+ Just x -> sattr "lang" x
+ Nothing -> none
+ )
+ += ( case pageFileName page of
+ Just x -> sattr "fileName" x
+ Nothing -> none
+ )
+ += ( case pageType page of
+ MIMEType "text" "css" _
+ -> sattr "isTheme" (yesOrNo $ pageIsTheme page)
+ MIMEType "text" "x-rakka" _
+ -> sattr "isFeed" (yesOrNo $ pageIsFeed page)
+ _
+ -> none
+ )
+ += sattr "isLocked" (yesOrNo $ pageIsLocked page)
+ += sattr "isBoring" (yesOrNo $ pageIsBoring page)
+ += sattr "isBinary" (yesOrNo $ pageIsBinary page)
+ += sattr "revision" (show $ pageRevision page)
+ += sattr "lastModified" (formatW3CDateTime lastMod)
+ += ( case pageSummary page of
+ Just s -> eelem "summary" += txt s
+ Nothing -> none
+ )
+ += ( if M.null (pageOtherLang page) then
+ none
+ else
+ selem "otherLang"
+ [ eelem "link"
+ += sattr "lang" lang
+ += sattr "page" name
+ | (lang, name) <- M.toList (pageOtherLang page) ]
+ )
+ += ( if pageIsBinary page then
+ ( eelem "binaryData"
+ += txt (B64.encode $ L.unpack $ pageContent page)
+ )
+ else
+ ( eelem "textData"
+ += txt (decode $ L.unpack $ pageContent page)
+ )
+ )
+ )) -<< ()
+
+
+parseXmlizedPage :: (ArrowXml a, ArrowChoice a) => a (PageName, XmlTree) Page
+parseXmlizedPage
+ = proc (name, tree)
+ -> do redirect <- maybeA (getXPathTreesInDoc "/page/@redirect/text()" >>> getText) -< tree
+ case redirect of
+ Nothing -> parseEntity -< (name, tree)
+ Just dest -> returnA -< (Redirection {
+ redirName = name
+ , redirDest = dest
+ , redirRevision = undefined
+ , redirLastMod = undefined
+ })
+
+
+parseEntity :: (ArrowXml a, ArrowChoice a) => a (PageName, XmlTree) Page
+parseEntity
+ = proc (name, tree)
+ -> do mimeType <- (getXPathTreesInDoc "/page/@type/text()" >>> getText
+ >>> arr read) -< tree
+
+ lang <- maybeA (getXPathTreesInDoc "/page/@lang/text()" >>> getText) -< tree
+ fileName <- maybeA (getXPathTreesInDoc "/page/@filename/text()" >>> getText) -< tree
+
+ isTheme <- (withDefault (getXPathTreesInDoc "/page/@isTheme/text()" >>> getText) "no"
+ >>> parseYesOrNo) -< tree
+ isFeed <- (withDefault (getXPathTreesInDoc "/page/@isFeed/text()" >>> getText) "no"
+ >>> parseYesOrNo) -< tree
+ isLocked <- (withDefault (getXPathTreesInDoc "/page/@isLocked/text()" >>> getText) "no"
+ >>> parseYesOrNo) -< tree
+ isBoring <- (withDefault (getXPathTreesInDoc "/page/@isBoring/text()" >>> getText) "no"
+ >>> parseYesOrNo) -< tree
+
+ summary <- (maybeA (getXPathTreesInDoc "/page/summary/text()"
+ >>> getText
+ >>> deleteIfEmpty)) -< tree
+
+ otherLang <- listA (getXPathTreesInDoc "/page/otherLang/link"
+ >>>
+ (getAttrValue0 "lang"
+ &&&
+ getAttrValue0 "page")) -< tree
+
+ textData <- maybeA (getXPathTreesInDoc "/page/textData/text()" >>> getText) -< tree
+ binaryData <- maybeA (getXPathTreesInDoc "/page/binaryData/text()" >>> getText) -< tree
+
+ let (isBinary, content)
+ = case (textData, binaryData) of
+ (Just text, Nothing ) -> (False, L.pack $ encode text )
+ (Nothing , Just binary) -> (True , L.pack $ B64.decode binary)
+ _ -> error "one of textData or binaryData is required"
+
+ returnA -< Entity {
+ pageName = name
+ , pageType = mimeType
+ , pageLanguage = lang
+ , pageFileName = fileName
+ , pageIsTheme = isTheme
+ , pageIsFeed = isFeed
+ , pageIsLocked = isLocked
+ , pageIsBoring = isBoring
+ , pageIsBinary = isBinary
+ , pageRevision = undefined
+ , pageLastMod = undefined
+ , pageSummary = summary
+ , pageOtherLang = M.fromList otherLang
+ , pageContent = content
+ }
putPage :: MonadIO m => Storage -> Page -> RevNum -> m ()
-putPage _sto _page _oldRev
+putPage sto page oldRev
= error "FIXME: not implemented"
)
where
-import qualified Codec.Binary.Base64 as B64
-import Codec.Binary.UTF8.String
import Control.Arrow
import Control.Arrow.ArrowIO
import Control.Arrow.ArrowList
-import qualified Data.ByteString.Lazy as L
-import qualified Data.Map as M
import Data.Set (Set)
import qualified Data.Set as S
-import Data.Time
import Data.Time.Clock.POSIX
import Paths_Rakka -- Cabal が用意する。
import Rakka.Page
-import Rakka.Utils
import System.Directory
import System.FilePath
import System.FilePath.Find hiding (fileName, modificationTime)
import System.Posix.Files
import Text.XML.HXT.Arrow.ReadDocument
-import Text.XML.HXT.Arrow.XmlArrow
import Text.XML.HXT.Arrow.XmlIOStateArrow
-import Text.XML.HXT.Arrow.XmlNodeSet
-import Text.XML.HXT.DOM.TypeDefs
import Text.XML.HXT.DOM.XmlKeywords
>>=
return . posixSecondsToUTCTime . fromRational . toRational . modificationTime)
-< fpath
- parsePage -< (name, lastMod, tree)
-
-
-parsePage :: (ArrowXml a, ArrowChoice a) => a (PageName, UTCTime, XmlTree) Page
-parsePage
- = proc (name, lastMod, tree)
- -> do redirect <- maybeA (getXPathTreesInDoc "/page/@redirect/text()" >>> getText) -< tree
- case redirect of
- Nothing -> parseEntity -< (name, lastMod, tree)
- Just dest -> returnA -< (Redirection {
- redirName = name
- , redirDest = dest
- , redirRevision = Nothing
- , redirLastMod = lastMod
- })
-
-
-parseEntity :: (ArrowXml a, ArrowChoice a) => a (PageName, UTCTime, XmlTree) Page
-parseEntity
- = proc (name, lastMod, tree)
- -> do mimeType <- (getXPathTreesInDoc "/page/@type/text()" >>> getText
- >>> arr read) -< tree
-
- lang <- maybeA (getXPathTreesInDoc "/page/@lang/text()" >>> getText) -< tree
- fileName <- maybeA (getXPathTreesInDoc "/page/@filename/text()" >>> getText) -< tree
-
- isTheme <- (withDefault (getXPathTreesInDoc "/page/@isTheme/text()" >>> getText) "no"
- >>> parseYesOrNo) -< tree
- isFeed <- (withDefault (getXPathTreesInDoc "/page/@isFeed/text()" >>> getText) "no"
- >>> parseYesOrNo) -< tree
- isLocked <- (withDefault (getXPathTreesInDoc "/page/@isLocked/text()" >>> getText) "no"
- >>> parseYesOrNo) -< tree
- isBoring <- (withDefault (getXPathTreesInDoc "/page/@isBoring/text()" >>> getText) "no"
- >>> parseYesOrNo) -< tree
-
- summary <- (maybeA (getXPathTreesInDoc "/page/summary/text()"
- >>> getText
- >>> deleteIfEmpty)) -< tree
-
- otherLang <- listA (getXPathTreesInDoc "/page/otherLang/link"
- >>>
- (getAttrValue0 "lang"
- &&&
- getAttrValue0 "page")) -< tree
-
- textData <- maybeA (getXPathTreesInDoc "/page/textData/text()" >>> getText) -< tree
- binaryData <- maybeA (getXPathTreesInDoc "/page/binaryData/text()" >>> getText) -< tree
-
- let (isBinary, content)
- = case (textData, binaryData) of
- (Just text, Nothing ) -> (False, L.pack $ encode text )
- (Nothing , Just binary) -> (True , L.pack $ B64.decode binary)
- _ -> error "one of textData or binaryData is required"
-
- returnA -< Entity {
- pageName = name
- , pageType = mimeType
- , pageLanguage = lang
- , pageFileName = fileName
- , pageIsTheme = isTheme
- , pageIsFeed = isFeed
- , pageIsLocked = isLocked
- , pageIsBoring = isBoring
- , pageIsBinary = isBinary
- , pageRevision = 0
- , pageLastMod = lastMod
- , pageSummary = summary
- , pageOtherLang = M.fromList otherLang
- , pageContent = content
- }
\ No newline at end of file
+ page <- parseXmlizedPage -< (name, tree)
+
+ case page of
+ Redirection _ _ _ _
+ -> returnA -< page {
+ redirRevision = 0
+ , redirLastMod = lastMod
+ }
+
+ Entity _ _ _ _ _ _ _ _ _ _ _ _ _ _
+ -> returnA -< page {
+ pageRevision = 0
+ , pageLastMod = lastMod
+ }
)
where
-import qualified Codec.Binary.Base64 as B64
-import Codec.Binary.UTF8.String
import Control.Arrow
import Control.Arrow.ArrowIO
import Control.Arrow.ArrowList
-import qualified Data.ByteString.Lazy as L
import Data.Map (Map)
import qualified Data.Map as M
import Data.Maybe
-import Data.Time
import Network.HTTP.Lucu
import Network.URI
import Rakka.Page
import Rakka.Storage
import Rakka.SystemConfig
import Rakka.Utils
-import Rakka.W3CDateTime
import Rakka.Wiki
import Rakka.Wiki.Parser
import Rakka.Wiki.Formatter
type InterpTable = Map String Interpreter
-{-
- <page name="Foo/Bar"
- type="text/x-rakka"
- lang="ja" -- 存在しない場合もある
- fileName="bar.rakka" -- 存在しない場合もある
- isTheme="no" -- text/css の場合のみ存在
- isFeed="no" -- text/x-rakka の場合のみ存在
- isLocked="no"
- isBinary="no"
- revision="112"> -- デフォルトでない場合のみ存在
- lastModified="2000-01-01T00:00:00">
-
- <summary>
- blah blah...
- </summary> -- 存在しない場合もある
-
- <otherLang> -- 存在しない場合もある
- <link lang="ja" page="Bar/Baz" />
- </otherLang>
-
- <!-- 何れか一方のみ -->
- <textData>
- blah blah...
- </textData>
- <binaryData>
- SKJaHKS8JK/DH8KS43JDK2aKKaSFLLS...
- </binaryData>
- </page>
--}
-xmlizePage :: (ArrowXml a, ArrowChoice a, ArrowIO a) => a Page XmlTree
-xmlizePage
- = proc page
- -> do lastMod <- arrIO (utcToLocalZonedTime . pageLastMod) -< page
- ( eelem "/"
- += ( eelem "page"
- += sattr "name" (pageName page)
- += sattr "type" (show $ pageType page)
- += ( case pageLanguage page of
- Just x -> sattr "lang" x
- Nothing -> none
- )
- += ( case pageFileName page of
- Just x -> sattr "fileName" x
- Nothing -> none
- )
- += ( case pageType page of
- MIMEType "text" "css" _
- -> sattr "isTheme" (yesOrNo $ pageIsTheme page)
- MIMEType "text" "x-rakka" _
- -> sattr "isFeed" (yesOrNo $ pageIsFeed page)
- _
- -> none
- )
- += sattr "isLocked" (yesOrNo $ pageIsLocked page)
- += sattr "isBoring" (yesOrNo $ pageIsBoring page)
- += sattr "isBinary" (yesOrNo $ pageIsBinary page)
- += sattr "revision" (show $ pageRevision page)
- += sattr "lastModified" (formatW3CDateTime lastMod)
- += ( case pageSummary page of
- Just s -> eelem "summary" += txt s
- Nothing -> none
- )
- += ( if M.null (pageOtherLang page) then
- none
- else
- selem "otherLang"
- [ eelem "link"
- += sattr "lang" lang
- += sattr "page" name
- | (lang, name) <- M.toList (pageOtherLang page) ]
- )
- += ( if pageIsBinary page then
- ( eelem "binaryData"
- += txt (B64.encode $ L.unpack $ pageContent page)
- )
- else
- ( eelem "textData"
- += txt (decode $ L.unpack $ pageContent page)
- )
- )
- )) -<< ()
-
-
wikifyPage :: (ArrowXml a, ArrowChoice a) => InterpTable -> a XmlTree WikiPage
wikifyPage interpTable
= proc tree