private void cloneStructEntryTree(WGStructEntry rootEntry, WGDocument cloneParent, WGDatabase to, List contentClones, Map oldToNewContentKeys)
throws WGAPIException {
// Clone entry
WGStructEntry entryClone = null;
validate(rootEntry);
_log.info("Cloning struct entry '" + rootEntry.getStructKey() + "'");
try {
entryClone = (WGStructEntry) createDumpClone(rootEntry, cloneParent);
}
catch (WGAPIException e) {
handleException("Error cloning struct entry", e, rootEntry);
return;
}
if (entryClone == null) {
handleSaveError("Unable to clone struct entry.", rootEntry);
return;
}
rootEntry.dropCore();
entryClone.dropCore();
incSourceDocCounter();
incTargetDocCounter();
// Clone contents of entry
Iterator contents = rootEntry.getAllContent(true).iterator();
WGContent content;
WGContent contentClone;
while (contents.hasNext()) {
content = (WGContent) contents.next();
validate(content);
_log.info("Cloning content '" + content.getContentKey() + "'");
try {
contentClone = (WGContent) createDumpClone(content, entryClone);
}
catch (WGAPIException e1) {
handleException("Error cloning content", e1, content);
return;
}
if (contentClone == null) {
handleSaveError("Unable to clone content.", content);
continue;
}
contentClone.dropCore();
content.dropCore();
incSourceDocCounter();
incTargetDocCounter();
oldToNewContentKeys.put(content.getContentKey(true).toString(), contentClone.getContentKey().toString());
if (contentClone.getStatus().equals(WGContent.STATUS_RELEASE)) {
oldToNewContentKeys.put(content.getContentKey(false).toString(), contentClone.getContentKey(false).toString());
oldToNewContentKeys.put(content.getStructKey() + "." + content.getLanguage().getName() + ".p", contentClone.getContentKey(false).toString());
}
contentClones.add(contentClone);
entryClone.dropCore();
rootEntry.dropCore();
}
// Proceed with child entries the same way