Mercurial > hg > mpdl-group
view software/eXist/webapp/mpdl/text/all.xql @ 17:7e883ce72fec
diverse Fehlerbehebungen
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 27 Sep 2011 16:41:15 +0200 |
parents | d6f528ad5d96 |
children |
line wrap: on
line source
xquery version "1.0"; module namespace mpdl-text = "http://www.mpiwg-berlin.mpg.de/ns/mpdl/text"; import module namespace functx = "http://www.functx.com" at "../util/functx.xql"; declare namespace text = "http://exist-db.org/xquery/text"; declare namespace util = "http://exist-db.org/xquery/util"; declare namespace local = "http://www.mpiwg-berlin.mpg.de/ns/mpdl/local"; declare namespace echo="http://www.mpiwg-berlin.mpg.de/ns/echo/1.0/"; declare namespace TEI="http://www.tei-c.org/ns/1.0"; declare namespace dcterms="http://purl.org/dc/terms"; declare function mpdl-text:insertNodeIdAttribute($element as element()) { element {node-name($element)} {$element/@*, attribute { "xmlNodeId" } { util:node-id($element) }, for $child at $pos in $element/node() return if ($child instance of element()) then mpdl-text:insertNodeIdAttribute($child) else $child } }; declare function mpdl-text:insertMyNodeIdAttribute($element as element()) { mpdl-text:insertMyNodeIdAttribute($element, "1") }; declare function mpdl-text:insertMyNodeIdAttribute($element as element(), $myNodeId as xs:string) { element {node-name($element)} {$element/@*, attribute { "xmlNodeId" } { $myNodeId }, for $child at $pos in $element/node() return if ($child instance of element()) then mpdl-text:insertMyNodeIdAttribute($child, concat($myNodeId, ".", $pos)) else $child } }; declare function mpdl-text:indexTerms($mpdlCollectionName, $language, $document, $indexTermsStartStr, $pn as xs:int, $pageSize as xs:int) as node()* { let $index := if ($mpdlCollectionName = 'archimedes') then $document/archimedes/text else if ($mpdlCollectionName = 'echo') then $document/echo:echo/echo:text else if ($mpdlCollectionName = 'tei') then $document/TEI:TEI/TEI:text else $document/*[1] let $from := ($pn * $pageSize) - $pageSize + 1 let $to := $pn * $pageSize let $maxTo := 10000 let $callback := util:function(QName("http://www.mpiwg-berlin.mpg.de/ns/mpdl/local", "local:termEntries"), 2) let $indexResult := text:index-terms($index, $indexTermsStartStr, $callback, $maxTo) let $count := count($indexResult) let $pages := if ($count = 0) then 0 else $count idiv $pageSize + 1 let $withPolluxKeys := 'true' let $resultEntries := for $entry at $pos in $indexResult let $term := $entry/term let $lexEntryKeys := if ($withPolluxKeys = 'true') then mpdltext:get-lex-entry-keys-by-form-name($language, $term) else '' let $lemmasWithOR := mpdltext:get-lemmasstr-by-form-name($language, $term) where $pos >= $from and $pos <= $to return <entry> <term>{$entry/term}</term> <pollux-keys>{$lexEntryKeys}</pollux-keys> <lemmas-with-or>{$lemmasWithOR}</lemmas-with-or> <frequency>{$entry/frequency}</frequency> <documents>{$entry/documents}</documents> <position>{$entry/position}</position> <rank>{$entry/rank}</rank> </entry> let $callbackBig5 := if ($language = "zh") then util:function(QName("http://www.mpiwg-berlin.mpg.de/ns/mpdl/local", "local:termEntriesInBig5"), 2) else () let $indexResultBig5 := if ($language = "zh") then text:index-terms($index, $indexTermsStartStr, $callbackBig5, $maxTo) else () let $resultEntriesBig5 := if ($language = "zh") then for $entry at $pos in $indexResultBig5 where $pos >= $from and $pos <= $to return $entry else () let $result := <result> <size>{$count}</size> <page-size>{$pageSize}</page-size> <pages>{$pages}</pages> <pn>{$pn}</pn> <hits>{$resultEntries}</hits> <big5-hits>{$resultEntriesBig5}</big5-hits> </result> return $result }; declare function local:termEntries($term as xs:string, $data as xs:int+) { let $result := <entry> <term>{$term}</term> <frequency>{$data[1]}</frequency> <documents>{$data[2]}</documents> <position>{$data[3]}</position> <rank>{$data[4]}</rank> </entry> return $result }; declare function local:termEntriesInBig5($term as xs:string, $data as xs:int+) { let $encodedTerm := mpdltext:encode-big5($term) let $result := <entry-big5-encoded> <term>{$encodedTerm}</term> </entry-big5-encoded> return $result }; declare function mpdl-text:get-toc($docBase, $queryType, $document, $pn as xs:int, $pageSize as xs:int) { let $from := ($pn * $pageSize) - $pageSize + 1 let $to := $pn * $pageSize let $tocEntriesAll := if ($docBase = 'echo' and $queryType = 'toc') then $document//echo:div[@type = 'section' or @type = 'chapter'] else if ($docBase = 'echo' and $queryType = 'figures') then $document//echo:figure else if ($docBase = 'archimedes' and $queryType = 'figures') then $document//figure else if ($docBase = 'tei' and $queryType = 'figures') then $document//TEI:figure else () let $tocEntriesAllTmp := for $entry at $pos in $tocEntriesAll let $pb := if ($docBase = 'echo') then $entry/preceding::echo:pb[1] else if ($docBase = 'tei') then $entry/preceding::TEI:pb[1] else $entry/preceding::pb[1] let $pageNum := if ($docBase = 'echo') then count($pb/preceding::echo:pb) + 1 else if ($docBase = 'tei') then count($pb/preceding::TEI:pb) + 1 else count($pb/preceding::pb) + 1 let $level := if ($queryType = 'toc') then number($entry/@level) else 1 let $figureCaption := if ($docBase = 'echo' and $queryType = 'figures' and not(empty($entry/echo:caption))) then concat(': ', string-join($entry/echo:caption/text(), ' ')) else '' let $figureDescription := if ($docBase = 'echo' and $queryType = 'figures' and not(empty($entry/echo:description))) then concat(': ', string-join($entry/echo:description/text(), ' ')) else '' let $figureVariables := if ($docBase = 'echo' and $queryType = 'figures' and not(empty($entry/echo:variables))) then concat(' (Variables: ', string-join($entry/echo:variables/text(), ' '), ')') else '' let $figureAllDesc := if ($docBase = 'echo' and $queryType = 'figures') then concat($figureCaption, $figureDescription, $figureVariables) else '' let $content := if ($docBase = 'echo' and $queryType = 'toc') then string-join($entry/echo:head, ' ') else if ($queryType = 'figures') then concat('Figure', $figureAllDesc) else () return <toc-entry> <page>{$pageNum}</page> <level>{$level}</level> <content>{$content}</content> </toc-entry> let $tocEntriesAllTmpWithLevels := mpdltext:generate-toc-levels($tocEntriesAllTmp)/toc-entries/toc-entry let $tocEntries := for $entry at $pos in $tocEntriesAllTmpWithLevels where $pos >= $from and $pos <= $to return $entry let $size := count($tocEntriesAll) let $pages := if ($size = 0) then 0 else $size idiv $pageSize + 1 let $result := <result> <size>{$size}</size> <page-size>{$pageSize}</page-size> <pages>{$pages}</pages> <pn>{$pn}</pn> <hits>{$tocEntries}</hits> </result> return $result }; declare function mpdl-text:getEchoArchivePath($mpdlDocUri) { let $documentName := substring-before(substring-after(substring-after(substring-after($mpdlDocUri, "/"), "/"), "/"), ".") let $language := substring-before(substring-after(substring-after($mpdlDocUri, "/"), "/"), "/") let $docbase := substring-before(substring-after($mpdlDocUri, "/"), "/") let $fullDocumentUri := concat('/db/mpdl/documents/standard', $mpdlDocUri) let $document := doc($fullDocumentUri) let $metadata := if ($docbase = 'archimedes') then $document/archimedes/info else if ($docbase = 'echo') then $document/echo:echo/echo:metadata else if ($docbase = 'tei') then $document/TEI:TEI/TEI:teiHeader else () let $documentIdentifier := if ($docbase = 'archimedes') then $metadata/locator else if ($docbase = 'echo') then $metadata/dcterms:identifier else if ($docbase = 'tei') then $metadata/TEI:fileDesc/TEI:publicationStmt/TEI:idno else $metadata/dcterms:identifier let $echoDocIdentifier := if ($documentIdentifier != '') then substring-before(substring-after($documentIdentifier, "ECHO:"), ".") else '' let $nausikaaURLTexter := "http://nausikaa2.mpiwg-berlin.mpg.de/digitallibrary/servlet/Texter" let $echoImageDir := if ($docbase = 'archimedes') then string($metadata/echodir) else if ($docbase = 'echo') then string($metadata/echo:echodir) else '' let $imagesDocDirectory := if ($echoImageDir != '') then $echoImageDir else if ($docbase = 'archimedes') then concat("/permanent/archimedes/", $documentName) else if ($docbase = 'echo') then concat("/permanent/library/", $echoDocIdentifier) else if ($docbase = 'tei') then $documentIdentifier else '' let $imagesDocDirectoryIndexMetaUrl := concat($nausikaaURLTexter, "?fn=", $imagesDocDirectory, "/index.meta") let $digilibAvailable := mpdldoc:check-uri($imagesDocDirectoryIndexMetaUrl, 2000) let $imagesDocDirectoryIndexMeta := if ($digilibAvailable) then doc($imagesDocDirectoryIndexMetaUrl) else "XXXXDigilibNotAvailableXXXX" let $archivePath := if ($digilibAvailable) then string($imagesDocDirectoryIndexMeta/resource/archive-path) else $imagesDocDirectoryIndexMeta return $archivePath }; declare function mpdl-text:transform($inputXml, $xslFileName) { let $pageXslDoc := doc($xslFileName) let $result := transform:transform($inputXml, $pageXslDoc, ()) return $result }; declare function mpdl-text:html2pdf($language, $inputXml, $xslFileName, $title, $pageNumber, $mode) { let $pageXslDoc := doc($xslFileName) let $htmlPageFragment := transform:transform($inputXml, $pageXslDoc, ()) let $topLeftStr := $title let $topRightStr := concat("Page ", $pageNumber, " (" counter(page) ")") let $bottomLeftStr := concat("View mode: ", $mode) let $currentTime := current-dateTime() let $year := year-from-dateTime($currentTime) let $month := month-from-dateTime($currentTime) let $day := day-from-dateTime($currentTime) let $hours := hours-from-dateTime($currentTime) let $minutes := minutes-from-dateTime($currentTime) let $dateStr := concat("", $day, ".", $month, ".", $year, " ", $hours, ":", $minutes) let $bottomRightStr := $dateStr let $pdfResult := mpdldoc:html2pdf($htmlPageFragment, $language, $topLeftStr, $topRightStr, $bottomLeftStr, $bottomRightStr) return $pdfResult };