Commit 44a6a56c authored by jbierma's avatar jbierma

Merge branch 'feature/#122-Confluence' into 'develop'

bugfix for confluence module (closes #122)

Closes #122

See merge request !88
parents 60ba1062 9f26d779
......@@ -19,50 +19,49 @@ declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare variable $confluence:collection := $config:app-root || '/docs';
declare variable $confluence:httprequestget := "<http:request method='get' />";
declare function confluence:confluence($node as node(), $model as map(*), $id as xs:string) as node()*
{
let $lastRevinDb := confluence:getLastRevInDb($id)
let $revisionInWiki := confluence:getLastRevInWiki($id)
let $revisionInWiki := if ($revisionInWiki=-1) then ($lastRevinDb) else ()
declare function confluence:confluence($node as node(), $model as map(*), $id as xs:string) as node()* {
(: Only for debugging, needs to be commented out for productive state :)
(: let $lastRevinDb := 0:)
let $httprequestget := "<http:request method='get'><http:header name='connection' value='close' /></http:request>"
let $lastRevinDb := confluence:getLastRevInDb($id)
let $revisionInWiki := confluence:getLastRevInWiki($id)
let $revisionInWiki := if ($revisionInWiki=-1) then ($lastRevinDb) else ($revisionInWiki)
let $config-lang := string(config:get("lang.default", "multilanguage"))
let $lang := if($config-lang = "") then "" else app:getLanguage()
let $config-lang := string(config:get("lang.default", "multilanguage")),
$lang := if($config-lang = "") then "" else app:getLanguage()
return
if( $revisionInWiki = $lastRevinDb )
then doc($confluence:collection || "/" || $id || '_' || $lang || '.rev' || $lastRevinDb || '.xml' )
else (
let $login := xmldb:login("/db", "admin", "" )
let $remove :=
xmldb:get-child-resources( $confluence:collection )[starts-with(., $id)]
! xmldb:remove($confluence:collection , . )
let $url:= config:get("confluence.url", "wiki") || $id || '?expand=body.storage'
let $export := http:send-request($httprequestget, $url)
let $map := xs:base64Binary($export[2]/text())
=> string()
=> util:base64-decode()
=> parse-json()
let $result := map:get(map:get(map:get($map, "body")[1], "storage"), "value")
let $result := local:replaceParsingErrors($result)
let $result := '<ac:confluence xmlns:ac="http://www.atlassian.com/schema/confluence/4/ac/" xmlns:ri="http://www.atlassian.com/schema/confluence/4/ri/" xmlns="http://www.atlassian.com/schema/confluence/4/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.atlassian.com/schema/confluence/4/ac/ ">' || $result || "</ac:confluence>"
let $result as element() := parse-xml( $result )/*
let $result := local:remove-element-ns-deep( $result )
let $result := <div id="wiki">{ local:confluenceparser($result, $id) }</div>
return
if( $revisionInWiki = $lastRevinDb )
then (
doc($confluence:collection || "/" || $id || '_' || $lang || '.rev' || $lastRevinDb || '.xml' )
)
else (
let $login := xmldb:login("/db", "admin", "" )
let $remove :=
xmldb:get-child-resources( $confluence:collection )[starts-with(., $id)]
! xmldb:remove($confluence:collection , . )
let $url:= config:get("confluence.url", "wiki") || $id || '?expand=body.storage'
let $httprequestget := <http:request href="{ $url }" method="get" />
let $export := http:send-request($httprequestget)
let $map := parse-json(util:base64-decode($export[2]))
let $result := map:get(map:get(map:get($map, "body"), "storage"), "value")
let $result := local:replaceParsingErrors($result)
let $result := '<ac:confluence xmlns:ac="http://www.atlassian.com/schema/confluence/4/ac/" xmlns:ri="http://www.atlassian.com/schema/confluence/4/ri/" xmlns="http://www.atlassian.com/schema/confluence/4/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.atlassian.com/schema/confluence/4/ac/ ">' || $result || "</ac:confluence>"
let $result as element() := parse-xml( $result )/*
let $result := local:remove-element-ns-deep( $result )
let $result := <div id="wiki">{local:confluenceparser($result, $id)}</div>
let $allLanguages := app:getAllLanguages()
let $forLoop := map:merge(
for $el in $allLanguages
let $resultLangSpecific := local:confluenceparseLanguage($result, $el)
let $store := xmldb:store( $confluence:collection, $id || '_' || $el || '.rev' || $revisionInWiki || '.xml' , $resultLangSpecific )
return map:entry($el, $store)
)
let $allLanguages := app:getAllLanguages()
let $forLoop := map:merge(
for $el in $allLanguages
let $resultLangSpecific := local:confluenceparseLanguage($result, $el)
let $store := xmldb:store( $confluence:collection, $id || '_' || $el || '.rev' || $revisionInWiki || '.xml' , $resultLangSpecific )
return map:entry($el, $store)
)
let $result := doc( $forLoop( $lang ) )
return ($result)
)
let $result := doc( $forLoop( $lang ) )
return ($result)
)
};
(:~
......@@ -175,7 +174,7 @@ declare function local:confluenceparser($nodes as node()*, $id)
attribute class {"title"}
}
})
default
return
element xhtml:span {
......@@ -232,7 +231,7 @@ declare function local:retrieveImageUrl($pageId, $imageName) {
};
:)
declare function confluence:getLastRevInDb($id) as xs:integer
declare function confluence:getLastRevInDb($id) as xs:integer
{
let $num := xmldb:get-child-resources( $confluence:collection )[contains(., $id)][1]
=> substring-after('.rev')
......@@ -248,30 +247,27 @@ declare function confluence:getLastRevInDb($id) as xs:integer
: Returns the last revision number we get from Confluence
: @param $id – the ID of a Confluence page
: :)
declare function confluence:getLastRevInWiki($id as xs:string) as xs:integer
{
let $rest :=
http:send-request
(
$httprequestget,
config:get("confluence.url", "wiki")||$id||"/history?expand=lastUpdated"
)
declare function confluence:getLastRevInWiki($id as xs:string) as xs:integer {
let $url := config:get("confluence.url", "wiki")||$id||"/history?expand=lastUpdated"
let $httprequestget := <http:request href="{ $url }" method="get" />
let $rest := http:send-request($httprequestget)
let $statuscode := $rest[1]/@status
let $map := if ($statuscode = 200) then (
parse-json(util:base64-decode($rest[2]))
)
else ()
let $statuscode := $rest/@statusCode
let $revision := if ($statuscode = 200) then (
string(map:get (map:get($map, "lastUpdated"), "number"))
)
else (-1)
let $map := if ($statuscode = 200) then (parse-json(
util:base64-decode(string(xs:base64Binary($rest[2]/text())))
))
else ()
let $revision := if ($statuscode = 200) then (string(map:get (map:get($map, "lastUpdated"), "number")))
else (-1)
return
$revision
};
return
$revision
};
declare function local:HTML2html($node)
declare function local:HTML2html($node)
{
for $node in $node
......
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