This issue has been created
There is 1 update.
 
 
XWiki Platform / cid:jira-generated-image-avatar-120247d2-8ad6-4000-a139-357239b79010 XWIKI-24872 Open

Allow a short HTML displayer template name for parameterized types

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-ede14862-542a-4b40-8240-c8671306e678 Charpentier Lucas created this issue on 14/Sep/26 11:59
 
Summary: Allow a short HTML displayer template name for parameterized types
Issue Type: cid:jira-generated-image-avatar-120247d2-8ad6-4000-a139-357239b79010 Improvement
Affects Versions: 18.7.0
Assignee: Unassigned
Components: Display
Created: 14/Sep/26 11:59
Priority: cid:jira-generated-image-static-major-f3384c76-4bc9-4597-85a7-00eadcdec54b Major
Reporter: Charpentier Lucas
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:

  1. java.util.list(org.xwiki.model.reference.spacereference)
  2. 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.
 
 

1 update

 
cid:jira-generated-image-avatar-ede14862-542a-4b40-8240-c8671306e678 Changes by Charpentier Lucas on 14/Sep/26 12:00
 
Assignee: Charpentier Lucas