Hi all,
I never gave it too much thought, but I recently encountered an issue
that seems to be a limit case, but nevertheless worth reporting.
If I export a multi valued property in System View, I will obtain an
sv:property element, and as children, a sequence of sv:value elements:
...
<sv:property sv:name="my:list" sv:type="String">
<sv:value>one</sv:value>
<sv:value>two</sv:value>
</sv:property>
...
Now, if my:list happens to have only one element, my export will look
like the following:
<sv:property sv:name="my:list" sv:type="String">
<sv:value>one</sv:value>
</sv:property>
which happens to be exactly the same XML mapping of a "regular",
single valued property (and that's the issue)
The specs (I have jcr 283 handy, so I am quoting form there ) say at
4.4.1:
"A multi-value property is converted to an <sv:property> element
containing multiple <sv:value> elements. The order of the <sv:value>
elements reflects the order of the value array returned by
Property.getValues" (4.4.1)
So this as by specs. But, when I import it (and the assumption is that
I want to roundtrip my data, which should be supported in the System
View), the logic is implemented (I believe in in
o.a.j.core.xml.PropInfo) as follow: if there's a node type definition
that tells me that this node is multi valued or if I don't have
exaclty one value, set it as such, otherwise set it as single valued.
This works fine if there's a node type definition that constrains this
property, but if there's none (unstructured nodes all around) then my
roundtrip will create a node that is not exaclty like the original
one, and if the application is using getValues() it will probably
throw an exception:
"Accessing a multi-valued property with Property.getValue, or a
single-value property with Property.getValues will throw a
ValueFormatException" (3.7.1)
Which in turns forces the application code to recover in the catch
using getValue(). I think is dangerous and quite inefficient to do so,
especially in situations where multi valued properties have often a
single value (say for instance my:authors).
Maybe I am missing something, but if that's the case that I am not,
maybe it would be worth adding some implementation specific
workaround, such as adding an optional sv:multivalued="true" attribute
that then can be used transparently during import. It should not break
anything I believe (unless there's some strict validation of the SV
schema in place). Or was this intentional?
Thoughts?
Alessandro