(:~ : A set of helper functions to access the application context from : within a module. :) module namespace config="http://exist-db.org/xquery/apps/config"; declare namespace repo="http://exist-db.org/xquery/repo"; declare namespace expath="http://expath.org/ns/pkg"; (: Determine the application root collection from the current module load path. :) declare variable $config:app-root := let $rawPath := system:get-module-load-path() let $modulePath := (: strip the xmldb: part :) if (starts-with($rawPath, "xmldb:exist://")) then if (starts-with($rawPath, "xmldb:exist://embedded-eXist-server")) then substring($rawPath, 36) else substring($rawPath, 15) else $rawPath return substring-before($modulePath, "/modules") ; (:~ : Returns the repo.xml descriptor for the current application. :) declare function config:repo-descriptor() as element(repo:meta) { doc(concat($config:app-root, "/repo.xml"))/repo:meta }; (:~ : Returns the expath-pkg.xml descriptor for the current application. :) declare function config:expath-descriptor() as element(expath:package) { doc(concat($config:app-root, "/expath-pkg.xml"))/expath:package }; declare function config:get-configuration() as element(configuration) { doc(concat($config:app-root, "/configuration.xml"))/configuration }; declare function config:access-allowed($path as xs:string, $user as xs:string) as xs:boolean { if (sm:is-dba($user)) then true() else let $deny := config:get-configuration()/restrictions/deny return if ($deny) then not( some $denied in $deny/@collection satisfies starts-with($path, $denied) ) else true() }; (:~ : For debugging: generates a table showing all properties defined : in the application descriptors. :) declare function config:app-info($node) { let $expath := config:expath-descriptor() let $repo := config:repo-descriptor() return
app collection: | {$config:app-root} |
{node-name($attr)}: | {$attr/string()} |