in src/main/java/org/apache/sling/contentparser/xml/internal/XMLContentParser.java [82:159]
private void parse(ContentHandler handler, Element element, ParserOptions parserOptions, String parentPath) throws IOException {
// build node path
String path;
if (parentPath == null) {
path = "/";
} else {
String name = getChildText(element, "name");
if (StringUtils.isEmpty(name)) {
throw new IOException("Child node without name detected below path " + parentPath);
}
if (parserOptions.getIgnoreResourceNames().contains(name)) {
return;
}
path = parentPath.endsWith("/") ? parentPath + name : parentPath + "/" + name;
}
Map<String, Object> properties = new HashMap<>();
// primary node type and mixins
String primaryType = getChildText(element, "primaryNodeType");
if (StringUtils.isNotBlank(primaryType) && !parserOptions.getIgnorePropertyNames().contains(JCR_PRIMARY_TYPE)) {
properties.put(JCR_PRIMARY_TYPE, primaryType);
}
String[] mixins = getChildTextArray(element, "mixinNodeType");
if (mixins.length > 0 && !parserOptions.getIgnorePropertyNames().contains("jcr:mixinTypes")) {
properties.put("jcr:mixinTypes", mixins);
}
// properties
List<Element> propertyElements = getChildren(element, "property");
for (Element propertyElement : propertyElements) {
// property name
String name = getChildText(propertyElement, "name");
if (StringUtils.isBlank(name)) {
throw new IOException("Property without name detected at path " + path);
}
if (parserOptions.getIgnorePropertyNames().contains(name)) {
continue;
}
// property type
String type = getChildText(propertyElement, "type");
if (StringUtils.isBlank(type)) {
throw new IOException("Property '" + name + "' has no type at path " + path);
}
// property value
Object value;
List<Element> valuesElements = getChildren(propertyElement, "values");
if (!valuesElements.isEmpty()) {
Element valuesElement = valuesElements.get(0);
List<Element> valueElements = getChildren(valuesElement, "value");
String[] stringValues = new String[valueElements.size()];
for (int i = 0; i < valueElements.size(); i++) {
stringValues[i] = valueElements.get(i).getTextContent();
}
value = convertMultiValue(stringValues, type);
} else {
String stringValue = getChildText(propertyElement, "value");
value = convertValue(stringValue, type);
}
properties.put(name, value);
}
String defaultPrimaryType = parserOptions.getDefaultPrimaryType();
if (defaultPrimaryType != null && !properties.containsKey(JCR_PRIMARY_TYPE)) {
properties.put(JCR_PRIMARY_TYPE, defaultPrimaryType);
}
handler.resource(path, properties);
// child nodes
List<Element> nodeElements = getChildren(element, "node");
for (Element node : nodeElements) {
parse(handler, node, parserOptions, path);
}
}