String fName = f.getName();
if (f.isDirectory() == true) {
// We need to create the child directory if it does not yet exist.
// If it does exist, but is not a collection, then we need to delete
// the existing resource and create the new collection
ContentNode node = n.getChild(fName);
if (node == null) {
node = n.createChild(fName, Type.COLLECTION);
}
else if (!(node instanceof ContentCollection)) {
node.getParent().removeChild(node.getName());
node = n.createChild(fName, Type.COLLECTION);
}
ContentCollection dir = (ContentCollection)node;
// Recursively descend the children and copy them over too.
File[] subdirs = f.listFiles();
if (subdirs != null) {
for (File child : subdirs) {
copyFiles(child, dir);
}
}
} else {
// For a file, create the file if it does not yet exist. If it does
// exist, but is not a resource, then delete the existing node and
// create a new resource
ContentNode node = n.getChild(fName);
if (node == null) {
node = n.createChild(fName, Type.RESOURCE);
}
else if (!(node instanceof ContentResource)) {
node.getParent().removeChild(node.getName());
node = n.createChild(fName, Type.RESOURCE);
}
ContentResource resource = (ContentResource)node;
resource.put(f);
}