SiteTree sourceTree = getTree(sourceDocument);
SiteTree destinationTree = getTree(destinationDocument);
SiteTreeNode sourceNode = sourceTree.getNode(sourceDocument.getId());
if (sourceNode == null) {
throw new SiteException("The node for source document [" + sourceDocument.getId()
+ "] doesn't exist!");
}
SiteTreeNode[] siblings = sourceNode.getNextSiblings();
SiteTreeNode parent = sourceNode.getParent();
String parentId = "";
if (parent != null) {
parentId = parent.getAbsoluteId();
}
SiteTreeNode sibling = null;
String siblingDocId = null;
// same document ID -> insert at the same position
if (sourceDocument.getId().equals(destinationDocument.getId())) {
for (int i = 0; i < siblings.length; i++) {
String docId = parentId + "/" + siblings[i].getId();
sibling = destinationTree.getNode(docId);
if (sibling != null) {
siblingDocId = docId;
break;
}
}
}
Label label = sourceNode.getLabel(sourceDocument.getLanguage());
if (label == null) {
// the node that we're trying to publish
// doesn't have this language
throw new SiteException("The node " + sourceDocument.getId()
+ " doesn't contain a label for language " + sourceDocument.getLanguage());
}
SiteTreeNode destinationNode = destinationTree.getNode(destinationDocument.getId());
if (destinationNode == null) {
Label[] labels = { label };