* @throws DBException
*/
public static Map copy(Collection col, String dest, boolean overwrite, boolean deep) throws DBException {
Location destLocation = new Location(dest);
Collection destCollection = destLocation.getCollection();
String destName = destLocation.getName();
Map results = new HashMap();
if (destLocation.isRoot()) {
results.put(dest, new Integer(WebdavStatus.SC_BAD_REQUEST));
return results;
} else if (destCollection == null) {
// either intermidiate collection does not exist or destination points to
// the first level collection (database).
results.put(dest, new Integer(WebdavStatus.SC_CONFLICT));
return results;
} else if (deep && destCollection.getCanonicalName().startsWith(col.getCanonicalName())) {
// destination points to a location inside target collection subtree.
// deep copy does not make sense in that case
results.put(dest, new Integer(WebdavStatus.SC_FORBIDDEN));
return results;
}
// FIXME: the operations are not atomic, they can fail because of another
// thread deleting or creating collections. Introduce locks.
if (destName != null) { // destination collection does not exist
results.putAll(copyCollection(col, destCollection, destName, deep));
if (results.size() == 0) {
results.put(dest, new Integer(WebdavStatus.SC_CREATED));
}
} else { // existing collection
if (overwrite) {
// overwrites the collection
String name = destCollection.getName();
Collection parent = destCollection.getParentCollection();
// delete collection
parent.dropCollection(destCollection);
results.putAll(copyCollection(col, parent, name, deep));
if (results.size() == 0) {
results.put(dest, new Integer(WebdavStatus.SC_NO_CONTENT));
}
} else {