in src/main/java/org/apache/sling/sitemap/impl/SitemapStorage.java [228:277]
public String writeSitemap(@NotNull Resource sitemapRoot, @NotNull String name, @NotNull InputStream data,
int index, int size, int entries) throws IOException {
if (index < 1) {
throw new IllegalArgumentException("only unsigned integer greater then zero permitted");
}
String sitemapFilePath = getSitemapFilePath(sitemapRoot, name);
String statePath = sitemapFilePath + STATE_EXTENSION;
sitemapFilePath += index > 1 ? "-" + index + XML_EXTENSION : XML_EXTENSION;
try (ResourceResolver resolver = resourceResolverFactory.getServiceResourceResolver(AUTH)) {
String sitemapFileName = ResourceUtil.getName(sitemapFilePath);
Resource folder = getOrCreateFolder(resolver, ResourceUtil.getParent(sitemapFilePath));
Resource sitemapResource = folder.getChild(sitemapFileName);
if (sitemapResource == null) {
Map<String, Object> properties = new HashMap<>(3);
properties.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
properties.put(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance());
properties.put(JcrConstants.JCR_DATA, data);
properties.put(PN_SITEMAP_NAME, name);
properties.put(PN_SITEMAP_FILE_INDEX, index);
properties.put(PN_SITEMAP_ENTRIES, entries);
properties.put(PN_SITEMAP_SIZE, size);
properties.put(PN_RESOURCE_TYPE, RT_SITEMAP_FILE);
sitemapResource = resolver.create(folder, sitemapFileName, properties);
} else {
ModifiableValueMap properties = sitemapResource.adaptTo(ModifiableValueMap.class);
if (properties == null) {
throw new IOException("Cannot overwrite existing sitemap at: " + sitemapFilePath);
}
properties.put(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance());
properties.put(JcrConstants.JCR_DATA, data);
properties.put(PN_SITEMAP_ENTRIES, entries);
properties.put(PN_SITEMAP_SIZE, size);
}
Resource stateResource = resolver.getResource(statePath);
if (stateResource != null) {
resolver.delete(stateResource);
}
resolver.commit();
eventAdmin.postEvent(newUpdateEvent(newSitemapStorageInfo(sitemapResource), sitemapRoot));
} catch (LoginException | PersistenceException ex) {
throw new IOException("Cannot create sitemap at " + sitemapFilePath, ex);
}
return sitemapFilePath;
}