private void parse()

in src/main/java/org/apache/sling/jcr/contentparser/impl/XmlContentParser.java [71:156]


    private void parse(ContentHandler handler, Element element, String parentPath) {
        
        // build node path
        String path;
        if (parentPath == null) {
            path = "/";
        }
        else {
            String name = getChildText(element, "name");
            if (StringUtils.isEmpty(name)) {
                throw new ParseException("Child node without name detected below path " + parentPath);
            }
            path = helper.concatenatePath(parentPath, name);
            if (helper.ignoreResource(name)) {
                return;
            }
        }

        Map<String,Object> properties = new HashMap<>();
        
        // primary node type and mixins
        String primaryType = getChildText(element, "primaryNodeType");
        if (StringUtils.isNotBlank(primaryType) && !helper.ignoreProperty("jcr:primaryType")) {
            properties.put("jcr:primaryType", primaryType);
        }
        String[] mixins = getChildTextArray(element, "mixinNodeType");
        if (mixins.length > 0 && !helper.ignoreProperty("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 ParseException("Property without name detected at path " + path);
            }
            if (helper.ignoreProperty(name)) {
                continue;
            }
            
            // property type
            String typeString = getChildText(propertyElement, "type");
            if (StringUtils.isBlank(typeString)) {
                throw new ParseException("Property '" + name + "' has no type at path " + path);
            }
            int type;
            try {
                type = PropertyType.valueFromName(typeString);
            }
            catch (IllegalArgumentException ex) {
                throw new ParseException("Property '" + name + "' has illegal type '" + typeString + "' 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);
        }
        
        // report current JSON object
        helper.ensureDefaultPrimaryType(properties);
        handler.resource(path, properties);
        
        // child nodes
        List<Element> nodeElements = getChildren(element, "node");
        for (Element node : nodeElements) {
            parse(handler, node, path);
        }
        
    }