@Override
public Content add(QName name, QName... classes) {
try {
+ Node node = openForEdit();
Node child;
if (classes.length > 0) {
classes: for (int i = 0; i < classes.length; i++) {
}
}
QName primaryType = classes[0];
- Node node = openForEdit();
child = Jcr.addNode(node, name.toString(), primaryType.toString());
for (int i = 1; i < classes.length; i++)
if (NtType.file.qName().equals(primaryType)) {
// TODO optimise when we have a proper save mechanism
child.addNode(Node.JCR_CONTENT, NodeType.NT_UNSTRUCTURED);
-// Binary binary;
-// try (InputStream in = new ByteArrayInputStream(new byte[0])) {
-// binary = content.getSession().getValueFactory().createBinary(in);
-// content.setProperty(Property.JCR_DATA, binary);
-// } catch (IOException e) {
-// throw new UncheckedIOException(e);
-// }
- child.getSession().save();
}
} else {
- child = Jcr.addNode(getJcrNode(), name.toString(), NodeType.NT_UNSTRUCTURED);
+ child = Jcr.addNode(node, name.toString(), NodeType.NT_UNSTRUCTURED);
}
+ saveEditedNode(node);
return new JcrContent(getSession(), provider, jcrWorkspace, child.getPath());
} catch (RepositoryException e) {
throw new JcrException("Cannot add child to " + jcrPath + " in " + jcrWorkspace, e);
public synchronized Node openForEdit(String workspace, String jcrPath) throws RepositoryException {
Session session = getWriteSession(workspace);
Node node = session.getNode(jcrPath);
- if (node.isNodeType(NodeType.MIX_SIMPLE_VERSIONABLE)) {
- VersionManager versionManager = session.getWorkspace().getVersionManager();
- if (versionManager.isCheckedOut(jcrPath)) {
+ VersionManager versionManager = session.getWorkspace().getVersionManager();
+
+ Node versionedAncestor = findVersionedAncestor(node);
+ boolean checkedOut = versionManager.isCheckedOut(jcrPath);
+
+ if (versionedAncestor != null) {
+ if (checkedOut) {
if (!checkedOutModified.containsKey(workspace))
checkedOutModified.put(workspace, new TreeSet<>());
- checkedOutModified.get(workspace).add(jcrPath);
+ checkedOutModified.get(workspace).add(versionedAncestor.getPath());
} else {
if (!checkedInModified.containsKey(workspace))
checkedInModified.put(workspace, new TreeSet<>());
- checkedInModified.get(workspace).add(jcrPath);
- versionManager.checkout(jcrPath);
+ checkedInModified.get(workspace).add(versionedAncestor.getPath());
+ versionManager.checkout(versionedAncestor.getPath());
}
}
return node;
}
+ private Node findVersionedAncestor(Node node) throws RepositoryException {
+ if (node.isNodeType(NodeType.MIX_SIMPLE_VERSIONABLE))
+ return node;
+ Node parent = node.getParent();
+ if (parent == null)
+ return null;
+ return findVersionedAncestor(parent);
+ }
+
public synchronized Node freeze(String workspace, String jcrPath) throws RepositoryException {
Session session = getWriteSession(workspace);
Node node = session.getNode(jcrPath);