-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.xql
214 lines (207 loc) · 9.17 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
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.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;
import module namespace doc="http://localhost:8080/exist/apps/pessoa/doc" at "modules/doc.xqm";
import module namespace author="http://localhost:8080/exist/apps/pessoa/author" at "modules/author.xqm";
import module namespace search="http://localhost:8080/exist/apps/pessoa/search" at "modules/search.xqm";
import module namespace helpers="http://localhost:8080/exist/apps/pessoa/helpers" at "modules/helpers.xqm";
if ($exist:path eq "/") then
(: forward root path to index.xql :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{$helpers:web-language}/index.html"/>
</dispatch>
(: Language Notation :)
else if (contains($exist:path, concat($helpers:web-language,"/index.html"))) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/index.html" />
<view>
<forward url="{$exist:controller}/modules/view.xql"/>
</view>
</dispatch>
else if (contains($exist:path, "doc/versao-pessoal")) then
let $lb := request:get-parameter("lb", "yes")
let $abbr := request:get-parameter("abbr", "yes")
let $version := request:get-parameter("version","diplomatic")
let $id := request:get-parameter("id", ())
return doc:get-text-pessoal(<node />, map {"test" := "test"}, $id, $lb, $abbr, $version)
else if (contains($exist:path, "/doc/")) then
if ($exist:resource = "xml") then
let $id := substring-before(substring-after($exist:path, "/doc/"), "/xml")
return
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/data/doc/{$id}.xml"/>
</dispatch>
else
(session:set-attribute("id", $exist:resource),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/page/doc.html">
<add-parameter name="id" value="{$exist:resource}" />
</forward>
<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>)
else if (contains($exist:path, "/pub/")) then
(session:set-attribute("id", $exist:resource),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/page/pub.html">
<add-parameter name="id" value="{$exist:resource}" />
</forward>
<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>)
else if (contains($exist:path, "/author/")) then
if (request:get-parameter("orderBy","")!="") then
let $orderBy := request:get-parameter("orderBy", "alphab")
let $author := substring-before(substring-after($exist:path, '/page/author/'), '/')
let $textType := $exist:resource
return
author:reorder(<node />, map {"test" := "test"},$orderBy, $textType, $author)
else
let $author := substring-before(substring-after($exist:path, '/author/'), '/')
let $textType := $exist:resource
return
(session:set-attribute("textType", $textType),
session:set-attribute("author", $author),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/page/author.html" />
<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>)
else if(contains($exist:path, "page/genre") ) then
if(request:get-parameter("orderBy",'') ) then
let $orderBy := request:get-parameter("orderBy", '')
let $type := $exist:resource
return doc:get-genre(<node />, map {"test" := "test"}, $type, $orderBy)
else (
session:set-attribute("type",$exist:resource),
session:set-attribute("orderBy","alphab"),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/page/genre.html" />
<add-parameter name="type" value="{$exist:resource}" />
<add-parameter name="orderBy" value="alphab"/>
<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>
)
else if(contains($exist:path,"page/bibliografia")) then
let $type :=$exist:resource
return (
session:set-attribute("type",$type),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/page/bibliografia.html" />
<add-parameter name="type" value="{$type}" />
<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>
)
else if (contains($exist:path,"timeline")) then
(
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/page/timeline.html" />
<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>)
else if (contains($exist:path,"obras")) then
(
session:set-attribute("id",$exist:resource),
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/page/obras.html" />
<add-parameter name="id" value="{$exist:resource}" />
<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>
)
else if (ends-with($exist:resource, ".html") and contains($exist:path,"page/")) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/page/{substring-after($exist:path,"page/")}"/>
<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>
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="{$exist:controller}/../shared-resources/{substring-after($exist:path, '/$shared/')}">
<set-header name="Cache-Control" value="max-age=3600, must-revalidate"/>
</forward>
</dispatch>
(:Suche:)
else if (contains($exist:path, "search")) then
if(request:get-parameter("orderBy", '') != "" )
then
let $orderBy := request:get-parameter("orderBy", '')
return( search:profiresult(<node />, search:profisearch(<node />, map {"test" := "test"}, request:get-parameter("term",'')), "union",$orderBy))
else
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="{$exist:controller}/page/search.html" />
<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>
else if (contains($exist:path, "events")) then
let $language := $helpers:web-language (: request:get-parameter("lang", "pt"):)
return
transform:transform((collection("/db/apps/pessoa/data/doc"), collection("/db/apps/pessoa/data/pub"))//tei:TEI, doc("/db/apps/pessoa/xslt/events.xsl"), <parameters><param name="language" value="{$language}"/></parameters>)
else
(: everything else is passed through :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<cache-control cache="yes"/>
</dispatch>