# Wiki source code of VelocityMacros

Last modified by Richard Johnson on 2019/03/30 13:46
Export
Office Formats
Export as PDF
Other Formats
Export as HTML

Show last authors

author | version | line-number | content
--- | --- | --- | ---
|  | 1 | {{velocity output="false"}}
|  | 2 | #macro (getAppReference)
|  | 3 | #set ($appLocalRef = $doc.getValue('dataSpaceName'))
|  | 4 | #if ("$!appLocalRef" != '')
|  | 5 | ## Between 6.3M2 (XWIKI-11249) and 7.3RC1 (XWIKI-12741).
|  | 6 | #set ($appReference = $services.model.resolveSpace($appLocalRef))
|  | 7 | #else
|  | 8 | ## Possible locations:
|  | 9 | ## 1. same space (<6.2M1, XWIKI-8757)
|  | 10 | ## 2. sibling space (between 6.2M1 and 6.3M2)
|  | 11 | ## 3. grand parent space (7.3RC1+)
|  | 12 | #set ($appReferences = [
|  | 13 | $doc.documentReference.parent,
|  | 14 | $services.model.createSpaceReference($stringtool.removeEnd($doc.documentReference.name, 'TemplateProvider'),
|  | 15 | $doc.documentReference.parent.parent),
|  | 16 | $doc.documentReference.parent.parent
|  | 17 | ])
|  | 18 | #foreach ($item in $appReferences)
|  | 19 | #set ($appReference = $item)
|  | 20 | #if ($xwiki.getDocument($appReference).getObject($appDescriptorClassName))
|  | 21 | #break
|  | 22 | #end
|  | 23 | #end
|  | 24 | #end
|  | 25 | #end
|  | 26 |
|  | 27 | #macro (getAppTitle)
|  | 28 | #getAppReference
|  | 29 | #set ($appTitle = $xwiki.getDocument($appReference).plainTitle)
|  | 30 | #end
|  | 31 |
|  | 32 | #macro (getExpectedAppClassReference $appName $appReference)
|  | 33 | #set ($expectedClassName = "$!{appName}Class")
|  | 34 | #set ($expectedClassLocations = [
|  | 35 | $services.model.createSpaceReference('Code', $appReference),
|  | 36 | $services.model.createSpaceReference("${appReference.name}Code", $appReference.parent),
|  | 37 | $appReference
|  | 38 | ])
|  | 39 | #set ($found = false)
|  | 40 | #foreach ($expectedClassLocation in $expectedClassLocations)
|  | 41 | #set ($expectedClassReference = $services.model.createDocumentReference($expectedClassName,
|  | 42 | $expectedClassLocation))
|  | 43 | #if ($xwiki.exists($expectedClassReference))
|  | 44 | #set ($found = true)
|  | 45 | #break
|  | 46 | #end
|  | 47 | #end
|  | 48 | #if (!$found)
|  | 49 | #set ($expectedClassReference = $NULL)
|  | 50 | #end
|  | 51 | #end
|  | 52 |
|  | 53 | #macro (getAppClassReference $appHomePage)
|  | 54 | #set ($appName = $appHomePage.pageReference.name)
|  | 55 | #set ($appReference = $appHomePage.documentReference.parent)
|  | 56 | ## Look for the application class in the expected location.
|  | 57 | #getExpectedAppClassReference($appName $appReference)
|  | 58 | #if ($expectedClassReference)
|  | 59 | #set ($classReference = $expectedClassReference)
|  | 60 | #else
|  | 61 | ## The application was probably moved or renamed.
|  | 62 | ## The configured class reference is relative to the application home page (holding the application descriptor).
|  | 63 | #set ($configuredClassReference = $services.model.resolveDocument("$!appHomePage.getValue('class')",
|  | 64 | $appHomePage.documentReference))
|  | 65 | #set ($previousAppName = $stringtool.removeEnd($configuredClassReference.name, 'Class'))
|  | 66 | ## Look for a class with the previous name in the current location.
|  | 67 | #getExpectedAppClassReference($previousAppName $appReference)
|  | 68 | #if ($expectedClassReference)
|  | 69 | #set ($classReference = $expectedClassReference)
|  | 70 | #else
|  | 71 | ## Use the configured class.
|  | 72 | #set ($classReference = $configuredClassReference)
|  | 73 | #end
|  | 74 | #end
|  | 75 | #end
|  | 76 | {{/velocity}}

# Applications

# Tips

You can click on the arrows next to the breadcrumb elements to quickly navigate to sibling and children pages.

# Need help?

If you need help with XWiki you can contact:

- Community Support
- Professional Support

XWiki Debian 13.10.2