Commit 76103e2b authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

Merge branch 'develop' of gitlab.gwdg.de:fontane-notizbuecher/SADE into develop

parents bd278a2e 012029e8
......@@ -13,6 +13,7 @@ xquery version "3.1";
module namespace etTransfo="http://fontane-nb.dariah.eu/etTransfo";
declare namespace err="http://www.w3.org/2005/xqt-errors";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace xi="http://www.w3.org/2001/XInclude";
......@@ -60,6 +61,36 @@ declare function etTransfo:complete() {
etTransfo:report-errors()
};
(:~
: A function to trigger the creation of the edited text for a single notebook.
: Mainly used for parallel creation of the notebooks.
:
: @param $uri The notebook's URI, e.g. "16b00" :)
declare function etTransfo:transform-single-nb($uri as xs:string) as xs:string* {
let $assure-dir-available := etTransfo:assure-dir-available("print")
let $assure-dir-available := etTransfo:assure-dir-available("log")
let $log := util:log-system-out("Start creating edited text for " || $uri)
let $log := etTransfo:create-log($uri)
let $tei := doc($config:data-root || "/data/" || $uri || ".xml")//tei:TEI
let $updated-notebook :=
element tei:TEI {
attribute id {$uri},
$tei/@*,
$tei/*
}
return
(try {
etTransfo:transform-tei($updated-notebook, $log)
} catch * {
etTransfo:add-log-entry($log, "ETTRANSFO08: Couldn't transform TEI. ")
},
etTransfo:tidy-logs(),
etTransfo:report-errors())
};
(:~
: Resolves all XIncludes in a given case file and copies all notebooks belonging to a case into one file.
......@@ -80,13 +111,7 @@ declare function etTransfo:create-case($showcase as xs:string) as xs:string {
let $log := util:log-system-out("Start creating case " || $showcase || " (" || $doc//tei:title[1] || ").")
let $new-filename := $doc//tei:title[1] => replace(" ", "-") || ".xml"
let $assure-dir-available :=
if(xmldb:collection-available($config:data-root || "/print/")) then
()
else
(xmldb:create-collection($config:data-root, "/print"),
xmldb:create-collection($config:data-root || "/print/", "xml"),
xmldb:create-collection($config:data-root || "/print/", "xhtml"))
let $assure-dir-available := etTransfo:assure-dir-available("print")
let $create-new-file := xmldb:store($config:data-root || "/print/xml/", $new-filename, $doc/*)
......@@ -175,28 +200,32 @@ declare function etTransfo:transform-tei($tei as element(tei:TEI), $log as xs:st
try {
prepCom:main($sorted, $tei/@id)
} catch * {
etTransfo:add-log-entry($log, "ETTRANSFO10: Error while preparing commentary for this notebook. ")
etTransfo:add-log-entry($log, "ETTRANSFO10: Error while preparing commentary for this notebook. Reason: 
" ||
concat("[", $err:line-number, ": ", $err:column-number, "] Error ", $err:code, ": ", $err:description))
}
let $transform-to-interform :=
try {
fontaneSimple:main($prepare-comment, $tei/@id, $log)
} catch * {
etTransfo:add-log-entry($log, "ETTRANSFO11: Error while transforming this notebook to an intermediate format. ")
etTransfo:add-log-entry($log, "ETTRANSFO11: Error while transforming this notebook to an intermediate format. Reason: 
" ||
concat("[", $err:line-number, ": ", $err:column-number, "] Error ", $err:code, ": ", $err:description))
}
let $tidy-interform :=
try {
tidySimple:main($transform-to-interform, $tei/@id)
} catch * {
etTransfo:add-log-entry($log, "ETTRANSFO12: Error while tidying up the intermediate format for this notebook. ")
etTransfo:add-log-entry($log, "ETTRANSFO12: Error while tidying up the intermediate format for this notebook. Reason: 
" ||
concat("[", $err:line-number, ": ", $err:column-number, "] Error ", $err:code, ": ", $err:description))
}
return
try {
simple2xhtml:main($tidy-interform, $tei/@id)
} catch * {
etTransfo:add-log-entry($log, "ETTRANSFO13: Error while creating XHTML for this notebook. ")
etTransfo:add-log-entry($log, "ETTRANSFO13: Error while creating XHTML for this notebook. Reason: 
" ||
concat("[", $err:line-number, ": ", $err:column-number, "] Error ", $err:code, ": ", $err:description))
}
};
......@@ -359,14 +388,25 @@ declare function etTransfo:create-log($uri as xs:string) as xs:string {
declare function etTransfo:assure-dir-available($dir-name as xs:string) {
if(xmldb:collection-available($etTransfo:dir || "logs")) then
$etTransfo:dir || "logs"
else
xmldb:create-collection($etTransfo:dir, "logs")
switch ($dir-name)
case "log" return
if(xmldb:collection-available($etTransfo:dir || "logs")) then
$etTransfo:dir || "logs"
else
xmldb:create-collection($etTransfo:dir, "logs")
};
case "print" return
if(xmldb:collection-available($config:data-root || "/print/")) then
()
else
(xmldb:create-collection($config:data-root, "/print"),
xmldb:create-collection($config:data-root || "/print/", "xml"),
xmldb:create-collection($config:data-root || "/print/", "xhtml"))
default return ()
};
declare function etTransfo:add-log-entry($log-file as xs:string,
$message as xs:string) as empty-sequence() {
let $entry := <LogEntry timestamp="{util:system-time()}">{$message}</LogEntry>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment