in mail-archive/server/src/main/java/org/apache/sling/mailarchiveserver/impl/MessageStoreImpl.java [323:372]
private Resource assertEachNode(ResourceResolver resolver, String archive, String domain, String list,
String threadPath, String threadName) throws PersistenceException, LoginException {
final String pathToMessage = archive+domain+"/"+list+"/"+threadPath;
String path = pathToMessage;
Resource resource = resolver.getResource(path);
int cnt = 0;
while (resource == null) {
cnt++;
path = path.substring(0, path.lastIndexOf("/"));
resource = resolver.getResource(path);
}
if (cnt > 0) {
int threadNodesNumber = threadPath.split("/").length;
// bind paths
List<String> nodePaths = new ArrayList<String>();
nodePaths.add(domain);
nodePaths.add(list);
for (String node : threadPath.split("/")) {
nodePaths.add(node);
}
// bind props
List<Map<String, Object>> nodeProps = new ArrayList<Map<String, Object>>();
nodeProps.add(setProperties(MailArchiveServerConstants.DOMAIN_RT, domain));
nodeProps.add(setProperties(MailArchiveServerConstants.LIST_RT, list));
for (int i = 0; i < threadNodesNumber-1; i++) {
nodeProps.add(null);
}
nodeProps.add(setProperties(MailArchiveServerConstants.THREAD_RT, threadName));
// checking
for (int i = nodePaths.size()-cnt; i < nodePaths.size(); i++) {
String name = nodePaths.get(i);
assertResource(resolver, resource, name, nodeProps.get(i));
resource = resolver.getResource(resource.getPath()+"/"+name);
}
}
resource = resolver.getResource(pathToMessage);
if (resource == null) {
throw new RuntimeException("Parent resource cannot be null.");
} else {
return resource;
}
}