| Code with Misuse: |
class CopyOperation {
/**
* Copy the <code>src</code> node into the <code>dstParent</code> node.
* The name of the newly created node is set to <code>name</code>.
* <p>
* This method does a recursive (deep) copy of the subtree rooted at the
* source node to the destination. Any protected child nodes and and
* properties are not copied.
*
* @param src The node to copy to the new location
* @param dstParent The node into which the <code>src</code> node is to be
* copied
* @param name The name of the newly created node. If this is
* <code>null</code> the new node gets the same name as the
* <code>src</code> node.
* @throws RepositoryException May be thrown in case of any problem copying
* the content.
*/
static Item copy(Node src, Node dstParent, String name)
throws RepositoryException {
// ensure destination name
if (name == null) {
name = src.getName();
}
// ensure new node creation
if (dstParent.hasNode(name)) {
dstParent.getNode(name).remove();
}
// create new node
Node dst = dstParent.addNode(name, src.getPrimaryNodeType().getName());
for (NodeType mix : src.getMixinNodeTypes()) {
dst.addMixin(mix.getName());
}
// copy the properties
for (PropertyIterator iter = src.getProperties(); iter.hasNext();) {
copy(iter.nextProperty(), dst, null);
}
// copy the child nodes
for (NodeIterator iter = src.getNodes(); iter.hasNext();) {
Node n = iter.nextNode();
if (!n.getDefinition().isProtected()) {
copy(n, dst, null);
}
}
return dst;
}
}
|