public FormActionResult handleForm()

in reference/src/main/java/org/apache/sling/cms/reference/forms/impl/actions/UserGeneratedContentAction.java [64:124]


    public FormActionResult handleForm(Resource actionResource, FormRequest request) throws FormException {
        log.trace("handleForm");
        ValueMap properties = actionResource.getValueMap();

        try {

            StringSubstitutor sub = new StringSubstitutor(request.getFormData());

            UGCBucketConfig bucketConfig = new UGCBucketConfig();
            bucketConfig.setAction(
                    APPROVE_ACTION.valueOf(properties.get("approveAction", APPROVE_ACTION.PUBLISH.toString())));
            bucketConfig.setBucket(sub.replace(properties.get("bucket", String.class)));
            bucketConfig
                    .setContentType(CONTENT_TYPE.valueOf(properties.get("contentType", CONTENT_TYPE.OTHER.toString())));
            bucketConfig.setPathDepth(properties.get("pathDepth", 0));
            log.debug("Creating UGC at with configuration:  {}", bucketConfig);

            Map<String, Object> contentProperties = new HashMap<>();
            contentProperties.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
            Arrays.stream(properties.get("additionalProperties", new String[0])).map(v -> {
                if (v.contains("=")) {
                    String[] vs = v.split("\\=");
                    return new ImmutablePair<String, String>(vs[0], vs[1]);
                } else {
                    log.warn("Invalid value: {}", v);
                    return null;
                }
            }).filter(Objects::nonNull).forEach(v -> {
                log.debug("Adding additional property: {}", v);
                contentProperties.put(v.getLeft(), v.getRight());
            });
            contentProperties.putAll(request.getFormData());
            log.debug("Persisting properties: {}", contentProperties);

            Resource container = ugcService.createUGCContainer(request.getOriginalRequest(), bucketConfig,
                    sub.replace(properties.get("preview", "")), properties.get("targetPath", ""));
            log.debug("Using container: {}", container);
            ResourceResolver resolver = container.getResourceResolver();

            String name = filter.filter(sub.replace(properties.get("name", "")));
            log.debug("Using name {}", name);

            if (properties.get("wrapPage", false)) {
                log.debug("Wrapping with page");
                Resource page = container.getResourceResolver().create(container, name,
                        Collections.singletonMap(JcrConstants.JCR_PRIMARYTYPE, CMSConstants.NT_PAGE));
                resolver.create(page, JcrConstants.JCR_CONTENT, contentProperties);
            } else {
                log.debug("Creating as direct child");
                resolver.create(container, name, contentProperties);
            }

            resolver.commit();
            log.debug("Successfully persisted UGC");

            request.getFormData().put("ugcPath", container.getPath());
            return FormActionResult.success("Created UGC Item");
        } catch (PersistenceException e) {
            throw new FormException("Failed to create UGC Content", e);
        }
    }