-- ------------------------------------------------------------

{- |
   Module     : Text.XML.HXT.RelaxNG
   Copyright  : Copyright (C) 2010 Uwe Schmidt, Torben Kuseler
   License    : MIT

   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
   Stability  : stable
   Portability: portable

   This helper module exports elements from the basic Relax NG libraries:
   Validator, CreatePattern, PatternToString and DataTypes.
   It is the main entry point to the Relax NG schema validator of the Haskell
   XML Toolbox.

-}

-- ------------------------------------------------------------

module   Text.XML.HXT.RelaxNG.SystemConfig
where

import           Text.XML.HXT.Arrow.XmlOptions
import           Text.XML.HXT.Arrow.XmlState.TypeDefs

import           Text.XML.HXT.RelaxNG.Validator       (validateDocumentWithRelaxSchema)


import           System.Console.GetOpt

-- ------------------------------------------------------------

withRelaxNG                     :: String -> SysConfig
withRelaxNG :: String -> SysConfig
withRelaxNG String
s                   = Selector XIOSysState (Bool, (String, IOSArrow XmlTree XmlTree))
-> (Bool, (String, IOSArrow XmlTree XmlTree)) -> SysConfig
forall s a. Selector s a -> a -> s -> s
setS (Selector XIOSysState Bool
theRelaxValidate
                                        Selector XIOSysState Bool
-> Selector XIOSysState (String, IOSArrow XmlTree XmlTree)
-> Selector XIOSysState (Bool, (String, IOSArrow XmlTree XmlTree))
forall s a b. Selector s a -> Selector s b -> Selector s (a, b)
.&&&. Selector XIOSysState String
theRelaxSchema
                                        Selector XIOSysState String
-> Selector XIOSysState (IOSArrow XmlTree XmlTree)
-> Selector XIOSysState (String, IOSArrow XmlTree XmlTree)
forall s a b. Selector s a -> Selector s b -> Selector s (a, b)
.&&&. Selector XIOSysState (IOSArrow XmlTree XmlTree)
theRelaxValidator
                                       ) ( Bool -> Bool
not (String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
s)         -- null s turns off validation
                                         , ( String
s
                                           , SysConfigList -> String -> IOSArrow XmlTree XmlTree
forall s. SysConfigList -> String -> IOStateArrow s XmlTree XmlTree
validateDocumentWithRelaxSchema [] String
s
                                           )
                                         )

withRelaxCheckRestr             ::  Bool -> SysConfig
withRelaxCheckRestr :: Bool -> SysConfig
withRelaxCheckRestr             = Selector XIOSysState Bool -> Bool -> SysConfig
forall s a. Selector s a -> a -> s -> s
setS Selector XIOSysState Bool
theRelaxCheckRestr

withRelaxValidateExtRef         :: Bool -> SysConfig
withRelaxValidateExtRef :: Bool -> SysConfig
withRelaxValidateExtRef         = Selector XIOSysState Bool -> Bool -> SysConfig
forall s a. Selector s a -> a -> s -> s
setS Selector XIOSysState Bool
theRelaxValidateExtRef

withRelaxValidateInclude        :: Bool -> SysConfig
withRelaxValidateInclude :: Bool -> SysConfig
withRelaxValidateInclude        = Selector XIOSysState Bool -> Bool -> SysConfig
forall s a. Selector s a -> a -> s -> s
setS Selector XIOSysState Bool
theRelaxValidateInclude

withRelaxCollectErrors          :: Bool -> SysConfig
withRelaxCollectErrors :: Bool -> SysConfig
withRelaxCollectErrors          = Selector XIOSysState Bool -> Bool -> SysConfig
forall s a. Selector s a -> a -> s -> s
setS Selector XIOSysState Bool
theRelaxCollectErrors

-- ------------------------------------------------------------

-- | available Relax NG validation options
--
-- defines options
-- 'a_check_restrictions', 'a_validate_externalRef', 'a_validate_include', 'a_do_not_check_restrictions',
-- 'a_do_not_validate_externalRef', 'a_do_not_validate_include'

