public ResourceCollection createCollection()

in src/main/java/org/apache/sling/resource/collection/impl/ResourceCollectionManagerImpl.java [78:114]


    public ResourceCollection createCollection(Resource parentResource, String name, Map<String, Object> properties)
            throws PersistenceException {

        if (parentResource != null) {
            String fullPath = parentResource.getPath() + "/" + name;

            if (parentResource.getResourceResolver().getResource(fullPath) != null) {
                throw new IllegalArgumentException("invalid path, " + fullPath + "resource already exists");
            }

            if (properties == null) {
                properties = new HashMap<>();
            }

            if (properties.get(SlingConstants.NAMESPACE_PREFIX + ":" + SlingConstants.PROPERTY_RESOURCE_TYPE) != null
                    && !ResourceCollection.RESOURCE_TYPE.equals(properties.get(
                            SlingConstants.NAMESPACE_PREFIX + ":" + SlingConstants.PROPERTY_RESOURCE_TYPE))) {
                properties.put(
                        SlingConstants.NAMESPACE_PREFIX + ":" + SlingConstants.PROPERTY_RESOURCE_SUPER_TYPE,
                        ResourceCollection.RESOURCE_TYPE);
            } else {
                properties.put(
                        SlingConstants.NAMESPACE_PREFIX + ":" + SlingConstants.PROPERTY_RESOURCE_TYPE,
                        ResourceCollection.RESOURCE_TYPE);
            }
            Resource collectionRes = parentResource.getResourceResolver().create(parentResource, name, properties);
            parentResource
                    .getResourceResolver()
                    .create(collectionRes, ResourceCollectionConstants.MEMBERS_NODE_NAME, null);
            log.debug("collection  {} created", fullPath);

            return new ResourceCollectionImpl(collectionRes);
        } else {
            log.error("parent resource can not be null");
            throw new IllegalArgumentException("parent resource can not be null ");
        }
    }