Fixed rendering when a relative path specified
package com.exadel.aem.toolkit.plugin.handlers.widget.common;
import java.util.Arrays;
-import java.util.List;
import java.util.function.BiConsumer;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import com.exadel.aem.toolkit.api.annotations.widgets.property.Property;
import com.exadel.aem.toolkit.api.handlers.Source;
import com.exadel.aem.toolkit.api.handlers.Target;
+import com.exadel.aem.toolkit.plugin.util.DialogConstants;
import com.exadel.aem.toolkit.plugin.util.PluginNamingUtility;
public class PropertyAnnotationHandler implements BiConsumer<Source, Target> {
@@ -22,8 +20,16 @@ public class PropertyAnnotationHandler implements BiConsumer<Source, Target> {
}
private void acceptProperty(Property property, Target target) {
- List<String> list = Pattern.compile("/").splitAsStream(property.name()).collect(Collectors.toList());
- String propertyName = list.remove(list.size() - 1);
- target.getOrCreateChild(String.join(StringUtils.EMPTY, list)).attribute(PluginNamingUtility.getValidFieldName(propertyName), property.value());
+ String propertyName;
+ String propertyPath;
+ if (property.name().contains(DialogConstants.PATH_SEPARATOR)) {
+ propertyName = StringUtils.substringAfterLast(property.name(), DialogConstants.PATH_SEPARATOR);
+ propertyPath = StringUtils.substringBeforeLast(property.name(), DialogConstants.PATH_SEPARATOR);
+ } else {
+ propertyName = property.name();
+ propertyPath = null;
+ }
+ Target effectiveTarget = StringUtils.isNotBlank(propertyPath) ? target.getOrCreateTarget(propertyPath) : target;
+ effectiveTarget.attribute(PluginNamingUtility.getValidFieldName(propertyName), property.value());
}
}
