[core] RuleSetWriter - write property value as attribute

This commit is contained in:
Andreas Dangel 2024-09-20 16:10:51 +02:00
parent 802decbbcf
commit df1a6797c6
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
2 changed files with 10 additions and 4 deletions

View File

@ -286,7 +286,7 @@ public class RuleSetWriter {
if (isPropertyDefinition) {
propertiesElement.appendChild(createPropertyDefinitionElementBR(descriptor, typeId));
} else {
propertiesElement.appendChild(propertyElementWithValue(propertySource, descriptor));
propertiesElement.appendChild(propertyElementWithValueAttribute(propertySource, descriptor));
}
}
@ -294,8 +294,14 @@ public class RuleSetWriter {
}
@NonNull
private <T> Element propertyElementWithValue(PropertySource propertySource, PropertyDescriptor<T> descriptor) {
return createPropertyValueElement(descriptor, propertySource.getProperty(descriptor));
private <T> Element propertyElementWithValueAttribute(PropertySource propertySource, PropertyDescriptor<T> propertyDescriptor) {
Element element = document.createElementNS(RULESET_2_0_0_NS_URI, "property");
SchemaConstants.NAME.setOn(element, propertyDescriptor.name());
PropertySerializer<T> xmlStrategy = propertyDescriptor.serializer();
T value = propertySource.getProperty(propertyDescriptor);
SchemaConstants.PROPERTY_VALUE.setOn(element, xmlStrategy.toString(value));
return element;
}
private <T> Element createPropertyValueElement(PropertyDescriptor<T> propertyDescriptor, T value) {

View File

@ -174,6 +174,6 @@ class RuleSetWriterTest extends RulesetFactoryTestBase {
assertThat(written, not(containsString("min=\"")));
assertThat(written, not(containsString("max=\"")));
assertThat(written, not(containsString("type=\"")));
assertThat(written, containsString("42"));
assertThat(written, containsString("value=\"42\""));
}
}