@@ -12,6 +12,8 @@ import module namespace config="http://srophe.org/srophe/config" at "../config.x
1212import module namespace cntneg="http://srophe.org/srophe/cntneg" at "content-negotiation.xqm" ;
1313import module namespace tei2html="http://srophe.org/srophe/tei2html" at "tei2html.xqm" ;
1414
15+ import module namespace rh = "http://localhost/manuForma/request-helper" at "../request-helper.xqm" ;
16+
1517(: Data processing module. :)
1618import module namespace data="http://srophe.org/srophe/data" at "../lib/data.xqm" ;
1719
@@ -26,6 +28,22 @@ declare namespace rest = "http://exquery.org/ns/restxq";
2628declare namespace http="http://expath.org/ns/http-client" ;
2729declare namespace srophe="https://srophe.app" ;
2830
31+ declare variable $local:api as xs:string? := rh:request-param ("api" );
32+ declare variable $local:collection as xs:string? := rh:request-param ("collection" );
33+ declare variable $local:doc as xs:string? := rh:request-param ("doc" );
34+ declare variable $local:element as xs:string? := rh:request-param ("element" );
35+ declare variable $local:exist-collection as xs:string? := rh:request-param ("existCollection" );
36+ declare variable $local:format as xs:string := rh:request-param ("format" , "xml" );
37+ declare variable $local:geo as xs:string? := rh:request-param ("geo" );
38+ declare variable $local:id as xs:string? := rh:request-param ("id" );
39+ declare variable $local:limit as xs:string? := rh:request-param ("limit" );
40+ declare variable $local:per-page as xs:integer := rh:request-param-integer ("perpage" , 10 );
41+ declare variable $local:q as xs:string* := rh:request-param ("q" );
42+ declare variable $local:results as xs:string? := rh:request-param ("results" );
43+ declare variable $local:start as xs:integer := rh:request-param-integer ("start" , 1 );
44+ declare variable $local:type as xs:string? := rh:request-param ("type" );
45+ declare variable $local:wrap-element as xs:QName? := rh:request-param ("wrapElement" ) ! xs:QName (.);
46+
2947(:~
3048 : Search API
3149 : @note : This function is important! Used by eKtobe
@@ -48,10 +66,10 @@ declare function local:search-element($element as xs:string?, $q as xs:string*,
4866 for $c in tokenize ($collection,',' )
4967 return data:apiSearch ($c, $e, $q, ())
5068 else data:apiSearch ($collection, $e, $q, ())
51- let $hits := if (request:get-parameter ( ' limit' , '' ) != '' ) then
69+ let $hits := if ($local: limit) then
5270 for $hit in $hits
5371 let $id := replace ($hit/ancestor-or-self::tei:TEI/descendant::tei:publicationStmt/tei:idno[@type ='URI' ][1 ],'/tei' ,'' )
54- where contains ($id,request:get-parameter ( 'limit' , '' ) )
72+ where contains ($id, $limit )
5573 return $hit
5674 else $hits
5775 return
@@ -104,8 +122,10 @@ declare function local:search-element($element as xs:string?, $q as xs:string*,
104122 <bibl xmlns = "http://www.tei-c.org/ns/1.0" >
105123 <bibl xmlns = "http://www.tei-c.org/ns/1.0" xml:id = "{$xmlID[1 ]} " >
106124 {
107- element {xs:QName (request:get-parameter ('wrapElement' , '' ))}
108- {attribute { "ref" } { $recID }, $headword[1 ]}
125+ element { ($local:wrap-element, 'value' )[1 ] } {
126+ attribute { "ref" } { $recID },
127+ $headword[1 ]
128+ }
109129 }
110130 <ptr target = "{$recID} " />
111131 </bibl>
@@ -143,19 +163,20 @@ declare function local:search-element($element as xs:string?, $q as xs:string*,
143163 {attribute { "ref" } { $recID }, concat ($type,$headword[1 ]) }
144164 </passive>
145165 else ()
146- else if (request:get-parameter ('wrapElement' , '' ) != '' ) then
147- if (request:get-parameter ('wrapElement' , '' ) = 'author' ) then
148- element {xs:QName (request:get-parameter ('wrapElement' , '' ))}
149- {attribute { "ref" } { $recID }, $headword[1 ]}
150- else if (request:get-parameter ('wrapElement' , '' ) = 'relation' ) then
151- element {xs:QName (request:get-parameter ('wrapElement' , '' ))}
152- {attribute { "ref" } { $recID }, $headword[1 ]}
166+ else if ($local:wrap-element) then
167+ if (local-name-from-QName ($local:wrap-element) = ('author' , 'relation' )) then
168+ element { $local:wrap-element } {
169+ attribute { "ref" } { $recID },
170+ $headword[1 ]
171+ }
153172 else
154- element {xs:QName (request:get-parameter ('wrapElement' , '' ))}
155- {attribute { "ref" } { $recID },
156- element {xs:QName ($element)}
157- {attribute { "ref" } { $recID }, $headword[1 ] }
173+ element { $local:wrap-element } {
174+ attribute { "ref" } { $recID },
175+ element { xs:QName ($element) } {
176+ attribute { "ref" } { $recID },
177+ $headword[1 ]
158178 }
179+ }
159180 else
160181 element {xs:QName ($element)}
161182 {attribute { "ref" } { $recID }, $headword[1 ] }
@@ -211,25 +232,21 @@ declare function local:coordinates($type as xs:string?, $collection as xs:string
211232 return util:eval ($path)
212233};
213234
214- let $path := if (request:get-parameter ('id' , '' ) != '' ) then
215- request:get-parameter ('id' , '' )
216- else if (request:get-parameter ('doc' , '' ) != '' ) then
217- request:get-parameter ('doc' , '' )
218- else ()
235+ let $path as xs:string? := ($local:id, $local:doc)[1 ]
219236let $data :=
220- if ( request:get-parameter ( 'id' , '' ) != '' or request:get-parameter ( 'doc' , '' ) != '' ) then
237+ if ($path ) then
221238 data:get-document ()
222- else if ( request:get-parameter-names () != '' ) then
223- if ( request:get-parameter ( ' api' , '' ) != '' ) then
224- if ( request:get-parameter ( ' element' , '' ) != '' and request:get-parameter ( 'q' , '' ) != '' ) then
225- local:search-element (request:get-parameter ( ' element' , '' ), request:get-parameter ( 'q' , '' ), if ( request:get-parameter ( ' collection' , '' )) then request:get-parameter ( 'collection' , '' ) else () )
226- else if ( request:get-parameter ( ' geo' , '' ) != '' ) then
227- local:coordinates (request:get-parameter ( ' type' , '' ), request:get-parameter ( ' collection' , '' ) )
239+ else if ( exists ( request:get-parameter-names ()) ) then
240+ if ($local: api) then
241+ if ( exists ($local: element) and exist ($local:q) ) then
242+ local:search-element ($local: element, $local:q, $local: collection)
243+ else if ($local: geo) then
244+ local:coordinates ($local: type, $local: collection)
228245 else <div>Nothing, check params: {request:get-parameter-names ()}</div>
229246 else
230247 let $collectionParam :=
231- if ( request:get-parameter ( 'existCollection' , '' ) != '' ) then
232- tokenize (replace (request:get-parameter ( 'existCollection' , '' ), ' /tei' ,'' ),'/' )[last ()]
248+ if ($local:exist-collection ) then
249+ tokenize (replace ($local:exist-collection, ' /tei' , '' ), '/' )[last ()]
233250 else ()
234251let $collection := $collectionParam
235252 let $hits := data:search ($collection,'' ,'' )
@@ -241,24 +258,22 @@ let $collection := $collectionParam
241258 return concat ('& ' ,$param, '=' ,request:get-parameter ($param, '' )),'' )}</action>
242259 <info count = "{count ($hits)} " >hits: {count ($hits)}</info>
243260 {
244- let $start := if (request:get-parameter ('start' ,'' ) != '' ) then request:get-parameter ('start' ,'' ) else '1'
245- let $perpage := if (request:get-parameter ('perpage' , 10 )) then request:get-parameter ('perpage' , 10 ) else 10
246- let $next := xs:integer ($start) + xs:integer ($perpage)
261+ let $next := xs:integer ($local:start) + xs:integer ($local:per-page)
247262 return
248- (<start>{$start}</start>,
263+ (<start>{$local: start}</start>,
249264 if ($next lt count ($hits)) then
250265 <next>{$next}</next>
251266 else (),
252267 <results>{
253268
254- for $hit in subsequence ($hits,$ start,$perpage )
269+ for $hit in subsequence ($hits, $local: start, $local:per-page )
255270 let $id := replace ($hit/descendant::tei:idno[starts-with (.,$config:base-uri)][1 ],'/tei' ,'' )
256271 let $title := $hit/descendant::tei:titleStmt/tei:title[1 ]
257272 let $expanded := kwic:expand ($hit)
258273 return
259274 <json:value json:array = "true" >
260275 {
261- if ( request:get-parameter ( ' results' , '' ) = 'manuForma' ) then
276+ if ($local: results = 'manuForma' ) then
262277 <record src = "{document-uri (root ($hit))} " name = "{$title} " idno = "{concat ('[' ,$id,']' )} " />
263278 else ()
264279 }
@@ -319,16 +334,15 @@ let $collection := $collectionParam
319334 </json:value>
320335 </root>
321336 else ()
322- let $format := if (request:get-parameter ('format' , '' ) != '' ) then request:get-parameter ('format' , '' ) else 'xml'
323337return
324338 if (not (empty ($data))) then
325- if ( request:get-parameter ( ' api' , '' ) != '' ) then
326- if ( request:get-parameter ( ' geo' , '' ) ) then
327- if ($format = 'kml' ) then
339+ if ($local: api) then
340+ if ($local: geo) then
341+ if ($local: format = 'kml' ) then
328342 cntneg:content-negotiation ($data,'kml' ,())
329343 else cntneg:content-negotiation ($data,'geojson' ,())
330344 else
331- let $format := if ( request:get-parameter ( ' format' , '' ) = 'xml' ) then 'xml' else 'json'
345+ let $format := if ($local: format eq 'xml' then 'xml' else 'json'
332346 return cntneg:content-negotiation ($data, $format, ())
333347 else cntneg:content-negotiation ($data, $format, $path)
334- else ()
348+ else ()
0 commit comments