Commit 848dd24f authored by Mathias Goebel's avatar Mathias Goebel 🎠

Merge branch 'feature/#89-exist-5.0.0-update' into 'develop'

Feature/#89 exist 5.1.0 update

exist-db-5.1.0 adjustment. Closes #89, #87. Remove fontane search analyser.

without the fontane analyser we fix #57, #12, #49.

See merge request !71
parents 2ce327bc b592d318
......@@ -22,7 +22,6 @@ stages:
- test
- deploy
# in the build stage eXist-db is (as the name implies) built considering all
# dependencies that are stated in build.properties and/or generic.xml.
# build-develop is triggered after pushing/merging into any branch except master
......@@ -70,12 +69,12 @@ installation:
paths:
- output.log
- test/tests-*.xml
- test/eXist-db-*/webapp/WEB-INF/logs/expath-repo.log
- test/eXist-db-*/logs/expath-repo.log
# this enables us to get information like test coverage.
reports:
junit: test/tests-*.xml
# upload the EXPath package to the repo
upload:
only:
- master
......
......@@ -2,7 +2,7 @@ project.name=http://sade.textgrid.de/ns/SADE-develop
project.version=4.1.0
project.title=Scalable Architecture for Digital Editions powered by TextGrid
project.abbrev=SADE-develop
project.processorversion=4.7.1
project.processorversion=5.1.0
destfile=${build.dir}/${project.abbrev}-${project.version}.xar
test.dir=test
......
......@@ -36,16 +36,20 @@
</target>
<target name="test" depends="antversion-test, cleanup, xar">
<!-- task setpermissions requries at least ant 1.10.0 -->
<get src="https://bintray.com/existdb/releases/download_file?file_path=eXist-db-${project.processorversion}.tar.bz2" dest="${build.dir}/eXist-db-${project.processorversion}.tar.bz2" skipexisting="true" />
<!-- this path may be and is subject to change! -->
<get src="https://bintray.com/existdb/releases/download_file?file_path=exist-distribution-${project.processorversion}-unix.tar.bz2" dest="${build.dir}/eXist-db-${project.processorversion}.tar.bz2" skipexisting="true" />
<untar src="${build.dir}/eXist-db-${project.processorversion}.tar.bz2" dest="${test.dir}" compression="bzip2" />
<!-- directory name changed: exist-distribution-5.0.0-->
<move todir="${test.dir}/eXist-db-${project.processorversion}">
<fileset dir="${test.dir}/exist-distribution-${project.processorversion}" />
</move>
<!-- task setpermissions requries at least ant 1.10.0 -->
<setpermissions mode="755">
<file file="${test.dir}/eXist-db-${project.processorversion}/bin/startup.sh"/>
</setpermissions>
<get src="https://ci.de.dariah.eu/exist-repo/find.zip?abbrev=${assets.abbrev}&amp;processor=${project.processorversion}" dest="${test.dir}/eXist-db-${project.processorversion}/autodeploy/sade_assets-latest.xar" ignoreerrors="true"/>
<get src="https://ci.de.dariah.eu/exist-repo/find.zip?abbrev=${code-viewer.abbrev}&amp;processor=${project.processorversion}" dest="${test.dir}/eXist-db-${project.processorversion}/autodeploy/codeview-latest.xar" ignoreerrors="true"/>
<get src="https://ci.de.dariah.eu/exist-repo/find.zip?abbrev=fontane-lucene-exist-module&amp;processor=${project.processorversion}" dest="${test.dir}/eXist-db-${project.processorversion}/autodeploy/fontane-lucene-latest.xar" ignoreerrors="true"/>
<get src="http://exist-db.org/exist/apps/public-repo/find.zip?abbrev=markdown&amp;processor=${project.processorversion}" dest="${test.dir}/eXist-db-${project.processorversion}/autodeploy/markdown-latest.xar" ignoreerrors="true"/>
<get src="http://exist-db.org/exist/apps/public-repo/find.zip?abbrev=functx&amp;processor=${project.processorversion}" dest="${test.dir}/eXist-db-${project.processorversion}/autodeploy/functx-latest.xar" ignoreerrors="true"/>
......
......@@ -3,6 +3,9 @@ xquery version "3.1";
: generic and simple functions used by templates and other modules.
: also an incubator of new modules.
:
: @author unknown
: @author Stefan Hynek
: @version 0.1
:)
module namespace app="https://sade.textgrid.de/ns/app";
......@@ -97,7 +100,8 @@ return
(:~
:
:)
declare function app:recentlyPublished($node as node(), $model as map(*), $howmany) as map(*)* {
declare function app:recentlyPublished($node as node(), $model as map(*), $howmany) as map(*)*
{
let $collection-uri := $config:app-root || "/" || config:get("project-id") || "/meta"
return if( not(xmldb:collection-available($collection-uri)) ) then () else
let $last-resources :=
......@@ -112,17 +116,20 @@ declare function app:recentlyPublished($node as node(), $model as map(*), $howma
map { "last-resources": $metadata[1,2,3] }
};
declare function app:recentlyPublished-link($node as node(), $model as map(*), $num as xs:integer) {
declare function app:recentlyPublished-link($node as node(), $model as map(*), $num as xs:integer)
{
<a href="./{$model("last-resources")[$num]//tgmd:textgridUri/string() => replace(":", "%3A")}">
<img class="media-object" src="~assets/generic/icons/{replace($model("last-resources")[$num]//tgmd:format, "/", "-")}.svg" alt="{string($model("last-resources")[$num]//tgmd:format)}"/>
</a>
};
declare function app:recentlyPublished-title($node as node(), $model as map(*), $num as xs:integer) {
declare function app:recentlyPublished-title($node as node(), $model as map(*), $num as xs:integer)
{
$model("last-resources")[$num]//tgmd:title/text()
};
declare function app:recentlyPublished-description($node as node(), $model as map(*), $num as xs:integer) {
declare function app:recentlyPublished-description($node as node(), $model as map(*), $num as xs:integer)
{
let $lastModinLab := $model("last-resources")[$num]//tgmd:lastModified/substring-before(., ".")
let $info := if($lastModinLab = "") then () else
"This document was last modified in the Lab at "
......@@ -144,7 +151,8 @@ declare function app:recentlyPublished-description($node as node(), $model as ma
};
declare
function app:featuredWorks($node as node(), $model as map(*)) {
function app:featuredWorks($node as node(), $model as map(*))
{
let $collection-uri := $config:app-root || "/" || config:get("project-id") || "/meta"
return if( not(xmldb:collection-available($collection-uri)) ) then () else
let $largest-resources :=
......@@ -226,7 +234,8 @@ element { name($node) } {
(:~
: link rewriter. takes a URL and returns the URL including the lang
: parameter.
: :)
:
:)
declare
%templates:wrap
function app:rewriteLink($ref as xs:string) as xs:string {
......@@ -234,8 +243,9 @@ function app:rewriteLink($ref as xs:string) as xs:string {
let $base-url := tokenize($ref, "\?|#")[1]
let $get-parameter := tokenize(substring-after($ref, "?"), "#")[1]
let $get-parameter :=
if(contains($get-parameter, "lang=")) then $get-parameter
else (tokenize($get-parameter, "&amp;")[. != ""], "lang=" || $lang)
if(contains($get-parameter, "lang="))
then $get-parameter
else (tokenize($get-parameter, "&amp;")[. != ""], "lang=" || $lang)
let $anchor := substring-after($ref, "#")
(:~
......@@ -263,7 +273,6 @@ return
|| (if($anchor != "") then "#" || $anchor else ())
};
declare
%templates:wrap
function app:list-docs($node as node(), $model as map(*)) {
......@@ -377,9 +386,14 @@ function app:display-charsyn-info($node as node(), $model as map(*)) {
: serves the error messages powered by programmingexcuses.com
: a random message is created on each error report and send out to the user.
: :)
declare function app:error($node as node(), $model as map(*)) {
httpclient:get(xs:anyURI('http://programmingexcuses.com/'), false(), ())//*:body/*:div[@class="wrapper"]/*:center/*:a/text()
};
declare function app:error($node as node(), $model as map(*))
{
hc:send-request(
<hc:request method="get" />,
'http://programmingexcuses.com/'
)[1]/*:body/*:div[@class="wrapper"]/*:center/*:a/text()
};
declare function app:currentyear($node as node(), $model as map(*)) {
year-from-date( current-date() )
......
......@@ -58,7 +58,6 @@ declare function callgraph:main($option as xs:string, $filename as xs:string) as
if(ends-with($option, ".xqm")
or $option = "full"
or xmldb:collection-available($option)) then
let $bla := console:log("test")
let $filename :=
if(contains($filename, ".")) then
error( QName("https://sade.textgrid.de/ns/app", "CALLGRAPH01"),
......
......@@ -11,7 +11,7 @@ declare namespace expath="http://expath.org/ns/pkg";
declare namespace repo="http://exist-db.org/xquery/repo";
(:
Determine the application root collection from the current module load path.
: Determine the application root collection from the current module load path.
:)
declare variable $config:app-root :=
let $rawPath := system:get-module-load-path()
......
......@@ -37,12 +37,12 @@ declare function fsearch:results($node as node(), $model as map(*)) as map()* {
return
map {
"facets" := fsearch:facets($model, $hits),
"hits" := subsequence($hitsordered,$start,$num),
"totalhits" := count($hits),
"start" := $start,
"page" := $page,
"pages" := $pages
"facets" : fsearch:facets($model, $hits),
"hits" : subsequence($hitsordered,$start,$num),
"totalhits" : count($hits),
"start" : $start,
"page" : $page,
"pages" : $pages
}
};
......@@ -170,7 +170,7 @@ function fsearch:result-id($node as node(), $model as map(*)) {
};
declare function fsearch:facets($model as map(*), $hits) as map() {
map:new(
map:merge(
for $facet in config:get("facets", "faceted-search")
return
map:entry($facet/string(@key), local:facet($model, $hits, $facet/string(@key), string($facet/cf:xpath/text())))
......@@ -178,7 +178,7 @@ declare function fsearch:facets($model as map(*), $hits) as map() {
};
declare function fsearch:list-facets($node as node(), $model as map(*)) as map(*){
map { "facetgroups" := $model("facet") }
map { "facetgroups" : $model("facet") }
};
declare
......
......@@ -6,7 +6,8 @@ xquery version "3.1";
: but in the new application.
:
: @author Mathias Göbel
: @version 0.2
: @author Stefan Hynek
: @version 0.3
: :)
import module namespace dbutil="http://exist-db.org/xquery/dbutil";
......@@ -126,7 +127,7 @@ return
let $prepare as xs:string :=
(
xmldb:create-collection(xmldb:create-collection("/db", "tmp"), $name),
xmldb:copy($source-collection, "/db/tmp/"||$name)
xmldb:copy-collection($source-collection, "/db/tmp/"||$name)
)
let $replace-the-configs := (
xmldb:store("/db/tmp/"||$name ||"/"||$source-name, "repo.xml", $repoConf),
......
......@@ -4,7 +4,8 @@ xquery version "3.1";
: documents, e.g. TEI, Markdown or HTML passthrou.
: @author Mathias Göbel
: @author Ubbo Veentjer
: @version 1.0
: @author Stefan Hynek
: @version 1.1
:)
module namespace multiviewer="https://sade.textgrid.de/ns/multiviewer";
......@@ -179,7 +180,7 @@ return <div id="stn">
(: TODO: tei-specific :)
declare function multiviewer:tei-paging($doc, $page as xs:integer) {
let $doc := if ($page > 0 and ($doc//tei:pb)[$page]) then
util:parse(util:get-fragment-between(($doc//tei:pb)[$page], ($doc//tei:pb)[$page+1], true(), true()))
fn:parse-xml(util:get-fragment-between(($doc//tei:pb)[$page], ($doc//tei:pb)[$page+1], true(), true()))
(: Kann das funktionieren, wenn page als integer übergeben wird? müsste man nicht tei:pb/@n auswerten? :)
else
$doc
......
xquery version "3.1";
(:~
: description
:
: @author unknown
: @author Stefan Hynek
: @version 0.1
:)
module namespace nav="https://sade.textgrid.de/ns/navigation";
import module namespace app="https://sade.textgrid.de/ns/app" at "app.xqm";
......@@ -18,7 +27,7 @@ function nav:navitems($node as node(), $model as map(*)) as map(*) {
let $confLocation := config:get("location", $nav:module-key)
let $navitems := doc( $config:app-root || "/" || $confLocation)//navigation/*
return
map { "navitems" := $navitems }
map { "navitems" : $navitems }
};
declare function nav:head($node as node(), $model as map(*)) {
......@@ -51,7 +60,7 @@ declare function nav:head($node as node(), $model as map(*)) {
declare
%templates:wrap
function nav:subitems($node as node(), $model as map(*)) as map(*) {
map{ "subitems" := $model("item")/*}
map{ "subitems" : $model("item")/*}
};
declare function nav:subitem($node as node(), $model as map(*)) {
......
......@@ -4,7 +4,8 @@ xquery version "3.1";
: when they are available via REST.
: @author Ubbo Veentjer
: @author Mathias Göbel
: @version 1.0
: @author Stefan Hynek
: @version 1.1
: @see https://sade.textgrid.de
:)
......@@ -20,44 +21,58 @@ declare namespace test="http://exist-db.org/xquery/xqsuite";
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
(:
: Queries TextGrid RDF store. Mainly used to get URIs within a collection
: @param $query - the SPARQL query as string
: @param $tg-sesame-uri - URL of the public SPARQL endpoint
: @return the result of the SPARQL query as XML node
:)
declare function tgclient:sparql($query as xs:string, $tg-sesame-uri as xs:string) as node() {
declare function tgclient:sparql($query as xs:string, $tg-sesame-uri as xs:string) as node()
{
let $urlEncodedQuery as xs:string := encode-for-uri($query)
let $reqUrl as xs:anyURI := string-join(($tg-sesame-uri, "?query=", $urlEncodedQuery)) => xs:anyURI()
let $headers := <headers>
<header name="Accept" value="text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"/>
<header name="Connection" value="close"/>
</headers>
return
httpclient:get($reqUrl, false(), $headers)//httpclient:body/node()
let $reqUrl := string-join(($tg-sesame-uri, "?query=", $urlEncodedQuery))
let $reqGet :=
<http:request method="get">
<http:header
name = "accept"
value = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
/>
<http:header
name = "connection"
value = "close"
/>
</http:request>
return http:send-request($reqGet, $reqUrl)[2]/node()
};
(:~ Get TextGrid Metadata Object :)
declare function tgclient:getMeta($id as xs:string, $tgcrud-url as xs:string, $sid as xs:string?) as node() {
let $reqUrl := xs:anyURI(string-join(($tgcrud-url,"/",$id,"/metadata?sessionId=", $sid),""))
let $headers := <headers>
<header name="Connection" value="close"/>
</headers>
declare function tgclient:getMeta($id as xs:string, $tgcrud-url as xs:string, $sid as xs:string?) as node()
{
let $reqUrl := string-join(($tgcrud-url,"/",$id,"/metadata?sessionId=", $sid),"")
let $reqGet :=
<http:request method="get">
<http:header name="connection" value="close" />
</http:request>
let $result :=
try { httpclient:get($reqUrl, false(), $headers)//httpclient:body/node() }
try {
http:send-request($reqGet, $reqUrl)[2]//tgmd:MetadataContainerType
}
catch * { <error>URI:{ $id } { $err:code }: { $err:description }</error> }
return
if( count($result) != 1 ) then <error> { $id } </error> else $result
};
(:~ Get TextGrid Data Object :)
declare function tgclient:getData($id as xs:string, $tgcrud-url as xs:string, $sid as xs:string?) {
let $reqUrl := xs:anyURI(string-join(($tgcrud-url,"/",$id,"/data?sessionId=", $sid),""))
let $headers := <headers>
<header name="Connection" value="close"/>
</headers>
let $getBody := httpclient:get($reqUrl, false(), $headers)//httpclient:body
declare function tgclient:getData($id as xs:string, $tgcrud-url as xs:string, $sid as xs:string?)
{
let $reqUrl := string-join(($tgcrud-url,"/",$id,"/data?sessionId=", $sid),"")
let $reqGet :=
<http:request method="get">
<http:header name="Connection" value="close" />
</http:request>
let $getBody := http:send-request($reqGet, $reqUrl)[2]
return
switch ($getBody/@mimetype)
case "text/plain" return
......@@ -65,7 +80,6 @@ declare function tgclient:getData($id as xs:string, $tgcrud-url as xs:string, $s
process:execute(('/usr/bin/curl',$reqUrl, "-s"), ())//line => string-join("&#13;")
else string($getBody)
default return document { $getBody/node() }
};
(:~ Returns a list of TextGrid items within a given aggregation, but only the
......@@ -161,6 +175,7 @@ let
tgclient:getData($uri, $sid, $crud)
else (),
$data := if($data//ore:aggregates) then $data else ()
return
(
$meta,
......@@ -175,9 +190,10 @@ declare function tgclient:tgsearch-navigation-agg($uri as xs:string, $sid as xs:
let $tgsearch-nonpublic := "https://textgridlab.org/1.0/tgsearch/navigation"
let $API := "/agg/"
let $url := $tgsearch-nonpublic || $API || $uri || "?sid=" || $sid
let $reqGet := <http:request method="get" />
return
httpclient:get($url, false(), (), ())//httpclient:body/node()
http:send-request($reqGet, $url)[2]/node()
};
declare function tgclient:tgsearch-query-filter($filters as element(filters), $query as xs:string, $sid as xs:string, $limit as xs:integer, $start as xs:integer) {
......@@ -193,23 +209,27 @@ return
declare function tgclient:confserv(){
let $confservUrl := "https://textgridlab.org/1.0/confserv/getAll"
let $reqGet :=
<http:request method="get" />
let $confserv :=
httpclient:get(xs:anyURI($confservUrl), false(), ())//httpclient:body/text()
=> util:base64-decode()
=> parse-json()
http:send-request($reqGet, $confservUrl)[2]/text()
=> util:base64-decode()
=> parse-json()
return
map:new(
map:merge(
for $key at $pos in $conf?*?*?*?("key")
let $value := $conf?*?*?*?("value")[$pos]
return
map:entry($key, $value))
};
declare function local:soapHeader($requestName as xs:string) as node() {
<headers>
<header name="SOAP-Action" value="http://textgrid.info/namespaces/middleware/tgauth/{ $requestName }"/>
</headers>
declare function local:soapHeader($requestName as xs:string) as node()
{
<http:header
name = "SOAP-Action"
value = "http://textgrid.info/namespaces/middleware/tgauth/{ $requestName }"
/>
};
declare function local:soapElement($requestName as xs:string, $sid as xs:string, $XML as node()*) {
......@@ -224,7 +244,17 @@ declare function local:soapElement($requestName as xs:string, $sid as xs:string,
};
declare function local:tgAuth-call($authUrl as xs:string, $soapHeader as node(), $soapElement as node()) as node()* {
httpclient:post($authUrl, $soapElement, false(), $soapHeader)//env:Body/node()
let $reqPost :=
<http:request method='post'>
{ $soapHeader }
</http:request>
return
http:send-request(
$reqPost,
$authUrl,
$soapElement
)[1]/env:Body/node()
};
declare function tgclient:tgauth-tgAssignedProjects($sid as xs:string) {
......
......@@ -24,18 +24,19 @@ declare namespace xhtml="http://www.w3.org/1999/xhtml";
: @param $uri – a textgrid uri
: @param $sid – a valid sessionId for TextGrid
: :)
declare function tgconnect:publish( $uri as xs:string,
$sid as xs:string ) {
tgconnect:publish( $uri,
$sid,
$target,
$user,
$password,
$project,
$surface,
false())
declare function tgconnect:publish( $uri as xs:string, $sid as xs:string )
{
tgconnect:publish
(
$uri,
$sid,
$target,
$user,
$password,
$project,
$surface,
false()
)
};
(:~ The main function for the publisher.
......@@ -87,14 +88,13 @@ declare function tgconnect:publish( $uri as xs:string,
then config:get("textgrid.public-triplestore")
else config:get("textgrid.nonpublic-triplestore")
(: we are repared to iterate over the uris we want to publish :)
(: we are prepared to iterate over the uris we want to publish :)
return
for $pubUri in tgclient:getAggregatedUris($tguri, $rdfstoreUrl)
let $meta := (: we should not download the metadata twice :)
if($pubUri = $tguri)
then $metadataContainer
else tgclient:getMeta($pubUri, $tgcrudUrl, $sid),
$targetUri := tgclient:remove-prefix($meta//tgmd:textgridUri/text())
! (if($preserveRevisions)
then string(.)
......@@ -147,7 +147,7 @@ declare function tgconnect:publish( $uri as xs:string,
let $relaxNGPath := $targetPath || "/data/" || $grammar || ".xml.rng"
return
if( ($grammar = "" ) or not($instance//tei:TEI) or not( doc-available( $relaxNGPath ) )) then () else
validation:validate-report($instance, doc($relaxNGPath))
validation:jaxv-report($instance, doc($relaxNGPath))
(: $grammar:)
return ($targetUri, $validate)
......
......@@ -11,10 +11,14 @@ return
then error( QName("", "DIGILI01"), "Got no ID." )
else
let $reqUrl := config:get("textgrid.digilib") || $id || "/full/" || config:get("textgrid.digilib.defaultSize") ||"/0/default.jpg"
let $header := <headers><header name="Connection" value="close"/></headers>
let $result := httpclient:get( xs:anyURI($reqUrl), false(), $header )
let $mime := xs:string($result//httpclient:header[@name="Content-Type"]/@value)
let $last-modified := xs:string($result//httpclient:header[@name="Last-Modified"]/@value)
let $cache-control := xs:string($result//httpclient:header[@name="Cache-Control"]/@value)
let $reqGet :=
<http:request method="get">
<http:header name="Connection" value="close" />
</http:request>
let $result := http:send-request($reqGet, $reqUrl)
let $mime := xs:string($result[1][@name="Content-Type"]/@value)
let $last-modified := xs:string($result[1][@name="Last-Modified"]/@value)
let $cache-control := xs:string($result[1][@name="Cache-Control"]/@value)
return
response:stream-binary(xs:base64Binary($result//httpclient:body), $mime)
response:stream-binary(xs:base64Binary($result[2]), $mime)
......@@ -4,7 +4,8 @@ xquery version "3.1";
: @author Markus Matoni
: @author Johannes Biermann
: @author Mathias Göbel
: @version 0.1
: @author Stefan Hynek
: @version 0.2
:)
module namespace confluence="https://sade.textgrid.de/ns/wiki-confluence";
......@@ -16,8 +17,10 @@ declare namespace http="http://expath.org/ns/http-client";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare variable $confluence:collection := $config:app-root || '/docs';
declare variable $confluence:httprequestget := "<http:request method='get' />";
declare function confluence:confluence($node as node(), $model as map(*), $id as xs:string) as node()* {
declare function confluence:confluence($node as node(), $model as map(*), $id as xs:string) as node()*
{
let $lastRevinDb := confluence:getLastRevInDb($id)
let $revisionInWiki := confluence:getLastRevInWiki($id)
let $revisionInWiki := if ($revisionInWiki=-1) then ($lastRevinDb) else ()
......@@ -36,11 +39,9 @@ declare function confluence:confluence($node as node(), $model as map(*), $id as
let $remove :=
xmldb:get-child-resources( $confluence:collection )[starts-with(., $id)]
! xmldb:remove($confluence:collection , . )
let $url:= xs:anyURI(config:get("confluence.url", "wiki") || $id || '?expand=body.storage')
let $persist := false()
let $request-headers:= ()
let $export := httpclient:get(xs:anyURI($url), false(), $request-headers)
let $map := xs:base64Binary($export//httpclient:body/text())
let $url:= config:get("confluence.url", "wiki") || $id || '?expand=body.storage'
let $export := http:send-request($httprequestget, $url)
let $map := xs:base64Binary($export[2]/text())
=> string()
=> util:base64-decode()
=> parse-json()
......@@ -52,7 +53,7 @@ declare function confluence:confluence($node as node(), $model as map(*), $id as
let $result := <div id="wiki">{ local:confluenceparser($result, $id) }</div>
let $allLanguages := app:getAllLanguages()
let $forLoop := map:new(
let $forLoop := map:merge(
for $el in $allLanguages
let $resultLangSpecific := local:confluenceparseLanguage($result, $el)
let $store := xmldb:store( $confluence:collection, $id || '_' || $el || '.rev' || $revisionInWiki || '.xml' , $resultLangSpecific )
......@@ -71,17 +72,18 @@ declare function confluence:confluence($node as node(), $model as map(*), $id as
: @param $nodes – confluence node(s)
: @param $lang – the target language
: :)
declare function local:confluenceparseLanguage($nodes as node()*, $lang){
declare function local:confluenceparseLanguage($nodes as node()*, $lang)
{
for $node in $nodes return
typeswitch($node)
case element ( structured-macro ) return
if( string($node/@name) = (config:get("confluence.lang", "wiki")[@code=$lang]/string(@name)))
then
element xhtml:div {
local:confluenceparseLanguage($node/rich-text-body/node(), $lang)
}
else ()
(: error( QName("https://sade.textgrid.de/ns/wiki", "CONF02"), "Language ("|| $lang ||") not supported. Request was: "||$node/@name):)
if( string($node/@name) = (config:get("confluence.lang", "wiki")[@code=$lang]/string(@name)))
then
element xhtml:div {
local:confluenceparseLanguage($node/rich-text-body/node(), $lang)
}
else ()
(: error( QName("https://sade.textgrid.de/ns/wiki", "CONF02"), "Language ("|| $lang ||") not supported. Request was: "||$node/@name):)
case element( * ) return
element {local-name($node)} {
$node/@*,
......@@ -91,7 +93,8 @@ declare function local:confluenceparseLanguage($nodes as node()*, $lang){
default return local:confluenceparseLanguage($node/node(), $lang)
};
declare function local:confluenceparser($nodes as node()*, $id){
declare function local:confluenceparser($nodes as node()*, $id)
{
for $node in $nodes return
typeswitch($node)
(:Confluence often returns an empty p element at the beginning:)
......@@ -215,6 +218,7 @@ declare function local:passthru($node as node()*, $id) as item()* {
};
(: not needed anymore, but could be handy for further usage :)
(: httpclient-syntax deprecated
declare function local:retrieveImageUrl($pageId, $imageName) {
let $url:= xs:anyURI('https://wiki.de.dariah.eu/rest/api/content/' || $pageId || '/child/attachment?filename=' || encode-for-uri($imageName))
let $persist := false()
......@@ -226,8 +230,10 @@ declare function local:retrieveImageUrl($pageId, $imageName) {
let $imageurl := $map("results")(1)("_links")("download")
return 'https://wiki.de.dariah.eu/' || $imageurl
};
:)
declare function confluence:getLastRevInDb($id) as xs:integer {
declare function confluence:getLastRevInDb($id) as xs:integer
{
let $num := xmldb:get-child-resources( $confluence:collection )[contains(., $id)][1]
=> substring-after('.rev')
=> substring-before('.xml')
......@@ -242,17 +248,20 @@ declare function confluence:getLastRevInDb($id) as xs:integer {
: Returns the last revision number we get from Confluence
: @param $id – the ID of a Confluence page
: :)
declare function confluence:getLastRevInWiki($id as xs:string) as xs:integer {
declare function confluence:getLastRevInWiki($id as xs:string) as xs:integer
{
let $rest :=
httpclient:get(
xs:anyURI(config:get("confluence.url", "wiki")||$id||"/history?expand=lastUpdated"),
false(),
())
http:send-request
(
$httprequestget,
config:get("confluence.url", "wiki")||$id||"/history?expand=lastUpdated"
)
let $statuscode := $rest/@statusCode
let $map := if ($statuscode = 200) then (parse-json(
util:base64-decode(string(xs:base64Binary($rest//httpclient:body/text())))
util:base64-decode(string(xs:base64Binary($rest[2]/text())))
))
else ()
......@@ -262,8 +271,10 @@ declare function confluence:getLastRevInWiki($id as xs:string) as xs:integer {
$revision
};
declare function local:HTML2html($node) {
declare function local:HTML2html($node)
{
for $node in $node
return
typeswitch ( $node )
case element() return element { lower-case($node/local-name()) } { $node/@*, local:HTML2html($node/node()) }
......
xquery version "3.1";
(:~
: A Module for getting and preparing wikipages from DokuWiki.
: A Module for getting and preparing wikipages from Dokuwiki.
: @author unknown
: @author Stefan Hynek
: @version 0.1
:)
module namespace wiki="http://sade.textgrid.de/ns/SADE/wiki";
......@@ -9,7 +12,8 @@ import module namespace config="https://sade.textgrid.de/ns/config" at "../confi
declare namespace http="http://expath.org/ns/http-client";
declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare function wiki:dokuwiki($node as node(), $model as map(*), $id as xs:string) as node()* {
declare function wiki:dokuwiki($node as node(), $model as map(*), $id as xs:string) as node()*
{
(: replace id not in whitelist :)
let $id:= if((config:get("dokuwiki.whitelist", "wiki")//text())[.=$id]) then $id else config:get("dokuwiki.whitelist", "wiki")//text()[1]
(: trigger image reload :)
......@@ -17,19 +21,20 @@ declare function wiki:dokuwiki($node as node(), $model as map(*), $id as xs:stri
(: test 4 new edits in DokuWiki :)
let $lastRevinDb := local:dokuwikiGetLastRevInDb($id)
let $revisionInWiki := local:dokuwikiNewModification($id, $model, $lastRevinDb)
let $doc :=
if( $revisionInWiki = $lastRevinDb )
then
doc('/sade-projects/textgrid/data/xml/doku/' || $id || '.rev' || local:dokuwikiGetLastRevInDb($id) || '.xml' )/div/*
else
let $url:= xs:anyURI(config:get("dokuwiki.url") || '/doku.php?id='||config:get("space", "dokuwiki")||':'|| $id || '&amp;rev='|| $revisionInWiki ||'&amp;u='|| config:get("dokuwiki.user") ||'&amp;p='|| config:get("dokuwiki.password") ||'&amp;do=export_xhtml')
let $persist := false()
let $request-headers:= ()
let $options:= <options><property name="http://cyberneko.org/html/properties/default-encoding" value="UTF-8"/></options>
let $export := ( httpclient:get($url, $persist, $request-headers, $options)//div[@class="dokuwiki export"]
, httpclient:get($url, $persist, $request-headers, $options)//DIV[@class="dokuwiki export"] )
let $result := if( $export//DIV ) then local:HTML2html($export) else $export
(: TODO needs check and test :)
let $reqUrl:= config:get("dokuwiki.url") || '/doku.php?id='||config:get("space", "dokuwiki")||':'|| $id || '&amp;rev='|| $revisionInWiki ||'&amp;u='|| config:get("dokuwiki.user") ||'&amp;p='|| config:get("dokuwiki.password") ||'&amp;do=export_xhtml'
let $getReq := <http:request method="GET"/>
let $response := http:send-request($getReq, $reqUrl)
let $html := util:parse-html($response[2])
let $export := ( $html//div[@class="dokuwiki export"], $html//DIV[@class="dokuwiki export"] )
let $result := if( $html//DIV ) then local:HTML2html($export) else $export
let $result := <div>{ local:dokuwikiparser( $result/*[not(@id='dw__toc')] ) }</div>
let $login := xmldb:login( '/sade-projects/textgrid/data/xml/doku/', config:get('sade.user') , config:get("sade.password"))
let $store := xmldb:store( '/sade-projects/textgrid/data/xml/doku/', $id || '.rev' || $revisionInWiki || '.xml' , $result )
......@@ -63,7 +68,8 @@ return
$lastRevinWiki
};
declare function local:HTML2html($node) {
declare function local:HTML2html($node)
{
for $node in $node
return
typeswitch ( $node )
......@@ -74,7 +80,8 @@ declare function local:HTML2html($node) {
declare function local:dokuwikiparser($nodes as node()*){
local:dokuwikiparser($nodes, false())
};
declare function local:dokuwikiparser($nodes as node()*, $char as xs:boolean){
declare function local:dokuwikiparser($nodes as node()*, $char as xs:boolean)
{
for $node in $nodes return
typeswitch($node)
case element(h1)
......@@ -273,7 +280,8 @@ declare function local:dokuwikiparser($nodes as node()*, $char as xs:boolean){
(: default return local:dokuwikiparser($node/node()):)
};
declare function local:dokuwikiTOC($nodes) {
declare function local:dokuwikiTOC($nodes)
{
for $node in $nodes return
typeswitch($node)
case element(div) return
......@@ -322,34 +330,42 @@ declare function local:dokuwikiTOC($nodes) {
default return local:dokuwikiTOC($node/node())
};
declare function local:asciiutf8($text as text(), $map as map()) as text(){
declare function local:asciiutf8($text as text(), $map as map()) as text()
{
let $pattern := map:keys($map)[1]
let $replacement := map:get( $map, $pattern )
let $newText := text { replace($text, $pattern, $replacement) }
let $newMap := map:remove( $map, $pattern )