Hello everyone!
I want to browse an XWiki page line by line with Velocity Scripting API. Does anyone know how to do it ?
I’m using an api “Documentation”, this api provide a TOC listing all the doc of a project.
The main goal of this code is to display all of the pages located in Documentation api in one page named “Export PDF”. In this way, I will be able to display all the doc of the project in one PDF document with the correct numbering.
When i use the function #displaySections($sectionChildRef $sectionNum)
, it displays the titles of pages in Documentation but when I add the $sectionChildRef.getContent()
function it try to display all the content of the pages. The fact is that in “Export PDF” page, title displayed by #displaySections($sectionChildRef $sectionNum)
merge with Headers of the other pages displayed by $sectionChildRef.getContent()
. Which makes my numbering wrong.
#set($sectionTemplate = 'Documentation.Code.SectionTemplate')
#set($parentPropName = 'parentSection')
#set($numberingPropName = 'numbering')
##
## Building the hierarchy view (TOC) of sections
#macro(displaySections $parentReference $sectionNum $heading)
#set($sectionChildren = $services.query.hql("select distinct obj.name from BaseObject obj, LongProperty numbering, StringProperty parent where obj.className = :sectionClass and obj.name <> :sectionTemplate and obj.id = numbering.id.id and obj.id = parent.id.id and parent.id.name = :parentPropName and numbering.id.name = :numberingPropName and parent.value = :parentReference order by numbering.value asc").bindValue('parentReference', $services.model.serialize($parentReference, 'local')).bindValue('sectionClass', $sectionClass).bindValue('sectionTemplate', $sectionTemplate).bindValue('parentPropName', $parentPropName).bindValue('numberingPropName', $numberingPropName).execute())
#foreach($sectionChild in $sectionChildren)
#set($sectionChildRef = $services.model.resolveDocument($sectionChild))
#set($sectionChildDocument = $xwiki.getDocument($sectionChildRef))
#if ($services.security.authorization.hasAccess('view', $sectionChildRef))
## Pages marked as "not included in export" are excluded when exporting indeed, but included in standard view mode.
#if(!$services.multilingualHtmlExport.isExporting() || $services.documentation.isIncludedInExports($sectionChildRef, false))
#set($equals = "")
#set($equalonly = "=" )
#set($start = 0)
#set($range = [$start..$sectionNum])
#foreach($i in $range)
#set($equals = "$equals$equalonly" )
#end
$equals$sectionChildDocument.displayTitle$equals
$sectionChildDocument.getContent()
#set($sectionNum = $sectionNum + 1)
#displaySections($sectionChildRef $sectionNum)
#end
#end
#end
#set($sectionNum = $sectionNum - 1)
#end
{{/velocity}}
{{velocity}}
#set($root = $xcontext.macro.params.root)
#if("$!root" == '')
#set($root = 'Documentation.WebHome')
#end
#displaySections($services.model.resolveDocument($root) 0)
{{/velocity}}
I want to browse all of pages to locate headers lines and indent them, in this way, the numbering will still correct.