* @throws IOException
* @throws DotHibernateException
*/
private File copyFile ( File file, Folder parent, Host host ) throws DotDataException, IOException {
File newFile = new File();
newFile.copy( file );
newFile.setParent(parent.getInode());
// gets filename before extension
String fileName = com.dotmarketing.util.UtilMethods.getFileName( file.getFileName() );
// gets file extension
String fileExtension = com.dotmarketing.util.UtilMethods.getFileExtension( file.getFileName() );
Boolean fileNameExists;
if (parent != null) {
fileNameExists = fileNameExists( parent, file.getFileName() );
} else {
fileNameExists = fileNameExists( APILocator.getFolderAPI().findSystemFolder(), file.getFileName() );
}
// Setting file name
if ( fileNameExists ) {
// adds "copy" word to the filename
newFile.setFileName( fileName + "_copy." + fileExtension );
newFile.setFriendlyName( file.getFriendlyName() + " (COPY) " );
} else {
newFile.setFileName( fileName + "." + fileExtension );
}
Identifier identifier;
if ( parent != null ) {
identifier = APILocator.getIdentifierAPI().createNew( newFile, parent );
} else {
identifier = APILocator.getIdentifierAPI().createNew( newFile, host );
}
newFile.setIdentifier( identifier.getInode() );
// persists the webasset
HibernateUtil.saveOrUpdate( newFile );
saveFileData( file, newFile, null );