diff --git a/controller.xql b/controller.xql index 5ed8a9db2..23a843d34 100644 --- a/controller.xql +++ b/controller.xql @@ -236,6 +236,14 @@ else if (matches($exist:path, '^/cmif_v2.xml$')) then +(: OAI-PMH-Interface :) +else if (matches($exist:path, '/(en|de)?/?' || config:get-option('generalIdPattern') || '(.*)/oai.xml')) then + + + + + + (: Sitemap :) else if (matches($exist:path, '^/sitemap(/?|/index.xml)?$') or matches($exist:path, '^/sitemap/sitemap_(en|de).xml.(gz|zip)$')) then diff --git a/modules/oai.xql b/modules/oai.xql new file mode 100644 index 000000000..62df547c2 --- /dev/null +++ b/modules/oai.xql @@ -0,0 +1,136 @@ +xquery version "3.1" encoding "UTF-8"; + +(:~ + : Module for exporting data as oai/xml + : see https://www.openarchives.org/OAI/openarchivesprotocol.html + :) + +declare namespace tei="http://www.tei-c.org/ns/1.0"; +declare namespace mei="http://www.music-encoding.org/ns/mei"; +declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization"; +declare namespace request="http://exist-db.org/xquery/request"; +declare namespace response="http://exist-db.org/xquery/response"; +declare namespace util="http://exist-db.org/xquery/util"; +declare namespace oai="http://www.openarchives.org/OAI/2.0/"; + +import module namespace functx="http://www.functx.com"; +import module namespace crud="http://xquery.weber-gesamtausgabe.de/modules/crud" at "crud.xqm"; +import module namespace config="http://xquery.weber-gesamtausgabe.de/modules/config" at "config.xqm"; +import module namespace wega-util="http://xquery.weber-gesamtausgabe.de/modules/wega-util" at "wega-util.xqm"; +import module namespace date="http://xquery.weber-gesamtausgabe.de/modules/date" at "xmldb:exist:///db/apps/WeGA-WebApp-lib/xquery/date.xqm"; +import module namespace str="http://xquery.weber-gesamtausgabe.de/modules/str" at "xmldb:exist:///db/apps/WeGA-WebApp-lib/xquery/str.xqm"; +import module namespace mycache="http://xquery.weber-gesamtausgabe.de/modules/cache" at "xmldb:exist:///db/apps/WeGA-WebApp-lib/xquery/cache.xqm"; +import module namespace lod="http://xquery.weber-gesamtausgabe.de/modules/lod" at "lod.xqm"; +import module namespace lang="http://xquery.weber-gesamtausgabe.de/modules/lang" at "lang.xqm"; +import module namespace query="http://xquery.weber-gesamtausgabe.de/modules/query" at "query.xqm"; +import module namespace wdt="http://xquery.weber-gesamtausgabe.de/modules/wdt" at "wdt.xqm"; + +declare option output:method "xml"; +declare option output:media-type "application/xml"; +declare option output:indent "yes"; + +(:~ + : Get the last date of modification from dataHistory.xml. Fallback: VersionDate from options.xml + : @author Dennis Ried + : + : @param $docID The ID of the document + : return The date ad xs:dateTime or empty +:) +declare %private function oai:last-modified($docID) as xs:dateTime { + let $props := config:get-data-props($docID) + return + if($props?dateTime castable as xs:dateTime) + then ($props?dateTime => xs:dateTime()) + else (fn:current-dateTime()) +}; + +(:~ + : Create a header response + : + : @author Dennis Ried +:) +declare %private function oai:response-headers($docID) as empty-sequence() { + response:set-header('Access-Control-Allow-Origin', '*'), + response:set-header('Last-Modified', date:rfc822(oai:last-modified($docID))), + response:set-header('Cache-Control', 'max-age=300,public') +}; + +(:~ + : Creating the response for the interface (header, calling record by oai:record) + : + : @author Dennis Ried +:) +declare function oai:oai($model as map(*)) as node() { + + {fn:current-dateTime()} + http://www.openarchives.org/OAI/2.0/oai_dc/ + + {oai:record($model)} + + +}; + +(:~ + : Creating the record for the called file (body of response) + : + : @author Dennis Ried +:) +declare function oai:record($model as map(*)) as node() { + let $docID := $model('docID') + let $lang := $model('lang') + let $dc-date := oai:last-modified($docID) => substring(1,10) + let $lod-metadata := lod:metadata(, $model, $lang) + return + +
+ {$lod-metadata?DC.identifier} + {fn:current-dateTime()} + {$model('docType')} +
+ + + {$lod-metadata?meta-page-title} + {$lod-metadata?DC.creator} + {$lod-metadata?DC.subject} + {$lod-metadata?DC.description} + {$dc-date} + {$docID} + + + + + + {config:get-option('permaLinkPrefix')} + {$docID} + {$dc-date} + http://www.openarchives.org/OAI/2.0/oai_dc/ + + + +
+}; + +let $lang := config:guess-language(()) +let $docID := request:get-attribute('docID') +let $doc := crud:doc($docID) +let $model := + map { + 'lang': $lang, + 'docID': $docID, + 'doc': $doc, + 'docType': config:get-doctype-by-id($docID), + 'lod': lod:metadata(, $model, $lang) + } +return + ( + oai:response-headers($docID), + response:set-status-code(202), + oai:oai($model) + ) \ No newline at end of file