Skip to content

Commit

Permalink
Merge pull request Edirom#428 from Edirom/fix/getPreferencesURI
Browse files Browse the repository at this point in the history
Make `eutil:getPreference#2` and `edition:getPreferencesURI#1` more robust
  • Loading branch information
bwbohl authored Sep 12, 2024
2 parents 8111bd7 + b12b822 commit 95a76e8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 1 addition & 3 deletions add/data/xql/getPreferences.xql
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
17 changes: 10 additions & 7 deletions add/data/xqm/edition.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -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 =================================================== :)

(:~
Expand Down Expand Up @@ -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
};

(:~
Expand Down
17 changes: 8 additions & 9 deletions add/data/xqm/util.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -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()

};

Expand Down

0 comments on commit 95a76e8

Please sign in to comment.