relaxOptions :: [OptDescr SysConfig]
relaxOptions :: [OptDescr SysConfig]
relaxOptions
    = [ String
-> [String] -> ArgDescr SysConfig -> String -> OptDescr SysConfig
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
"X" [String
a_relax_schema]                     ((String -> SysConfig) -> String -> ArgDescr SysConfig
forall a. (String -> a) -> String -> ArgDescr a
ReqArg String -> SysConfig
withRelaxNG             String
"SCHEMA")  String
"validation with Relax NG, SCHEMA is the URI for the Relax NG schema"
      , String
-> [String] -> ArgDescr SysConfig -> String -> OptDescr SysConfig
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
""  [String
a_check_restrictions]               (SysConfig -> ArgDescr SysConfig
forall a. a -> ArgDescr a
NoArg (Bool -> SysConfig
withRelaxCheckRestr        Bool
True))  String
"check Relax NG schema restrictions during schema simplification (default)"
      , String
-> [String] -> ArgDescr SysConfig -> String -> OptDescr SysConfig
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
""  [String
a_do_not_check_restrictions]        (SysConfig -> ArgDescr SysConfig
forall a. a -> ArgDescr a
NoArg (Bool -> SysConfig
withRelaxCheckRestr       Bool
False))  String
"do not check Relax NG schema restrictions"
      , String
-> [String] -> ArgDescr SysConfig -> String -> OptDescr SysConfig
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
""  [String
a_validate_externalRef]             (SysConfig -> ArgDescr SysConfig
forall a. a -> ArgDescr a
NoArg (Bool -> SysConfig
withRelaxValidateExtRef    Bool
True))  String
"validate a Relax NG schema referenced by a externalRef-Pattern (default)"
      , String
-> [String] -> ArgDescr SysConfig -> String -> OptDescr SysConfig
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
""  [String
a_do_not_validate_externalRef]      (SysConfig -> ArgDescr SysConfig
forall a. a -> ArgDescr a
NoArg (Bool -> SysConfig
withRelaxValidateExtRef   Bool
False))  String
"do not validate a Relax NG schema referenced by an externalRef-Pattern"
      , String
-> [String] -> ArgDescr SysConfig -> String -> OptDescr SysConfig
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
""  [String
a_validate_include]                 (SysConfig -> ArgDescr SysConfig
forall a. a -> ArgDescr a
NoArg (Bool -> SysConfig
withRelaxValidateInclude   Bool
True))  String
"validate a Relax NG schema referenced by an include-Pattern (default)"
      , String
-> [String] -> ArgDescr SysConfig -> String -> OptDescr SysConfig
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
""  [String
a_do_not_validate_include]          (SysConfig -> ArgDescr SysConfig
forall a. a -> ArgDescr a
NoArg (Bool -> SysConfig
withRelaxValidateInclude  Bool
False))   String
"do not validate a Relax NG schema referenced by an include-Pattern"
      , String
-> [String] -> ArgDescr SysConfig -> String -> OptDescr SysConfig
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
""  [String
a_collect_errors]                   (SysConfig -> ArgDescr SysConfig
forall a. a -> ArgDescr a
NoArg (Bool -> SysConfig
withRelaxCollectErrors     Bool
True))   String
"collect errors, default"
      , String
-> [String] -> ArgDescr SysConfig -> String -> OptDescr SysConfig
forall a. String -> [String] -> ArgDescr a -> String -> OptDescr a
Option String
""  [String
a_do_not_collect_errors]            (SysConfig -> ArgDescr SysConfig
forall a. a -> ArgDescr a
NoArg (Bool -> SysConfig
withRelaxCollectErrors    Bool
False))   String
"do not collect errors"
      ]

-- ------------------------------------------------------------
-- option for Relax NG

a_relax_schema,
 a_do_not_check_restrictions,
 a_check_restrictions,
 a_do_not_validate_externalRef,
 a_validate_externalRef,
 a_do_not_validate_include,
 a_validate_include,
 a_do_not_collect_errors :: String

a_relax_schema :: String
a_relax_schema                = String
"relax-schema"
a_do_not_check_restrictions :: String
a_do_not_check_restrictions   = String
"do-not-check-restrictions"
a_check_restrictions :: String
a_check_restrictions          = String
"check-restrictions"
a_do_not_validate_externalRef :: String
a_do_not_validate_externalRef = String
"do-not-validate-externalRef"
a_validate_externalRef :: String
a_validate_externalRef        = String
"validate-externalRef"
a_do_not_validate_include :: String
a_do_not_validate_include     = String
"do-not-validate-include"
a_validate_include :: String
a_validate_include            = String
"validate-include"
a_do_not_collect_errors :: String
a_do_not_collect_errors       = String
"do-not-collect-errors"

-- ------------------------------------------------------------