s.refresh(false);
Node root = s.getRootNode();
Node testRootNode;
if (root.hasNode(testPath)) {
RetentionManager rm;
try {
rm = s.getRetentionManager();
} catch (UnsupportedRepositoryOperationException e) {
rm = null;
}
// clean test root
testRootNode = root.getNode(testPath);
NodeIterator children = testRootNode.getNodes();
while (children.hasNext()) {
Node child = children.nextNode();
// Remove retention policy if needed
String childPath = child.getPath();
if (rm != null && rm.getRetentionPolicy(childPath) != null) {
rm.removeRetentionPolicy(childPath);
s.save();
}
NodeDefinition nodeDef = child.getDefinition();
if (!nodeDef.isMandatory() && !nodeDef.isProtected()) {