Details
-
Improvement
-
Resolution: Unresolved
-
Major
-
None
-
18.7.0
-
None
-
Unknown
-
Description
DefaultTemplateHTMLDisplayer#getTemplateName looks for a template named after the displayed type, in this order:
- html_displayer/[type]/[mode].vm
- html_displayer/[type].vm
- html_displayer/[mode].vm
- html_displayer/default.vm
How [type] is computed depends on the kind of type:
- a plain Class is named by its simple name, lowercased, so org.xwiki.model.reference.SpaceReference resolves to html_displayer/spacereference.vm.
- any other Type, and in particular a ParameterizedType, is named by its fully qualified serialization, so java.util.List<org.xwiki.model.reference.SpaceReference> only ever resolves to html_displayer/java.util.list(org.xwiki.model.reference.spacereference).vm.
That asymmetry makes the templates of parameterized types much more verbose than the ones of plain classes, for no functional reason. A template author writing the displayer of a List<SpaceReference> has to spell out both fully qualified names, while the displayer of a bare SpaceReference is just spacereference.vm.
Proposal
Add a short name for parameterized types, built from the simple names of the raw type and of its type arguments, and look it up after the fully qualified one. For java.util.List<org.xwiki.model.reference.SpaceReference> the candidate type names become, in order:
- java.util.list(org.xwiki.model.reference.spacereference)
- list(spacereference)
The fully qualified name keeps the highest priority on purpose: simple names can collide, for instance List<org.xwiki.rendering.block.Block> and List<org.xwiki.contrib.myextension.Block> both shorten to list(block). Keeping the fully qualified name first means a template can always target one precise type, and the short name is only a convenience fallback for the common case.
Note that this collision risk is not new, it already exists for plain classes since XWiki 10.11RC1 (8fe09eda9de), where every Class is named by its simple name only. This issue does not change that, it only makes parameterized types behave consistently with it while keeping an unambiguous form available.
The resulting priority must be documented, both in the getTemplateName javadoc and in the documentation of the HTML displayer.
Notes
- The character replacements applied to the path stay unchanged: < and > become parentheses, ? becomes _ and spaces are removed.
- The change is needed by XWIKI-24636, which adds a List<SpaceReference> displayer template, but it stands on its own.