[139] | 1 | xquery version "1.0"; |
---|
[124] | 2 | |
---|
| 3 | (: |
---|
| 4 | $Id: cmd-model.xql 300 2010-03-28 22:45:52Z ljo $ |
---|
| 5 | :) |
---|
[174] | 6 | import module namespace request="http://exist-db.org/xquery/request"; |
---|
[247] | 7 | (: import module namespace json="http://www.json.org"; :) |
---|
[124] | 8 | |
---|
| 9 | import module namespace cmd-model = "http://spraakbanken.gu.se/clarin/xquery/model" |
---|
| 10 | at "xmldb:exist:///db/clarin/cmd-model.xqm"; |
---|
| 11 | |
---|
[175] | 12 | (: path="olac/OLAC/The_LINGUIST_List_Language_Resources", q="MDGroup.Actors.Actor", maxdepth=4 :) |
---|
[174] | 13 | |
---|
| 14 | declare function local:cmd-model() as item()* { |
---|
[254] | 15 | let $operation := request:get-parameter("operation", $cmd-model:queryModel), |
---|
[174] | 16 | $cmd-index := request:get-parameter("q", "MDGroup/Actors/Actor"), |
---|
| 17 | $cmd-index-path := |
---|
| 18 | if (fn:contains($cmd-index, ".")) then |
---|
| 19 | fn:translate($cmd-index, ".", "/") |
---|
| 20 | else |
---|
| 21 | $cmd-index, |
---|
[258] | 22 | $format := request:get-parameter("format", $cmd-model:responseFormatXml), |
---|
[298] | 23 | $collection := "/db/cmdi-mirror", |
---|
| 24 | $query-model-collection := fn:concat($collection, "/", if (fn:empty(request:get-parameter("collection", ()))) then "silang_data" else ""), |
---|
[300] | 25 | $query-collection := fn:concat($collection, if (fn:empty(request:get-parameter("collection", ()))) then "" else fn:concat("/", request:get-parameter("collection", ()))), |
---|
[174] | 26 | $max-depth as xs:integer := xs:integer(request:get-parameter("maxdepth", 1)) |
---|
| 27 | return |
---|
[254] | 28 | if ($operation eq $cmd-model:getCollections) then |
---|
[300] | 29 | cmd-model:get-collections($query-collection, $format, $max-depth) |
---|
[254] | 30 | else if ($operation eq $cmd-model:queryModel) then |
---|
[298] | 31 | cmd-model:query-model($cmd-index-path, $query-model-collection, $format, $max-depth) |
---|
[254] | 32 | else if ($operation eq $cmd-model:searchRetrieve) then |
---|
[292] | 33 | let $cql-query := request:get-parameter("query", "MDGroup/Actors/Actor"), |
---|
[300] | 34 | $start-item := request:get-parameter("startRecord", 1), |
---|
[292] | 35 | $end-item := request:get-parameter("iend", 50) |
---|
| 36 | |
---|
[300] | 37 | return cmd-model:search-retrieve($cql-query, $query-collection, $format, $start-item, $end-item) |
---|
[254] | 38 | else |
---|
| 39 | <error>Unknown operation</error> |
---|
| 40 | |
---|
[174] | 41 | }; |
---|
| 42 | |
---|
| 43 | local:cmd-model() |
---|