-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.xql
351 lines (316 loc) · 12.7 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
xquery version "3.0";
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;
(:let $query := request:get-parameter("q", ())
return:)
if ($exist:path eq "") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{request:get-uri()}/"/>
</dispatch>
else if ($exist:path eq "/") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="index.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</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>
(: Resources must be placed before other rules in order that stylesheets work :)
else if (contains($exist:path, "resources/")) then
let $resourcePath := substring-after($exist:path, "resources/")
let $url := $exist:controller || '/resources/' || $resourcePath
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$url}">
<cache-control cache="yes"/>
</forward>
</dispatch>
(:else if (starts-with($exist:path, ("/uub", "/lub", "/lsb", "/kb", "/gub", "/ra", "/skokl", "/nm", "/ms/"))) then:)
else if (matches($exist:path, '^/ms/\d+$')) then
let $id := $exist:resource
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/view.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql">
<add-parameter name="id" value="{$id}.xml"/>
</forward>
</view>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else if (matches($exist:path, '^/person/\d+$')) then
let $id := $exist:resource
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/view_person.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql">
<add-parameter name="person" value="{$id}.xml"/>
</forward>
</view>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else if (matches($exist:path, '^/place/\d+$')) then
let $id := $exist:resource
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/view_place.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql">
<add-parameter name="place" value="{$id}.xml"/>
</forward>
</view>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else if (matches($exist:path, '^/bibl/\d+$')) then
let $id := $exist:resource
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/view_bibl.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql">
<add-parameter name="bibl" value="{$id}.xml"/>
</forward>
</view>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else if (matches($exist:path, '^/org/\d+$')) then
let $id := $exist:resource
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/view_org.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql">
<add-parameter name="org" value="{$id}.xml"/>
</forward>
</view>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else if (matches($exist:path, '^/work/\d+$')) then
let $id := $exist:resource
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/view_work.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql">
<add-parameter name="work" value="{$id}.xml"/>
</forward>
</view>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
(:else if (matches($exist:path, '^/xml/\d+$')) then:)
else if (matches($exist:path, '^/ms/\d+\.xml$')) then
let $id := $exist:resource
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/data/msDescs/{$id}"/>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else if (matches($exist:path, '^/bibl/\d+\.xml$')) then
let $id := $exist:resource
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/data/id/bibl/{$id}"/>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else if (matches($exist:path, '^/org/\d+\.xml$')) then
let $id := $exist:resource
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/data/id/org/{$id}"/>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else if (matches($exist:path, '^/person/\d+\.xml$')) then
let $id := $exist:resource
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/data/id/person/{$id}"/>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else if (matches($exist:path, '^/place/\d+\.xml$')) then
let $id := $exist:resource
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/data/id/place/{$id}"/>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else if (matches($exist:path, '^/work/\d+\.xml$')) then
let $id := $exist:resource
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/data/id/work/{$id}"/>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else if ($exist:path eq "/guidelines") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{concat($exist:controller, "/guidelines.html")}"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/search") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{concat($exist:controller, "/search.html")}"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/results") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{concat($exist:controller, "/results.html")}"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/contact") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/contact.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/greek") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/greek_manuscripts.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/swedish") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/old_swedish_manuscripts.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/browse/manuscripts") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/manuscripts.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/browse/manuscripts/greek") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/manuscripts-greek.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/browse/manuscripts/swedish") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/manuscripts-swedish.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/browse/authors") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/authors.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/browse/incipits") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/incipits.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/browse/scribes") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/scribes.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/mirador") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/mirador.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/mirador_greek") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/mirador_greek.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/mirador_ttt") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/mirador_ttt.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if ($exist:path eq "/KB-medeltida") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/KB-medeltida.html"/>
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if (ends-with($exist:resource, ".html")) then
(: the html page is run through view.xql to expand templates :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
<error-handler>
<forward url="{$exist:controller}/404.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</dispatch>
else
(: everything else is passed through :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<cache-control cache="yes"/>
</dispatch>