1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| xquery version "3.0";
declare option exist:serialize "method=xhtml mediatype=text/xml";
(:--------------------------------------------------------------------------------------------------------------:)
(:----------------------------------------- FCT ----------------------------------------------:)
(:--------------------------------------------------------------------------------------------------------------:)
declare function local:getTimeFormated()
{
let $dateTime := fn:string(fn:current-dateTime())
let $dateTimeFormated := concat(substring-before($dateTime,'.'),'Z')
return $dateTimeFormated
};
declare function local:getHeader($identifiers,$start)
{
let $ITEMS := if(count($identifiers)>100)then subsequence($identifiers,fn:number($start),100) else $identifiers
for $article in $ITEMS
return
<header>
<identifier>{concat('oai:exist.kikoo.com:',$article/article/ean/text())}</identifier>
<datestamp>{$article/header/updated/text()}</datestamp>
<setSpec>BDNUM</setSpec>
</header>
};
declare function local:getResumptionToken($nbIdentifiers,$start,$from,$until,$metadataPrefix)
{
let $fromBis := if($from ='')then '0000-00-00' else $from
let $untilBis := if($until ='')then '0000-00-00' else $until
let $startBis := $start + 100
let $resumptionToken := if($nbIdentifiers>100 and $startBis <= $nbIdentifiers )then
<resumptionToken expirationDate="{local:getTimeFormated()}" completeListSize="{$nbIdentifiers}" cursor="{$start}">
{concat($fromBis,'!',$untilBis,'!',$startBis,'!',$metadataPrefix)}
</resumptionToken>
else ''
return $resumptionToken
};
(:--------------------------------------------------------------------------------------------------------------:)
(:----------------------------------------- MAIN ----------------------------------------------:)
(:--------------------------------------------------------------------------------------------------------------:)
let $metadataPrefix:= request:get-parameter("metadataPrefix",'')
let $set := request:get-parameter("set",'')
let $from := request:get-parameter("from",'')
let $until := request:get-parameter("until",'')
let $start := fn:number(request:get-parameter("start",'1'))
let $identifiers := if($from='' and $until='')then collection('BDX/ITEMS')/bdx[foo/album !='']
else if($from!='' and $until='') then collection('BDX/ITEMS')/bdx[foo/album !='' and header/updated >= $from]
else if($from='' and $until!='') then collection('BDX/ITEMS')/bdx[foo/album !='' and header/updated <= $until]
else collection('BDX/ITEMS')/bdx[foo/album !='' and header/updated >= $from and header/updated <= $until]
let $listIdentifiers := if(count($identifiers)>1)then
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>{local:getTimeFormated()}</responseDate>
<request metadataPrefix="{$metadataPrefix}" verb="ListIdentifiers">http://exist.kikoo.com:8080/exist/rest/db/PROC/OAI/</request>
<ListIdentifiers>
{local:getHeader($identifiers,$start)}
{local:getResumptionToken(count($identifiers),$start,$from,$until,$metadataPrefix)}
</ListIdentifiers>
</OAI-PMH>
else
<OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
<responseDate>{local:getTimeFormated()}</responseDate>
<request verb="ListIdentifiers">http://exist.kikoo.com:8080/exist/rest/db/PROC/OAI/</request>
<error code="noRecordsMatch">The combination of the values of the from, until, set, and metadataPrefix arguments results in an empty list.</error>
</OAI-PMH>
return $listIdentifiers |
Partager