packages feed

plist (empty) → 0.0.1

raw patch · 8 files changed

+309/−0 lines, 8 filesdep +basedep +dataencdep +hxtsetup-changed

Dependencies added: base, dataenc, hxt

Files

+ LICENSE view
@@ -0,0 +1,10 @@+Copyright (c) 2009, Yuras Shumovich+All rights reserved.++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++	* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.+	* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.+	* Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README view
@@ -0,0 +1,18 @@++plist is a library for generation and parsing Mac OS X+property list format files++Currently it supports only xml1.+It is based on Haskell XML Toolbox.+binary1 fromat support is TODO.+I don't know reference implementation of ISO 8601 in Haskell, so date is not validated and is pepresented as String++* Install++cabal configure+cabal build+cabal install++Yuras Shumovich+shumovichy@gmail.com+
+ Setup.lhs view
@@ -0,0 +1,6 @@+#!/usr/bin/runhaskell +> module Main where+> import Distribution.Simple+> main :: IO ()+> main = defaultMain+
+ plist.cabal view
@@ -0,0 +1,53 @@+name: plist+version: 0.0.1+cabal-version: -any+build-type: Simple+license: BSD3+license-file: LICENSE+copyright: (c) 2009, Yuras Shumovich+maintainer: shumovichy@gmail.com+build-depends: base >=3 && < 5, dataenc -any, hxt >= 8.3.0 && < 8.4+stability: experimental+homepage:+package-url:+bug-reports:+synopsis: Generate and parse Mac OX property list format+description: Simple helper to generate and parse Mac OS X plist format.+             Currently it supports only 'xml1' format.+             It is based on Haskell XML Toolbox.+             .+             See+             <http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man5/plist.5.html>+             for details about plist format.+category: XML+author: Yuras Shumovich<shumovichy@gmail.com>+tested-with:+data-files: LICENSE README+data-dir: ""+extra-source-files:+extra-tmp-files:+exposed-modules: Text.XML.Plist Text.XML.Plist.PlObject+                 Text.XML.Plist.Write Text.XML.Plist.Read+exposed: True+buildable: True+build-tools:+cpp-options:+cc-options:+ld-options:+pkgconfig-depends:+frameworks:+c-sources:+extensions:+extra-libraries:+extra-lib-dirs:+includes:+install-includes:+include-dirs:+hs-source-dirs: src+other-modules:+ghc-prof-options:+ghc-shared-options:+ghc-options: -Wall+hugs-options:+nhc98-options:+jhc-options:
+ src/Text/XML/Plist.hs view
@@ -0,0 +1,29 @@+-----------------------------------------------------------------------------+--+-- Module      :  Text.XML.Plist+-- Copyright   :  (c) Yuras Shumovich 2009+-- License     :  BSD3+--+-- Maintainer  :  shumovichy@gmail.com+-- Stability   :  experimental+-- Portability :  portable+--+-- |Library for generation and parsing Mac OS X plist format+--+-----------------------------------------------------------------------------++module Text.XML.Plist (++PlObject(..),+writePlistToFile,+readPlistFromFile,+objectToPlist,+plistToObject,+objectToXml,+xmlToObject++) where++import Text.XML.Plist.PlObject+import Text.XML.Plist.Read+import Text.XML.Plist.Write
+ src/Text/XML/Plist/PlObject.hs view
@@ -0,0 +1,42 @@+-----------------------------------------------------------------------------+--+-- Module      :  Text.XML.Plist.PlObject+-- Copyright   :  (c) Yuras Shumovich 2009+-- License     :  BSD3+--+-- Maintainer  :  shumovichy@gmail.com+-- Stability   :  experimental+-- Portability :  portable+--+-- |PlObject data type+--+-----------------------------------------------------------------------------++module Text.XML.Plist.PlObject (++PlObject(..)++) where++import Data.Word++-- |Data type that represents plist object+data PlObject =+    -- |string+    PlString String |+    -- |bool+    PlBool Bool |+    -- |integer+    PlInteger Int |+    -- |real+    PlReal Double |+    -- |array+    PlArray [PlObject] |+    -- |dictionary+    PlDict [(String, PlObject)] |+    -- |raw data+    PlData [Word8] |+    -- |date (ISO 8601, but currently it is not validated)+    PlDate String+    deriving Show+
+ src/Text/XML/Plist/Read.hs view
@@ -0,0 +1,92 @@+-----------------------------------------------------------------------------+--+-- Module      :  Text.XML.Plist.Read+-- Copyright   :  (c) Yuras Shumovich 2009+-- License     :  BSD3+--+-- Maintainer  :  shumovichy@gmail.com+-- Stability   :  experimental+-- Portability :  portable+--+-- |Parsing property list format+--+-----------------------------------------------------------------------------++module Text.XML.Plist.Read (++readPlistFromFile,+plistToObject,+xmlToObject++) where++import Text.XML.Plist.PlObject+import Text.XML.HXT.Arrow+import Codec.Binary.Base64+import Data.Maybe++-- |Read 'PlObject' from file.+readPlistFromFile :: String -> IO PlObject+readPlistFromFile fileName =+    do+    res <- runX (+        readDocument [] fileName >>>+        plistToObject+        )+    if null res+        then fail $ "can't parse " ++ fileName+        else return (res !! 0)++-- |Arrow that converts xml tree to 'PlObject'.+-- Tree should contain at list one \"plist\" element.+plistToObject :: ArrowXml a => a XmlTree PlObject+plistToObject =+    deep (hasName "plist") >>>+    getChildren >>>+    xmlToObject++-- |Arrow that converts xml element to 'PlObject'.+--  Element should be \"string\", \"array\", \"dict\", etc.+xmlToObject :: ArrowXml a => a XmlTree PlObject+xmlToObject = choiceA [+    hasName "string" :-> (innerText >>> arr PlString),+    hasName "true" :-> (constA $ PlBool True),+    hasName "false" :-> (constA $ PlBool False),+    hasName "integer" :-> (innerText >>> arr (PlInteger . read)),+    hasName "real" :-> (innerText >>> arr (PlReal . read)),+    hasName "array" :-> (listA readArray >>> arr PlArray),+    hasName "dict" :-> (readDict >>> arr PlDict),+    hasName "data" :-> (+        innerText >>>+        arr (decode . unchop . lines) >>>+        isA isJust >>>+        arr fromJust >>>+        arr PlData+        ),+    hasName "date" :-> (innerText >>> arr PlDate)+    ]++readDict :: ArrowXml a => a XmlTree [(String, PlObject)]+readDict = listA $+    readDict' $< listA (getChildren >>> isElem)++readDict' :: ArrowXml a => [XmlTree] -> a b (String, PlObject)+readDict' [] = none+readDict' [_] = none+readDict' (key : val : xs) =+    ((constA key >>> hasName "key" >>> innerText) &&&+    (constA val >>> xmlToObject)) <+>+    readDict' xs++readArray :: ArrowXml a => a XmlTree PlObject+readArray =+    getChildren >>>+    xmlToObject++innerText :: ArrowXml a => a XmlTree String+innerText = single (+    getChildren >>>+    isText >>>+    getText+    )+
+ src/Text/XML/Plist/Write.hs view
@@ -0,0 +1,59 @@+-----------------------------------------------------------------------------+--+-- Module      :  Text.XML.Plist.Write+-- Copyright   :  (c) Yuras Shumovich 2009+-- License     :  BSD3+--+-- Maintainer  :  shumovichy@gmail.com+-- Stability   :  experimental+-- Portability :  portable+--+-- |Generating property list format+--+-----------------------------------------------------------------------------++module Text.XML.Plist.Write (++writePlistToFile,+objectToPlist,+objectToXml++) where++import Text.XML.Plist.PlObject+import Text.XML.HXT.Arrow+import Codec.Binary.Base64++-- |Write 'PlObject' to file+writePlistToFile :: String -> PlObject -> IO ()+writePlistToFile fileName object = runX (constA object >>> writePlist fileName) >> return ()++writePlist :: String -> IOSLA (XIOState s) PlObject XmlTree+writePlist fileName =+    objectToPlist >>>+    writeDocument [(a_indent, "1"), (a_add_default_dtd, "1")] fileName++-- |Arrow to convert 'PlObject' to plist with root element and DTD declaration.+objectToPlist :: ArrowDTD a => a PlObject XmlTree+objectToPlist = root [+        sattr "doctype-name" "plist",+        sattr "doctype-SYSTEM" "http://www.apple.com/DTDs/PropertyList-1.0.dtd",+        sattr "doctype-PUBLIC" "-//Apple Computer//DTD PLIST 1.0//EN"+    ] [mkelem "plist" [sattr "version" "1.0"] [objectToXml $< this]]++-- |Arrow to convert 'PlObject' to xml. It produces 'XmlTree' without root element.+objectToXml :: ArrowXml a => PlObject -> a b XmlTree+objectToXml (PlString str) = selem "string" [txt str]+objectToXml (PlBool bool) = eelem $ if bool then "true" else "false"+objectToXml (PlInteger int) = selem "integer" [txt $ show int]+objectToXml (PlReal real) = selem "real" [txt $ show real]+objectToXml (PlArray objects) = selem "array" $ map objectToXml objects+objectToXml (PlDict objects) = selem "dict" elems+    where+    elems = foldr (++) [] $ map toXml objects+    toXml (key, val) = [selem "key" [txt key], objectToXml val]+objectToXml (PlData dat) = selem "data" [txt $ enc dat]+    where+    enc = (++ "\n") . foldr ((++) . ("\n" ++)) "" . chop 20 . encode+objectToXml (PlDate date) = selem "date" [txt date]+