]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Page.hs
dropped the concept of boring flag
[Rakka.git] / Rakka / Page.hs
index 0d355faee8b88a637ea7d671c826504d7bc632cc..0affbf52f3b700bceb02e38a1770ad0d19165981 100644 (file)
@@ -15,9 +15,6 @@ module Rakka.Page
     , encodePageName
     , decodePageName
 
-    , entityFileName'
-    , defaultFileName
-
     , mkPageURI
     , mkPageFragmentURI
     , mkObjectURI
@@ -31,7 +28,7 @@ module Rakka.Page
     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
@@ -71,11 +68,9 @@ data Page
         entityName       :: !PageName
       , entityType       :: !MIMEType
       , entityLanguage   :: !(Maybe LanguageTag)
-      , entityFileName   :: !(Maybe String)
       , entityIsTheme    :: !Bool     -- text/css 以外では無意味
       , entityIsFeed     :: !Bool     -- text/x-rakka 以外では無意味
       , entityIsLocked   :: !Bool
-      , entityIsBoring   :: !Bool
       , entityIsBinary   :: !Bool
       , entityRevision   :: RevNum
       , entityLastMod    :: UTCTime
@@ -101,8 +96,8 @@ isRedirect _                       = False
 
 
 isEntity :: Page -> Bool
-isEntity (Entity _ _ _ _ _ _ _ _ _ _ _ _ _ _ _) = True
-isEntity _                                      = False
+isEntity (Entity _ _ _ _ _ _ _ _ _ _ _ _ _) = True
+isEntity _                                  = False
 
 
 pageName :: Page -> PageName
@@ -128,7 +123,7 @@ pageRevision p
 
 -- 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)
@@ -144,26 +139,11 @@ isSafeChar c
 
 -- URI unescape して UTF-8 から decode する。
 decodePageName :: FilePath -> PageName
-decodePageName = decodeString . unEscapeString
+decodePageName = UTF8.decodeString . unEscapeString
 
 
 encodeFragment :: String -> String
-encodeFragment = escapeURIString isSafeChar . encodeString
-
-
-entityFileName' :: Page -> String
-entityFileName' page
-    = fromMaybe (defaultFileName (entityType page) (entityName page)) (entityFileName page)
-
-
-defaultFileName :: MIMEType -> PageName -> String
-defaultFileName pType pName
-    = let baseName = takeFileName pName
-      in 
-        case pType of
-          MIMEType "text" "x-rakka" _ -> baseName <.> "rakka"
-          MIMEType "text" "css"     _ -> baseName <.> "css"
-          _                           -> baseName
+encodeFragment = escapeURIString isSafeChar . UTF8.encodeString
 
 
 mkPageURI :: URI -> PageName -> URI
@@ -214,7 +194,6 @@ mkRakkaURI name = URI {
   <page name="Foo/Bar"
         type="text/x-rakka"
         lang="ja"            -- 存在しない場合もある
-        fileName="bar.rakka" -- 存在しない場合もある
         isTheme="no"         -- text/css の場合のみ存在
         isFeed="no"          -- text/x-rakka の場合のみ存在
         isLocked="no"
@@ -276,10 +255,6 @@ xmlizePage
                               Just x  -> sattr "lang" x
                               Nothing -> none
                           )
-                       += ( case entityFileName page of
-                              Just x  -> sattr "fileName" x
-                              Nothing -> none
-                          )
                        += ( case entityType page of
                               MIMEType "text" "css" _
                                   -> sattr "isTheme" (yesOrNo $ entityIsTheme page)
@@ -289,7 +264,6 @@ xmlizePage
                                   -> none
                           )
                        += sattr "isLocked" (yesOrNo $ entityIsLocked page)
-                       += sattr "isBoring" (yesOrNo $ entityIsBoring page)
                        += sattr "isBinary" (yesOrNo $ entityIsBinary page)
                        += sattr "revision" (show $ entityRevision page)
                        += sattr "lastModified" (formatW3CDateTime lastMod)
@@ -312,7 +286,7 @@ xmlizePage
                                 )
                             else
                                 ( eelem "textData"
-                                  += txt (decode $ L.unpack $ entityContent page)
+                                  += txt (UTF8.decode $ L.unpack $ entityContent page)
                                 )
                           )
                      )) -<< ()
@@ -339,11 +313,9 @@ parseEntity
     = 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
 
           isTheme  <- (withDefault (getXPathTreesInDoc "/page/@isTheme/text()" >>> getText) "no"
                        >>> parseYesOrNo) -< tree
@@ -351,8 +323,6 @@ parseEntity
                        >>> 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
@@ -369,19 +339,25 @@ parseEntity
 
           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
                       , entityType       = mimeType
                       , entityLanguage   = lang
-                      , entityFileName   = fileName
                       , entityIsTheme    = isTheme
                       , entityIsFeed     = isFeed
                       , entityIsLocked   = isLocked
-                      , entityIsBoring   = isBoring
                       , entityIsBinary   = isBinary
                       , entityRevision   = undefined
                       , entityLastMod    = undefined
@@ -395,9 +371,9 @@ parseEntity
 parseUpdateInfo :: (ArrowXml a, ArrowChoice a) => a XmlTree UpdateInfo
 parseUpdateInfo 
     = proc tree
-    -> do uInfo   <- getXPathTreesInDoc "/*/updateInfo" -< tree
+    -> do uInfo   <- getXPathTreesInDoc "/page/updateInfo" -< tree
           oldRev  <- (getAttrValue0 "oldRevision" >>> arr read) -< uInfo
-          oldName <- maybeA (getXPathTrees "/move/@from/text()" >>> getText) -< uInfo
+          oldName <- maybeA (getXPathTrees "/updateInfo/move/@from/text()" >>> getText) -< uInfo
           returnA -< UpdateInfo {
                         uiOldRevision = oldRev
                       , uiOldName     = oldName