}
protected void postProcessNodes() throws SAXException {
try {
for (AbstractJcrNode node : nodesForPostProcessing) {
MutableCachedNode mutable = node.mutable();
// ---------------
// mix:versionable
// ---------------
if (node.isNodeType(JcrMixLexicon.VERSIONABLE)) {
// Does the versionable node already have a reference to the version history?
// If so, then we ignore it because we'll use our own key ...
// Does the versionable node already have a base version?
AbstractJcrProperty baseVersionProp = node.getProperty(JcrLexicon.BASE_VERSION);
if (baseVersionProp != null) {
// we rely on the fact that the base version ref is exported with full key
NodeKeyReference baseVersionRef = (NodeKeyReference)baseVersionProp.getValue().value();
String workspaceKey = baseVersionRef.getNodeKey().getWorkspaceKey();
//we only register the base version if it comes from the system workspace (if it doesn't come from the
//system workspace, it's not valid - e.g. could be coming from an older version of ModeShape)
if (systemWorkspaceKey.equals(workspaceKey)) {
session.setDesiredBaseVersionKey(node.key(), baseVersionRef.getNodeKey());
}
}
}
// ---------------
// mix:lockable
// ---------------
if (node.isNodeType(JcrMixLexicon.LOCKABLE) && node.isLocked()) {
// Nodes should not be locked upon import ...
node.unlock();
}
// ---------------
// mix:lifecycle
// ---------------
if (node.isNodeType(JcrMixLexicon.LIFECYCLE)) {
if (lifecycleInfoRetained && !isValidReference(node, JcrLexicon.LIFECYCLE_POLICY, false)) {
// The 'jcr:lifecyclePolicy' REFERENCE values is not valid or does not reference an existing node,
// so the 'jcr:lifecyclePolicy' and 'jcr:currentLifecycleState' properties should be removed...
mutable.removeProperty(cache, JcrLexicon.LIFECYCLE_POLICY);
mutable.removeProperty(cache, JcrLexicon.CURRENT_LIFECYCLE_STATE);
}
}
// --------------------
// mix:managedRetention
// --------------------
if (node.isNodeType(JcrMixLexicon.MANAGED_RETENTION)) {
if (retentionInfoRetained && !isValidReference(node, JcrLexicon.RETENTION_POLICY, false)) {
// The 'jcr:retentionPolicy' REFERENCE values is not valid or does not reference an existing node,
// so the 'jcr:retentionPolicy', 'jcr:hold' and 'jcr:isDeep' properties should be removed ...
mutable.removeProperty(cache, JcrLexicon.HOLD);
mutable.removeProperty(cache, JcrLexicon.IS_DEEP);
mutable.removeProperty(cache, JcrLexicon.RETENTION_POLICY);
}
}
// --------------------
// mix:share
// --------------------
if (node.isNodeType(ModeShapeLexicon.SHARE)) {
// get the actual key of the shareable node
String shareableNodeUUID = shareIdsToUUIDMap.get(node.key());
assert shareableNodeUUID != null;
NodeKey shareableNodeKey = uuidToNodeKeyMapping.get(shareableNodeUUID);
assert shareableNodeKey != null;
// unlink the current key from its parent references
NodeKey parentKey = mutable.getParentKey(cache);
MutableCachedNode parent = cache.mutable(parentKey);
parent.removeChild(cache, node.key());
// re-link it with the correct key - that of the shareable node
parent.linkChild(cache, shareableNodeKey, node.name());
}
}
// Restore the back references ...
if (!referrersByNodeKey.isEmpty()) {
for (Map.Entry<NodeKey, ReferrerCounts> entry : referrersByNodeKey.entrySet()) {
PropertyFactory propFactory = context.getPropertyFactory();
MutableCachedNode referred = cache.mutable(entry.getKey());
ReferrerCounts counts = entry.getValue();
if (referred != null && counts != null) {
// Add in the strong and weak referrers (that are outside the import scope) that used to be in the node
// before it was replaced ...
for (NodeKey key : counts.getStrongReferrers()) {
int count = counts.countStrongReferencesFrom(key);
for (int i = 0; i != count; ++i) {
Property prop = propFactory.create(nameFor(key.toString() + i));
referred.addReferrer(cache, prop, key, ReferenceType.STRONG);
}
}
for (NodeKey key : counts.getWeakReferrers()) {
int count = counts.countWeakReferencesFrom(key);
for (int i = 0; i != count; ++i) {
Property prop = propFactory.create(nameFor(key.toString() + i));
referred.addReferrer(cache, prop, key, ReferenceType.WEAK);
}
}
}
}
}