forked from CliffordAnderson/shakespeare-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.xql
80 lines (71 loc) · 3.26 KB
/
controller.xql
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
79
80
xquery version "3.0";
(: Controller variables available to you to help route requests :)
declare variable $exist:path external;
declare variable $exist:resource external;
declare variable $exist:controller external;
declare variable $exist:prefix external;
declare variable $exist:root external;
if ($exist:path eq '') then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{request:get-uri()}/"/>
</dispatch>
(: Handles the default directory request :)
else if ($exist:path eq "/") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="index.html"/>
</dispatch>
(: An example of the variables passed into the controller.xql :)
else if ($exist:resource eq "controller.html") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<view>
<forward url="{$exist:controller}/modules/view.xql">
<!-- First two examples use an HTTP parameter -->
<add-parameter name="path" value="{$exist:path}"/>
<add-parameter name="resource" value="{$exist:resource}"/>
<!-- Next two examples use an HTTP session attribute -->
<set-attribute name="controller" value="{$exist:controller}"/>
<set-attribute name="prefix" value="{$exist:prefix}"/>
<!-- The last example, $exist:root, uses statically defined template default -->
</forward>
</view>
<error-handler>
<forward url="{$exist:controller}/error-page.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else if ($exist:resource eq 'demo') then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/modules/demo.xql"/>
</dispatch>
(: The HTML page is run through view.xql to expand templates :)
else if (ends-with($exist:resource, ".html")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
<error-handler>
<forward url="{$exist:controller}/error-page.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
(: This lets us reference the root in our page.html template, and have it work
: for templates which are not at the webapp's root direction (e.g., demos dir)
:)
else if (contains($exist:path, "/$root/")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{concat($exist:controller, substring-after($exist:path, '/$root'))}">
<set-header name="Cache-Control" value="max-age=3600, must-revalidate"/>
</forward>
</dispatch>
(: Resource paths starting with $shared are loaded from the shared-resources app :)
else if (contains($exist:path, "/$shared/")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="/shared-resources/{substring-after($exist:path, '/$shared/')}">
<set-header name="Cache-Control" value="max-age=3600, must-revalidate"/>
</forward>
</dispatch>
(: Everything else is just passed through :)
else
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<cache-control cache="yes"/>
</dispatch>