Name name = path.getSegment(2).getName();
// Find the parent ...
String generatedOutPath = "/" + topName.getLocalName() + "/generated-out";
String generatedOutId = getDocumentId(generatedOutPath);
Document generatedOutDoc = getDocumentById(generatedOutId);
DocumentWriter generatedOutWriter = writeDocument(generatedOutDoc);
// Create a document at '{topName}/generated-out/{name}'
String newId = newId();
String newPath = generatedOutPath + "/" + stringFrom(name);
DocumentWriter writer = newDocument(newId);
writer.setPrimaryType("nt:unstructured");
writer.setParent(generatedOutId);
writer.addProperty("prop1", "value1");
writer.addProperty("prop2", "value2");
newDocs.add(new DocInfo(writer.document(), newId, newPath));
DocumentReader reader = readDocument(writer.document());
changes.nodeCreated(newId, documentId, newPath, JcrNtLexicon.UNSTRUCTURED, Collections.<Name>emptySet(),
reader.getProperties(), isQueryable());
// And some children ...
for (int i = 0; i != 3; ++i) {
String childName = "child" + i;
String childId = newId();
String childPath = newPath + "/" + childName;
DocumentWriter childWriter = newDocument(childId);
childWriter.setPrimaryType("nt:unstructured");
childWriter.setParent(newId);
childWriter.addProperty("prop1", "value1");
childWriter.addProperty("prop2", "value2");
childWriter.setParent(newId);
writer.addChild(childId, childName);
newDocs.add(new DocInfo(childWriter.document(), childId, childPath));
DocumentReader childReader = readDocument(writer.document());
changes.nodeCreated(childId, newId, childPath, JcrNtLexicon.UNSTRUCTURED, Collections.<Name>emptySet(),
childReader.getProperties(), isQueryable());
}
for (DocInfo info : newDocs) {
documentsById.put(info.id, info.doc);
documentsByLocation.put(info.location, info.doc);
}
// Update the parent with a child reference to our new document ...
generatedOutWriter.addChild(newId, name);
Document doc = generatedOutWriter.document();
documentsById.put(generatedOutId, doc);
documentsByLocation.put(generatedOutPath, doc);
// Now generate events ...
changes.publish(null);