From b26de45b3fe957037ed6ce8c955d80ab06ab6fa9 Mon Sep 17 00:00:00 2001 From: Dennis Friedl Date: Fri, 8 Nov 2024 16:21:09 +0100 Subject: [PATCH 1/7] removed eutil:getDoc function --- add/data/xql/getAudioPlayer.xql | 2 +- add/data/xql/getChapters.xql | 2 +- add/data/xql/getHeader.xql | 2 +- add/data/xql/getLinkTarget.xql | 2 +- add/data/xql/getPages.xql | 2 +- add/data/xql/getSummary.xql | 2 +- add/data/xql/getText.xql | 2 +- add/data/xql/getXml.xql | 2 +- add/data/xqm/source.xqm | 2 +- add/data/xqm/util.xqm | 18 ------------------ 10 files changed, 9 insertions(+), 27 deletions(-) diff --git a/add/data/xql/getAudioPlayer.xql b/add/data/xql/getAudioPlayer.xql index dfc557b5c..2b5c3f071 100644 --- a/add/data/xql/getAudioPlayer.xql +++ b/add/data/xql/getAudioPlayer.xql @@ -28,7 +28,7 @@ let $docUri := (substring-before($uri, '#')) else ($uri) -let $doc := eutil:getDoc($docUri) +let $doc := doc($docUri) let $artist := $doc//mei:titleStmt/mei:respStmt/mei:persName[@role = 'artist'] let $album := $doc//mei:meiHead/mei:fileDesc/mei:sourceDesc/mei:source[1]/mei:titleStmt/mei:title[1]/text() let $albumCover := $doc//mei:graphic[@type = 'cover']/string(@target) diff --git a/add/data/xql/getChapters.xql b/add/data/xql/getChapters.xql index 0dfc51943..9b31756cd 100644 --- a/add/data/xql/getChapters.xql +++ b/add/data/xql/getChapters.xql @@ -48,7 +48,7 @@ declare function local:changeFormat($n) as xs:string { let $uri := request:get-parameter('uri', '') let $mode := request:get-parameter('mode', '') -let $tei := eutil:getDoc($uri) +let $tei := doc($uri) let $ret as array(*)* := array { diff --git a/add/data/xql/getHeader.xql b/add/data/xql/getHeader.xql index a30052561..c06e579e3 100644 --- a/add/data/xql/getHeader.xql +++ b/add/data/xql/getHeader.xql @@ -33,7 +33,7 @@ let $docUri := (substring-before($uri, '#')) else ($uri) -let $doc := eutil:getDoc($docUri) +let $doc := doc($docUri) let $lang := request:get-parameter('lang', 'de') let $base := concat(replace(system:get-module-load-path(), 'embedded-eXist-server', ''), '/../xslt/') (: TODO: Prüfen, wie wir an dem replace vorbei kommen:) diff --git a/add/data/xql/getLinkTarget.xql b/add/data/xql/getLinkTarget.xql index db7821697..88856d54a 100644 --- a/add/data/xql/getLinkTarget.xql +++ b/add/data/xql/getLinkTarget.xql @@ -250,7 +250,7 @@ let $path := else ($path) -let $doc := eutil:getDoc($docUri) +let $doc := doc($docUri) let $internal := $doc/id($internalId) diff --git a/add/data/xql/getPages.xql b/add/data/xql/getPages.xql index c7ddacf1b..10e6a6007 100644 --- a/add/data/xql/getPages.xql +++ b/add/data/xql/getPages.xql @@ -24,7 +24,7 @@ declare option output:media-type "application/json"; (: QUERY BODY ============================================================== :) let $uri := request:get-parameter('uri', '') -let $mei := eutil:getDoc($uri) +let $mei := doc($uri) let $ret := for $surface in $mei//mei:surface diff --git a/add/data/xql/getSummary.xql b/add/data/xql/getSummary.xql index db3a69c7b..b7e09a6ce 100644 --- a/add/data/xql/getSummary.xql +++ b/add/data/xql/getSummary.xql @@ -514,7 +514,7 @@ let $docUri := if (contains($uri, '#')) then (substring-before($uri, '#')) else ($uri) -let $doc := eutil:getDoc($docUri) +let $doc := doc($docUri) let $edition := request:get-parameter('edition', '') let $server := eutil:getPreference('image_server', $edition) let $imagePrefix := local:getImagePath($server, $edition) diff --git a/add/data/xql/getText.xql b/add/data/xql/getText.xql index 5109eb70d..c6b6d0ab7 100644 --- a/add/data/xql/getText.xql +++ b/add/data/xql/getText.xql @@ -36,7 +36,7 @@ let $idPrefix := request:get-parameter('idPrefix', '') let $term := request:get-parameter('term', '') let $path := request:get-parameter('path', '') let $page := request:get-parameter('page', '') -let $doc := eutil:getDoc($uri)/root() +let $doc := doc($uri)/root() let $contextPath := request:get-context-path() let $xslInstruction := $doc//processing-instruction(xml-stylesheet) diff --git a/add/data/xql/getXml.xql b/add/data/xql/getXml.xql index de732f4eb..3ec1ad5cf 100644 --- a/add/data/xql/getXml.xql +++ b/add/data/xql/getXml.xql @@ -24,7 +24,7 @@ declare option output:indent "yes"; let $uri := request:get-parameter('uri', '') let $internalId := request:get-parameter('internalId', '') -let $doc := eutil:getDoc($uri)/root() +let $doc := doc($uri)/root() let $internal := $doc/id($internalId) return diff --git a/add/data/xqm/source.xqm b/add/data/xqm/source.xqm index 71a52c819..4959fa6f3 100644 --- a/add/data/xqm/source.xqm +++ b/add/data/xqm/source.xqm @@ -32,7 +32,7 @@ declare namespace mei="http://www.music-encoding.org/ns/mei"; :) declare function source:isSource($uri as xs:string) as xs:boolean { - let $doc := eutil:getDoc($uri) + let $doc := doc($uri) let $meiVersion4To5Regex := '^[4-5](\.\d){1,2}(-dev)?(\+(anyStart|basic|CMN|Mensural|Neumes))?$' return diff --git a/add/data/xqm/util.xqm b/add/data/xqm/util.xqm index 49e466099..0fc0dc6f4 100644 --- a/add/data/xqm/util.xqm +++ b/add/data/xqm/util.xqm @@ -128,24 +128,6 @@ declare function eutil:getLocalizedTitle($node as node(), $lang as xs:string?) a else ('[No title found!]') -}; -(:~ - : Returns a document - : - : @param $uri The URIs of the documents to process - : @return The document - :) -declare function eutil:getDoc($uri) { - - if(starts-with($uri, 'textgrid:')) then( - let $session := request:get-cookie-value('edirom_online_textgrid_sessionId') - return - doc('http://textgridlab.org/1.0/tgcrud/rest/' || $uri || '/data?sessionId=' || $session) - - ) else ( - doc($uri) - ) - }; (:~ From d690fb2dd5b39fe0a54abacd18ad89a8fa4140e0 Mon Sep 17 00:00:00 2001 From: Dennis Friedl Date: Fri, 8 Nov 2024 16:21:35 +0100 Subject: [PATCH 2/7] Removed OR Statement with textgrid Uri --- app/controller/LinkController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controller/LinkController.js b/app/controller/LinkController.js index 794818d98..89bd15874 100644 --- a/app/controller/LinkController.js +++ b/app/controller/LinkController.js @@ -76,7 +76,7 @@ Ext.define('EdiromOnline.controller.LinkController', { }else if(singleUri.match(/^edirom:\/\//)) { this.parseEdiromLink(singleUri); - }else if(singleUri.match(/^xmldb:exist:\/\//) || singleUri.match(/^textgrid:/)) { + }else if(singleUri.match(/^xmldb:exist:\/\//)) { if(config['useExisting']) { var win = existingWindows.findBy(function(win) { From c01c61b49ef73eeff9fbf4263116832ebe86cd22 Mon Sep 17 00:00:00 2001 From: Dennis Friedl Date: Fri, 8 Nov 2024 17:46:48 +0100 Subject: [PATCH 3/7] Revert "removed eutil:getDoc function" This reverts commit a3ee82a97a7e2884249644ea38e81ebedfaf9c47. --- add/data/xql/getAudioPlayer.xql | 2 +- add/data/xql/getChapters.xql | 2 +- add/data/xql/getHeader.xql | 2 +- add/data/xql/getLinkTarget.xql | 2 +- add/data/xql/getPages.xql | 2 +- add/data/xql/getSummary.xql | 2 +- add/data/xql/getText.xql | 2 +- add/data/xql/getXml.xql | 2 +- add/data/xqm/source.xqm | 2 +- add/data/xqm/util.xqm | 18 ++++++++++++++++++ 10 files changed, 27 insertions(+), 9 deletions(-) diff --git a/add/data/xql/getAudioPlayer.xql b/add/data/xql/getAudioPlayer.xql index 2b5c3f071..dfc557b5c 100644 --- a/add/data/xql/getAudioPlayer.xql +++ b/add/data/xql/getAudioPlayer.xql @@ -28,7 +28,7 @@ let $docUri := (substring-before($uri, '#')) else ($uri) -let $doc := doc($docUri) +let $doc := eutil:getDoc($docUri) let $artist := $doc//mei:titleStmt/mei:respStmt/mei:persName[@role = 'artist'] let $album := $doc//mei:meiHead/mei:fileDesc/mei:sourceDesc/mei:source[1]/mei:titleStmt/mei:title[1]/text() let $albumCover := $doc//mei:graphic[@type = 'cover']/string(@target) diff --git a/add/data/xql/getChapters.xql b/add/data/xql/getChapters.xql index 9b31756cd..0dfc51943 100644 --- a/add/data/xql/getChapters.xql +++ b/add/data/xql/getChapters.xql @@ -48,7 +48,7 @@ declare function local:changeFormat($n) as xs:string { let $uri := request:get-parameter('uri', '') let $mode := request:get-parameter('mode', '') -let $tei := doc($uri) +let $tei := eutil:getDoc($uri) let $ret as array(*)* := array { diff --git a/add/data/xql/getHeader.xql b/add/data/xql/getHeader.xql index c06e579e3..a30052561 100644 --- a/add/data/xql/getHeader.xql +++ b/add/data/xql/getHeader.xql @@ -33,7 +33,7 @@ let $docUri := (substring-before($uri, '#')) else ($uri) -let $doc := doc($docUri) +let $doc := eutil:getDoc($docUri) let $lang := request:get-parameter('lang', 'de') let $base := concat(replace(system:get-module-load-path(), 'embedded-eXist-server', ''), '/../xslt/') (: TODO: Prüfen, wie wir an dem replace vorbei kommen:) diff --git a/add/data/xql/getLinkTarget.xql b/add/data/xql/getLinkTarget.xql index 88856d54a..db7821697 100644 --- a/add/data/xql/getLinkTarget.xql +++ b/add/data/xql/getLinkTarget.xql @@ -250,7 +250,7 @@ let $path := else ($path) -let $doc := doc($docUri) +let $doc := eutil:getDoc($docUri) let $internal := $doc/id($internalId) diff --git a/add/data/xql/getPages.xql b/add/data/xql/getPages.xql index 10e6a6007..c7ddacf1b 100644 --- a/add/data/xql/getPages.xql +++ b/add/data/xql/getPages.xql @@ -24,7 +24,7 @@ declare option output:media-type "application/json"; (: QUERY BODY ============================================================== :) let $uri := request:get-parameter('uri', '') -let $mei := doc($uri) +let $mei := eutil:getDoc($uri) let $ret := for $surface in $mei//mei:surface diff --git a/add/data/xql/getSummary.xql b/add/data/xql/getSummary.xql index b7e09a6ce..db3a69c7b 100644 --- a/add/data/xql/getSummary.xql +++ b/add/data/xql/getSummary.xql @@ -514,7 +514,7 @@ let $docUri := if (contains($uri, '#')) then (substring-before($uri, '#')) else ($uri) -let $doc := doc($docUri) +let $doc := eutil:getDoc($docUri) let $edition := request:get-parameter('edition', '') let $server := eutil:getPreference('image_server', $edition) let $imagePrefix := local:getImagePath($server, $edition) diff --git a/add/data/xql/getText.xql b/add/data/xql/getText.xql index c6b6d0ab7..5109eb70d 100644 --- a/add/data/xql/getText.xql +++ b/add/data/xql/getText.xql @@ -36,7 +36,7 @@ let $idPrefix := request:get-parameter('idPrefix', '') let $term := request:get-parameter('term', '') let $path := request:get-parameter('path', '') let $page := request:get-parameter('page', '') -let $doc := doc($uri)/root() +let $doc := eutil:getDoc($uri)/root() let $contextPath := request:get-context-path() let $xslInstruction := $doc//processing-instruction(xml-stylesheet) diff --git a/add/data/xql/getXml.xql b/add/data/xql/getXml.xql index 3ec1ad5cf..de732f4eb 100644 --- a/add/data/xql/getXml.xql +++ b/add/data/xql/getXml.xql @@ -24,7 +24,7 @@ declare option output:indent "yes"; let $uri := request:get-parameter('uri', '') let $internalId := request:get-parameter('internalId', '') -let $doc := doc($uri)/root() +let $doc := eutil:getDoc($uri)/root() let $internal := $doc/id($internalId) return diff --git a/add/data/xqm/source.xqm b/add/data/xqm/source.xqm index 4959fa6f3..71a52c819 100644 --- a/add/data/xqm/source.xqm +++ b/add/data/xqm/source.xqm @@ -32,7 +32,7 @@ declare namespace mei="http://www.music-encoding.org/ns/mei"; :) declare function source:isSource($uri as xs:string) as xs:boolean { - let $doc := doc($uri) + let $doc := eutil:getDoc($uri) let $meiVersion4To5Regex := '^[4-5](\.\d){1,2}(-dev)?(\+(anyStart|basic|CMN|Mensural|Neumes))?$' return diff --git a/add/data/xqm/util.xqm b/add/data/xqm/util.xqm index 0fc0dc6f4..49e466099 100644 --- a/add/data/xqm/util.xqm +++ b/add/data/xqm/util.xqm @@ -128,6 +128,24 @@ declare function eutil:getLocalizedTitle($node as node(), $lang as xs:string?) a else ('[No title found!]') +}; +(:~ + : Returns a document + : + : @param $uri The URIs of the documents to process + : @return The document + :) +declare function eutil:getDoc($uri) { + + if(starts-with($uri, 'textgrid:')) then( + let $session := request:get-cookie-value('edirom_online_textgrid_sessionId') + return + doc('http://textgridlab.org/1.0/tgcrud/rest/' || $uri || '/data?sessionId=' || $session) + + ) else ( + doc($uri) + ) + }; (:~ From 9e408760ae3fd7f64f95013921b86cd2dc0efffc Mon Sep 17 00:00:00 2001 From: Dennis Friedl Date: Fri, 8 Nov 2024 17:54:47 +0100 Subject: [PATCH 4/7] removed textgrid from eutil:getDoc --- add/data/xqm/util.xqm | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/add/data/xqm/util.xqm b/add/data/xqm/util.xqm index 49e466099..9fd0ec0fe 100644 --- a/add/data/xqm/util.xqm +++ b/add/data/xqm/util.xqm @@ -136,16 +136,7 @@ declare function eutil:getLocalizedTitle($node as node(), $lang as xs:string?) a : @return The document :) declare function eutil:getDoc($uri) { - - if(starts-with($uri, 'textgrid:')) then( - let $session := request:get-cookie-value('edirom_online_textgrid_sessionId') - return - doc('http://textgridlab.org/1.0/tgcrud/rest/' || $uri || '/data?sessionId=' || $session) - - ) else ( - doc($uri) - ) - + doc($uri) }; (:~ From 787d2fecd15a764bb0859d63fa21cda1f9b1f978 Mon Sep 17 00:00:00 2001 From: Peter Stadler Date: Fri, 8 Nov 2024 21:57:32 +0100 Subject: [PATCH 5/7] make eutil:getDoc#1 more robust --- add/data/xqm/util.xqm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/add/data/xqm/util.xqm b/add/data/xqm/util.xqm index 9fd0ec0fe..e6a05328f 100644 --- a/add/data/xqm/util.xqm +++ b/add/data/xqm/util.xqm @@ -129,14 +129,19 @@ declare function eutil:getLocalizedTitle($node as node(), $lang as xs:string?) a ('[No title found!]') }; + (:~ : Returns a document : : @param $uri The URIs of the documents to process : @return The document :) -declare function eutil:getDoc($uri) { - doc($uri) +declare function eutil:getDoc($uri as xs:string?) as document-node()? { + if(empty($uri) or ($uri eq "")) + then util:log("warn", "No document URI provided") + else if(doc-available($uri)) + then doc($uri) + else util:log("warn", "Unable to load document at " || $uri) }; (:~ From cf4fc7a72125aa71cb3995c9e55b47e0a995a1f8 Mon Sep 17 00:00:00 2001 From: Peter Stadler Date: Fri, 8 Nov 2024 21:58:14 +0100 Subject: [PATCH 6/7] use canonical function for retrieving documents --- add/data/xqm/util.xqm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add/data/xqm/util.xqm b/add/data/xqm/util.xqm index e6a05328f..8e6e6fef4 100644 --- a/add/data/xqm/util.xqm +++ b/add/data/xqm/util.xqm @@ -264,7 +264,7 @@ declare function eutil:getLanguageString($key as xs:string, $values as xs:string declare function eutil:getLanguageString($key as xs:string, $values as xs:string*, $lang as xs:string) as xs:string { let $base := system:get-module-load-path() - let $file := doc(concat($base, '/../locale/edirom-lang-', $lang, '.xml')) + let $file := eutil:getDoc(concat($base, '/../locale/edirom-lang-', $lang, '.xml')) let $string := $file//entry[@key = $key]/string(@value) let $string := functx:replace-multi($string, for $i in (0 to (count($values) - 1)) return concat('\{',$i,'\}'), $values) From 81e757eddc522688f2e8973e981eecc4cc2779d0 Mon Sep 17 00:00:00 2001 From: Peter Stadler Date: Fri, 8 Nov 2024 21:58:43 +0100 Subject: [PATCH 7/7] add unit tests for eutil:getDoc --- testing/XQSuite/eutil-tests.xqm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/testing/XQSuite/eutil-tests.xqm b/testing/XQSuite/eutil-tests.xqm index ec944e5a4..45ea161f7 100644 --- a/testing/XQSuite/eutil-tests.xqm +++ b/testing/XQSuite/eutil-tests.xqm @@ -38,3 +38,14 @@ declare function eut:test-getLocalizedTitle($node as element(), $lang as xs:string?) as xs:string { eutil:getLocalizedTitle($node, $lang) }; + +declare + %test:arg("uri") %test:assertEmpty + %test:arg("uri", "") %test:assertEmpty + %test:args("foo") %test:assertEmpty + %test:args("https://edirom.de") %test:assertXPath("/html") + %test:args("xmldb:exist://db/apps/Edirom-Online/data/locale/edirom-lang-de.xml") %test:assertXPath("/langFile") + %test:args("/db/apps/Edirom-Online/data/locale/edirom-lang-de.xml") %test:assertXPath("/langFile") + function eut:test-getDoc($uri as xs:string?) as document-node()? { + eutil:getDoc($uri) +};