Mercurial > hg > mpdl-group
comparison software/eXist/webapp/mpdl/_stuff/oxygen-projects/monte-project/page-query-result.xquery @ 7:5589d865af7a
Erstellung XQL/XSL Applikation
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 08 Feb 2011 15:16:46 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
6:2396a569e446 | 7:5589d865af7a |
---|---|
1 xquery version "1.0"; | |
2 | |
3 import module namespace mpdl-time = "http://www.mpiwg-berlin.mpg.de/ns/mpdl/util/time" at "util/time.xquery"; | |
4 import module namespace mpdl-lucene = "http://www.mpiwg-berlin.mpg.de/ns/mpdl/lucene/search" at "lucene/search.xquery"; | |
5 import module namespace mpdl-text = "http://www.mpiwg-berlin.mpg.de/ns/mpdl/text" at "text/all.xquery"; | |
6 | |
7 declare namespace request = "http://exist-db.org/xquery/request"; | |
8 declare namespace transform = "http://exist-db.org/xquery/transform"; | |
9 declare namespace util = "http://exist-db.org/xquery/util"; | |
10 | |
11 | |
12 let $document := request:get-parameter("document", "agric_remet_001_la_1556") | |
13 let $mode := request:get-parameter("mode", "image") | |
14 let $pn := number(request:get-parameter("pn", "1")) | |
15 let $ftQuery := request:get-parameter("ft-query", "") | |
16 let $indexTermsStartStr := request:get-parameter("index-terms-start-str", "") | |
17 | |
18 let $currentTimeBegin := util:system-time() | |
19 let $docPath := concat("/db/archimedes/", $document, ".xml") | |
20 let $docRoot := doc($docPath) | |
21 let $archimedesInfo := $docRoot/archimedes/info | |
22 let $locator := $archimedesInfo/locator | |
23 let $countPages := count($docRoot//pb) | |
24 let $pb1 := $docRoot//pb[$pn] | |
25 let $positionOfFirstFigureAfterPB1 := count($pb1/following::figure[1]/preceding::figure) + 1 (: position der ersten figure nach pb1 :) | |
26 let $pb1ImageRefLeft := substring-before($locator, ".") | |
27 let $pb1ImageRefRight := "01" | |
28 let $pb2 := $docRoot//pb[$pn + 1] | |
29 let $errorCode := | |
30 if ($pn < $countPages + 1 and $pn > 0) | |
31 then 0 | |
32 else 1 | |
33 | |
34 let $retPageFragment := | |
35 if ($mode = "image" or $errorCode > 0) | |
36 then () | |
37 else util:get-fragment-between($pb1, $pb2, true()) | |
38 | |
39 let $returnPageFragment := util:parse($retPageFragment) (: string2xml: returns a valid xml document for that string :) | |
40 | |
41 let $ftHits := | |
42 if ($ftQuery = "") | |
43 then () | |
44 else mpdl-lucene:search($docPath, $ftQuery) | |
45 | |
46 let $indexTerms := | |
47 if($indexTermsStartStr = "") | |
48 then () | |
49 else mpdl-text:indexTerms($docRoot, $indexTermsStartStr, 100) | |
50 | |
51 let $currentTimeEnd := util:system-time() | |
52 let $neededTime := mpdl-time:duration-as-ms($currentTimeEnd - $currentTimeBegin) | |
53 | |
54 let $xmlResult := | |
55 if ($errorCode = 0) | |
56 then | |
57 <result> | |
58 <mode>{$mode}</mode> | |
59 <document-description> | |
60 <document-name>{$document}</document-name> | |
61 {$archimedesInfo} | |
62 <count-pages>{$countPages}</count-pages> | |
63 <performance>{$neededTime}</performance> | |
64 </document-description> | |
65 <page> | |
66 <number>{$pn}</number> | |
67 <image>http://nausikaa2.rz-berlin.mpg.de/digitallibrary/digilib.jsp?fn=/permanent/archimedes/{$document}/{$pb1ImageRefLeft}-{$pb1ImageRefRight}-pageimg&pn={$pn}</image> | |
68 <image-echo>http://echo.mpiwg-berlin.mpg.de/zogilib?fn=/permanent/archimedes/{$document}/{$pb1ImageRefLeft}-{$pb1ImageRefRight}-pageimg&pn={$pn}</image-echo> | |
69 <image-scaler>http://nausikaa2.rz-berlin.mpg.de/digitallibrary/servlet/Scaler?fn=/permanent/archimedes/{$document}/{$pb1ImageRefLeft}-{$pb1ImageRefRight}-pageimg&pn={$pn}</image-scaler> | |
70 <xml-url>?document={$document}&pn={$pn}&mode=xml</xml-url> | |
71 <firstFigurePosition>{$positionOfFirstFigureAfterPB1}</firstFigurePosition> | |
72 <content>{$returnPageFragment}</content> | |
73 </page> | |
74 {$ftHits} | |
75 {$indexTerms} | |
76 </result> | |
77 else if ($errorCode = 1) | |
78 then <error>No result: Page {$pn} not found</error> | |
79 else <error>undefined error: {$errorCode}</error> | |
80 | |
81 let $declare := | |
82 if ($mode = "text" or $mode = "image" or $mode = "xml") | |
83 then util:declare-option("exist:serialize", "method=html media-type=text/html omit-xml-declaration=no indent=yes encoding=UTF-8") | |
84 else util:declare-option("exist:serialize", "method=xml media-type=text/xml omit-xml-declaration=no indent=yes encoding=UTF-8") | |
85 | |
86 let $result := transform:transform($xmlResult, doc("/db/xsl/archimedes-page-fragment.xsl"), ()) | |
87 | |
88 return $result |