public void writeState()

in src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java [184:213]


    public void writeState(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull Map<String, Object> state)
            throws IOException {
        String statePath = getSitemapFilePath(sitemapRoot, name) + STATE_EXTENSION;
        try (ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(AUTH)) {
            Resource folder = getOrCreateFolder(resolver, ResourceUtil.getParent(statePath));
            String stateName = ResourceUtil.getName(statePath);
            Resource stateResource = folder.getChild(stateName);

            if (stateResource == null) {
                Map<String, Object> properties = new HashMap<>(state.size() + 1);
                properties.putAll(state);
                properties.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
                properties.put(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance());
                properties.put(PN_RESOURCE_TYPE, RT_SITEMAP_PART);
                resolver.create(folder, stateName, properties);
            } else {
                ModifiableValueMap properties = stateResource.adaptTo(ModifiableValueMap.class);
                if (properties == null) {
                    throw new IOException("Cannot modify properties of existing state: " + statePath);
                }
                properties.putAll(state);
                properties.put(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance());
            }

            checkpointWrites.increment();
            resolver.commit();
        } catch (LoginException | PersistenceException ex) {
            throw new IOException("Cannot create state at " + statePath, ex);
        }
    }