diff --git a/add/data/xql/getPreferences.xql b/add/data/xql/getPreferences.xql index 3c3eaae42..d6c1dd21c 100644 --- a/add/data/xql/getPreferences.xql +++ b/add/data/xql/getPreferences.xql @@ -30,9 +30,7 @@ declare option output:omit-xml-declaration "yes"; let $mode := request:get-parameter('mode', '') let $edition := request:get-parameter('edition', '') -(:let $base := concat('file:', system:get-module-load-path()):) -(:let $file := doc(concat($base, '/../prefs/edirom-prefs.xml')):) -let $file := doc('../prefs/edirom-prefs.xml') +let $file := doc($edition:default-prefs-location) let $projectFile := doc(edition:getPreferencesURI($edition)) diff --git a/add/data/xqm/edition.xqm b/add/data/xqm/edition.xqm index 777e9f882..e0d3b383a 100644 --- a/add/data/xqm/edition.xqm +++ b/add/data/xqm/edition.xqm @@ -19,6 +19,10 @@ import module namespace functx="http://www.functx.com"; declare namespace edirom = "http://www.edirom.de/ns/1.3"; declare namespace xlink = "http://www.w3.org/1999/xlink"; +(: VARIABLE DECLARATIONS =================================================== :) + +declare variable $edition:default-prefs-location as xs:string := '../prefs/edirom-prefs.xml'; + (: FUNCTION DECLARATIONS =================================================== :) (:~ @@ -118,16 +122,15 @@ declare function edition:getLanguageCodesSorted($uri as xs:string) as xs:string }; (:~ - : Returns the URI for the preferences file + : Returns the URI of the preferences file for a given edition : : @param $uri The URI of the Edition's document to process - : @return The URI of the preference file + : @return The URI of the edition's preference file or the default edirom preferences as fallback :) -declare function edition:getPreferencesURI($uri as xs:string) as xs:string { - - if(doc($uri)//edirom:preferences/@xlink:href => string()) then( - doc($uri)//edirom:preferences/@xlink:href => string() - ) else ('../prefs/edirom-prefs.xml') +declare function edition:getPreferencesURI($uri as xs:string?) as xs:string { + if(doc-available($uri) and doc($uri)//edirom:preferences/@xlink:href => string()) + then(doc($uri)//edirom:preferences/@xlink:href => string()) + else $edition:default-prefs-location }; (:~ diff --git a/add/data/xqm/util.xqm b/add/data/xqm/util.xqm index dfbe2a145..8381b3710 100644 --- a/add/data/xqm/util.xqm +++ b/add/data/xqm/util.xqm @@ -279,21 +279,20 @@ declare function eutil:getLanguageString($key as xs:string, $values as xs:string }; (:~ - : Return a value of preference to key + : Returns a value from the preferences for a given key : - : @param $key The key to search for - : @return The string + : @param $key The key to look up + : @param $edition The current edition URI + : @return The preference value :) declare function eutil:getPreference($key as xs:string, $edition as xs:string?) as xs:string { - let $file := doc('../prefs/edirom-prefs.xml') - let $projectFile := doc(edition:getPreferencesURI($edition)) + let $preferencesFile := + try { doc(edition:getPreferencesURI($edition)) } + catch * { util:log-system-out('Failed to load preferences') } return - if($projectFile != 'null' and $projectFile//entry[@key = $key]) then - ($projectFile//entry[@key = $key]/string(@value)) - else - ($file//entry[@key = $key]/string(@value)) + $preferencesFile//entry[@key = $key]/@value => string() };