// a node with that name already exists...
NodeState.ChildNodeEntry entry =
parent.getChildNodeEntry(nodeName, 1);
NodeId idExisting = entry.getId();
NodeState existing = (NodeState) itemOps.getItemState(idExisting);
NodeDef def = ntReg.getNodeDef(existing.getDefinitionId());
if (!def.allowsSameNameSiblings()) {
// existing doesn't allow same-name siblings,
// check for potential conflicts
EffectiveNodeType entExisting =
itemOps.getEffectiveNodeType(existing);
if (def.isProtected() && entExisting.includesNodeType(ntName)) {
// skip protected node
parents.push(null); // push null onto stack for skipped node
succeeded = true;
log.debug("skipping protected node "
+ itemOps.safeGetJCRPath(existing.getNodeId()));
return;
}
if (def.isAutoCreated() && entExisting.includesNodeType(ntName)) {
// this node has already been auto-created,
// no need to create it
node = existing;
} else {
throw new ItemExistsException(itemOps.safeGetJCRPath(existing.getNodeId()));
}
}
}
if (node == null) {
// there's no node with that name...
if (id == null) {
// no potential uuid conflict, always create new node
NodeDef def =
itemOps.findApplicableNodeDefinition(nodeName, ntName, parent);
if (def.isProtected()) {
// skip protected node
parents.push(null); // push null onto stack for skipped node
succeeded = true;
log.debug("skipping protected node " + nodeName);
return;
}
if (parent.hasPropertyName(nodeName)) {
/**
* a property with the same name already exists; if this property
* has been imported as well (e.g. through document view import
* where an element can have the same name as one of the attributes
* of its parent element) we have to rename the onflicting property;
*
* see http://issues.apache.org/jira/browse/JCR-61
*/
PropertyId propId = new PropertyId(parent.getNodeId(), nodeName);
PropertyState conflicting = itemOps.getPropertyState(propId);
if (conflicting.getStatus() == ItemState.STATUS_NEW) {
// assume this property has been imported as well;
// rename conflicting property
// @todo use better reversible escaping scheme to create unique name
QName newName = new QName(nodeName.getNamespaceURI(), nodeName.getLocalName() + "_");
if (parent.hasPropertyName(newName)) {
newName = new QName(newName.getNamespaceURI(), newName.getLocalName() + "_");
}
PropertyState newProp =
itemOps.createPropertyState(parent, newName,
conflicting.getType(), conflicting.getValues().length);
newProp.setValues(conflicting.getValues());
parent.removePropertyName(nodeName);
itemOps.store(parent);
itemOps.destroy(conflicting);
}
}
// check if new node can be added (check access rights &
// node type constraints only, assume locking & versioning status
// has already been checked on ancestor)
itemOps.checkAddNode(parent, nodeName, ntName,
BatchedItemOperations.CHECK_ACCESS
| BatchedItemOperations.CHECK_CONSTRAINTS);
// do create new node
node = itemOps.createNodeState(parent, nodeName, ntName, mixins, null, def);
} else {
// potential uuid conflict
NodeState conflicting;
try {
conflicting = itemOps.getNodeState(id);
} catch (ItemNotFoundException infe) {
conflicting = null;
}
if (conflicting != null) {
// resolve uuid conflict
node = resolveUUIDConflict(parent, conflicting, nodeInfo);
} else {
// create new with given uuid
NodeDef def =
itemOps.findApplicableNodeDefinition(nodeName, ntName, parent);
if (def.isProtected()) {
// skip protected node
parents.push(null); // push null onto stack for skipped node
succeeded = true;
log.debug("skipping protected node " + nodeName);
return;