Repository navigation
Expand file tree
/
Copy pathcontroller.xql
More file actions
executable file
·78 lines (70 loc) · 3.59 KB
/
Copy pathcontroller.xql
File metadata and controls
executable file
·78 lines (70 loc) · 3.59 KB
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
78
xquery version "3.1";
(: IMPORTS ================================================================= :)
import module namespace edition="http://www.edirom.de/xquery/edition" at "data/xqm/edition.xqm";
(: NAMESPACE DECLARATIONS ================================================== :)
declare namespace exist="http://exist.sourceforge.net/NS/exist";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace request="http://exist-db.org/xquery/request";
(: VARIABLE DECLARATIONS =================================================== :)
declare variable $exist:path external;
declare variable $exist:resource external;
declare variable $exist:prefix external;
declare variable $exist:controller external;
let $langVal := edition:getLanguage(request:get-parameter("edition", ""))
return
if ($exist:path eq "") then
(: forward missing / to / :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{request:get-uri()}/"/>
</dispatch>
else if ($exist:path eq "/") then
(: redirect root path to index.html :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="index.html"/>
</dispatch>
else if ($exist:path eq "/index.html") then
(: forward index.html to index.xql :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="index.xql">
<add-parameter name="lang" value="{$langVal}"/>
</forward>
</dispatch>
(:else if (starts-with($exist:path, "/data")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<!--<redirect url="/exist/restxq{$exist:path}"/>-->
<forward servlet="RestXqServlet"/>
</dispatch>:)
else if (
(: serve static API documentation page :)
($exist:path eq "/api.html") or
($exist:path eq "/api.json")
) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/data/api/{$exist:path}"/>
</dispatch>
else if (starts-with($exist:path, "/api")) then
(: forward /api to api.xql :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/data/xql/api.xql">
<set-header name="Access-Control-Allow-Origin" value="*"/>
<set-header name="Access-Control-Allow-Headers" value="*"/>
<set-header name="Access-Control-Allow-Methods" value="GET,OPTIONS"/>
<set-attribute name="exist:path" value="{$exist:path}"/>
<set-attribute name="exist:resource" value="{$exist:resource}"/>
<set-attribute name="exist:controller" value="{$exist:controller}"/>
<set-attribute name="exist:prefix" value="{$exist:prefix}"/>
<cache-control cache="yes"/>
</forward>
</dispatch>
else
(: everything else is passed through :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<set-header name="Access-Control-Allow-Origin" value="*"/>
<set-header name="Access-Control-Allow-Headers" value="*"/>
<set-header name="Access-Control-Allow-Methods" value="GET,OPTIONS"/>
<set-attribute name="exist:path" value="{$exist:path}"/>
<set-attribute name="exist:resource" value="{$exist:resource}"/>
<set-attribute name="exist:controller" value="{$exist:controller}"/>
<set-attribute name="exist:prefix" value="{$exist:prefix}"/>
<cache-control cache="yes"/>
</dispatch>