# Adding a generic internal attribute map to XDOM blocks

**URL:** <https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788>\
**Category:** Development\
**Tags:** proposal\
**Created:** [January 26, 2023, 5:14pm UTC](https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788 "2023-01-26T17:14:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelHamann](https://forum.xwiki.org/user_avatar/forum.xwiki.org/michaelhamann/32/3813_2.png) [@MichaelHamann](https://forum.xwiki.org/u/MichaelHamann)\
**Post date:** [January 26, 2023, 5:14pm UTC](https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788/1 "2023-01-26T17:14:23Z")

</div>

For improving footnote rendering (see [the design page](https://design.xwiki.org/xwiki/bin/view/Proposal/FootnoteRendering)) I’ve discussed with @tmortagne and @mleduc that it would be very helpful to be able to store attributes of arbitrary type on XDOM `Block`s (in particular on `MacroMarkerBlock`s). This would also be helpful for the [compiled XDOM](https://design.xwiki.org/xwiki/bin/view/Proposal/CompiledXDOM).

The proposal is to duplicate on the `Block` interface what we have for parameters (`getParameters()`, `getParameter(String)`, `setParameter(String, String)`, `setParameters(Map<String, String>)`), just with a different name and `Object` as value type. These attributes should be ignored by renderers, they are just supposed to be used by transformations/macros internally. An implementation would also be provided in `AbstractBlock` such that these new attributes would be usable on all blocks.

Now the main question is the name. Some ideas:

1. `internalAttribute`
2. `annotation`
3. `property`
4. `internalProperty`

I think my favorite is 4 (`internalProperty`) but I’m open to other suggestions.

---

<div class="post-metadata">

**Author:** ![tmortagne](https://forum.xwiki.org/user_avatar/forum.xwiki.org/tmortagne/32/4930_2.png) [@tmortagne](https://forum.xwiki.org/u/tmortagne)\
**Post date:** [January 27, 2023, 8:24am UTC](https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788/2 "2023-01-27T08:24:24Z")

</div>

Here are some other ideas:

1. `transientProperty` (related to the `transient` keyword used in java for fields which should not be taken into account by serialization frameworks)
2. `blockProperty` (as in only applying to the block and not to events produced from the event, but I’m afraid it’s still too ambiguous)

I don’t really have an obvious choice yet, but I think my favorite so far is `transientProperty`.

---

<div class="post-metadata">

**Author:** ![surli](https://forum.xwiki.org/user_avatar/forum.xwiki.org/surli/32/2687_2.png) [@surli](https://forum.xwiki.org/u/surli)\
**Post date:** [January 27, 2023, 8:34am UTC](https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788/3 "2023-01-27T08:34:22Z")

</div>

> [@tmortagne](#):
>
> `transientProperty` (related to the `transient` keyword used in java for fields which should not be taken into account by serialization frameworks)

I like the idea

---

<div class="post-metadata">

**Author:** ![mflorea](https://forum.xwiki.org/user_avatar/forum.xwiki.org/mflorea/32/49_2.png) [@mflorea](https://forum.xwiki.org/u/mflorea)\
**Post date:** [January 30, 2023, 8:30pm UTC](https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788/4 "2023-01-30T20:30:23Z")

</div>

Why not simply `attribute`? `ServletRequest` for instance has both attributes (`Object`) and parameters (`String`). I’d keep it simple, without any “internal” or “transient” prefix.

---

<div class="post-metadata">

**Author:** ![MichaelHamann](https://forum.xwiki.org/user_avatar/forum.xwiki.org/michaelhamann/32/3813_2.png) [@MichaelHamann](https://forum.xwiki.org/u/MichaelHamann)\
**Post date:** [February 1, 2023, 9:22am UTC](https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788/5 "2023-02-01T09:22:03Z")

</div>

> [@mflorea](#):
>
> Why not simply `attribute`? `ServletRequest` for instance has both attributes (`Object`) and parameters (`String`). I’d keep it simple, without any “internal” or “transient” prefix.

That’s a good argument and example. +1 then for using `attribute`.

---

<div class="post-metadata">

**Author:** ![surli](https://forum.xwiki.org/user_avatar/forum.xwiki.org/surli/32/2687_2.png) [@surli](https://forum.xwiki.org/u/surli)\
**Post date:** [February 1, 2023, 9:30am UTC](https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788/6 "2023-02-01T09:30:56Z")

</div>

Is it a known usage in java libs to have this kind of scheme (`parameters` for String and `attributes` for Object)? I have never noticed such thing but maybe I just missed it.  
I’m asking because at first sight, with just the name, I think it’s not so obvious that the attributes will contain objects and won’t be rendered.

Now I agree it’s simple and it seems to fit. So I’d be +0 for it.

---

<div class="post-metadata">

**Author:** ![mleduc](https://forum.xwiki.org/user_avatar/forum.xwiki.org/mleduc/32/2328_2.png) [@mleduc](https://forum.xwiki.org/u/mleduc)\
**Post date:** [February 1, 2023, 9:31am UTC](https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788/7 "2023-02-01T09:31:51Z")

</div>

I mentioned in the call that led to this proposal from my compiler classes at university that I remembered that there was a term for this.  
I think I finally found what I was looking for in the [attribute grammar wikipedia page](https://en.wikipedia.org/wiki/Attribute_grammar), and its `attribute`.

So +1 for `attribute`.

---

<div class="post-metadata">

**Author:** ![tmortagne](https://forum.xwiki.org/user_avatar/forum.xwiki.org/tmortagne/32/4930_2.png) [@tmortagne](https://forum.xwiki.org/u/tmortagne)\
**Post date:** [February 1, 2023, 9:36am UTC](https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788/8 "2023-02-01T09:36:26Z")

</div>

> [@mflorea](#):
>
> I’d keep it simple, without any “internal” or “transient” prefix.

The point was that it’s really not obvious from the names what is the difference between “attributes” and “parameters”.

> [@mflorea](#):
>
> Why not simply `attribute`? `ServletRequest` for instance has both attributes (`Object`) and parameters (`String`).

> [@mleduc](#):
>
> I think I finally found what I was looking for in the [attribute grammar wikipedia page](https://en.wikipedia.org/wiki/Attribute_grammar), and its `attribute`.

But since there are two standard examples using this naming, I guess it’s good enough for me.

So +1 for `attribute` too.

---

<div class="post-metadata">

**Author:** ![mleduc](https://forum.xwiki.org/user_avatar/forum.xwiki.org/mleduc/32/2328_2.png) [@mleduc](https://forum.xwiki.org/u/mleduc)\
**Post date:** [February 1, 2023, 9:38am UTC](https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788/9 "2023-02-01T09:38:13Z")

</div>

Whatever the option we choose at the end, we’ll need to be very explicit on the Javadoc to make a clear distinction with `parameters`.

---

<div class="post-metadata">

**Author:** ![MichaelHamann](https://forum.xwiki.org/user_avatar/forum.xwiki.org/michaelhamann/32/3813_2.png) [@MichaelHamann](https://forum.xwiki.org/u/MichaelHamann)\
**Post date:** [February 9, 2023, 2:07pm UTC](https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788/10 "2023-02-09T14:07:18Z")

</div>

Just for the record, it is possible to set (string) parameters on `CompositeBlock` that are fully ignored by all renderers as `CompositeBlock` doesn’t generate any events (and `CompositeBlock` itself is ignored, too). Similarly, it is probably easy to add custom blocks similar to `CompositeBlock` but with custom attributes.

---

<div class="post-metadata">

**Author:** ![MichaelHamann](https://forum.xwiki.org/user_avatar/forum.xwiki.org/michaelhamann/32/3813_2.png) [@MichaelHamann](https://forum.xwiki.org/u/MichaelHamann)\
**Post date:** [February 16, 2023, 1:01pm UTC](https://forum.xwiki.org/t/adding-a-generic-internal-attribute-map-to-xdom-blocks/11788/11 "2023-02-16T13:01:18Z")

</div>

I decided not to implement this proposal as in my use case there were too many problems in particular when cloning blocks that I didn’t find them to be beneficial. Still, there might be other applications where they could be useful in which case this proposal could be revived.

The code can be found at [XRENDERING-703: Add attributes to XDOM blocks by michitux · Pull Request #245 · xwiki/xwiki-rendering · GitHub](https://github.com/xwiki/xwiki-rendering/pull/245), the Jira issue is [XRENDERING-703](https://jira.xwiki.org/browse/XRENDERING-703).
