-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.xql
executable file
·322 lines (273 loc) · 13.8 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
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;
(:
if ($exist:path eq '') then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{request:get-uri()}/"/>
</dispatch>
else:)
if (contains(lower-case($exist:path),'listall.json')) then
(: forward to xql :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_all_MEI_files_from_DB_as_JSON.xql"/>
</dispatch>
)
else if (matches(lower-case($exist:path),'/file/[\da-zA-Z-_\.]+.xml$')) then
(: request a complete edition as one XML file :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_MEI_file_as_XML.xql">
<add-parameter name="file.id" value="{replace(tokenize($exist:path,'/')[last()],'.xml','')}"/>
</forward>
</dispatch>
)
else if (matches(lower-case($exist:path),'/edition/[\da-zA-Z-_\.]+/finalstate.xml$')) then
(: request a complete edition as one XML file :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_final_state_as_XML.xql">
<add-parameter name="edition.id" value="{replace(tokenize($exist:path,'/')[last() - 1],'.xml','')}"/>
</forward>
</dispatch>
)
else if (matches(lower-case($exist:path),'/edition/[\da-zA-Z-_\.]+/element/[\da-zA-Z-_\.]+.xml$')) then
(: request an element as XML snippet :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_MEI_snippet_as_XML.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 2]}"/>
<add-parameter name="element.id" value="{replace(tokenize($exist:path,'/')[last()],'.xml','')}"/>
</forward>
</dispatch>
)
else if (matches(lower-case($exist:path),'/edition/[\da-zA-Z-_\.]+/element/[\da-zA-Z-_\.]+/[\d\.]+,[\d\.]+/facsimileinfo.json$')) then
(: get information about an element for displaying it as facsimile :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_facsimile_info_for_element_as_JSON.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 4]}"/>
<add-parameter name="element.id" value="{replace(tokenize($exist:path,'/')[last() - 2],'.xml','')}"/>
<add-parameter name="w" value="{substring-before(tokenize($exist:path,'/')[last() - 1],',')}"/>
<add-parameter name="h" value="{substring-after(tokenize($exist:path,'/')[last() - 1],',')}"/>
</forward>
</dispatch>
)
else if (matches(lower-case($exist:path),'/file/[\da-zA-Z-_\.]+.svg$')) then
(: request a complete edition as one XML file :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_SVG_file_as_XML.xql">
<add-parameter name="file.id" value="{replace(tokenize($exist:path,'/')[last()],'.xml','')}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/states/overview.json$')) then
(: request a list of states for navigation :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_geneticStatesList_as_JSON.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 2]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/annotations.json$')) then
(: request a list of annotations with their metadata, excluding their content :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_annotations_as_json.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 1]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/page/[\da-zA-Z-_\.]+/annotations.json$')) then
(: request a list of annotations on a page :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_annotations_on_page_as_json.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 3]}"/>
<add-parameter name="page.id" value="{tokenize($exist:path,'/')[last() - 1]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/scars/categories.json$')) then
(: request a list of scar categories :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_scar_categories_as_JSON.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 2]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/state/[\da-zA-Z-_\.]+/otherStates/[\da-zA-Z-_\.]+/meiSnippet.xml$')) then
(: forward to xql :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_geneticState_as_XML.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 5]}"/>
<add-parameter name="state.id" value="{tokenize($exist:path,'/')[last() - 3]}"/>
<add-parameter name="other.states" value="{tokenize($exist:path,'/')[last() - 1]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/element/[\da-zA-Z-_\.]+/states/[\da-zA-Z-_\.]+/preview.xml$')) then
(: request preview rendering of an item within a staff, relative to a given set of states :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_element_preview_as_XML.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 5]}"/>
<add-parameter name="element.id" value="{tokenize($exist:path,'/')[last() - 3]}"/>
<add-parameter name="states" value="{tokenize($exist:path,'/')[last() - 1]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/element/[\da-zA-Z-_\.]+/(en|de)/description.json$')) then
(: request a summary of any given element :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_element_description_as_JSON.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 4]}"/>
<add-parameter name="element.id" value="{tokenize($exist:path,'/')[last() - 2]}"/>
<add-parameter name="lang" value="{tokenize($exist:path,'/')[last() - 1]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/firstState/meiSnippet.xml$')) then
(: request the first state of an edition as MEI snippet (which can be rendered with Verovio) :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_geneticState_as_XML.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 2]}"/>
<add-parameter name="state.id" value="''"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/reconstructionSetup.json$')) then
(: request a list of states for navigation :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_reconstruction_setup_as_JSON.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 1]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/invarianceRelations.json$')) then
(: request a list of states for navigation :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_invariance_relations_as_JSON.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 1]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/shape/[\da-zA-Z-_\.]+/info.json$')) then
(: request the MEI information related to a specified shape :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_shape_info_as_JSON.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 3]}"/>
<add-parameter name="shape.id" value="{tokenize($exist:path,'/')[last() - 1]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/object/[\da-zA-Z-_\.]+/shapes.json$')) then
(: request the shapes belonging to a given object :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_shapes_for_object_as_JSON.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 3]}"/>
<add-parameter name="object.id" value="{tokenize($exist:path,'/')[last() - 1]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/introduction.html$')) then
(: request the introductory text of an edition :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_introduction_as_HTML.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 1]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/pages.json$')) then
(: request a list of all pages in an edition :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_pages_in_edition_as_JSON.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 1]}"/>
</forward>
</dispatch>
)
else if (matches($exist:path,'/edition/[\da-zA-Z-_\.]+/measures.json$')) then
(: request a list of all pages in an edition :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_measure_overview_as_JSON.xql">
<add-parameter name="edition.id" value="{tokenize($exist:path,'/')[last() - 1]}"/>
</forward>
</dispatch>
)
(: <temp> :)
else if (matches($exist:path,'/notePositions.json$')) then
(: request a list of all pages in an edition :)
(
response:set-header("Access-Control-Allow-Origin", "*"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/resources/xql/get_note_positions_as_JSON.xql"/>
</dispatch>
)
(: </temp> :)
else if ($exist:path eq "/") then
(: forward root path to index.xql :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="index.html"/>
</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}/error-page.html" method="get"/>
<forward url="{$exist:controller}/modules/view.xql"/>
</error-handler>
</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>
else
(: everything else is passed through :)
(:<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<cache-control cache="yes"/>
</dispatch>:)
<div><h1>404</h1><p>Unable to resolve request for {$exist:path}</p></div>