if(haveUpload) {
if ((uploadFileMaxSize > 0) && (uploadedFile.length() > uploadFileMaxSize)) {
// when there is an error saving should unlock working asset
WebAssetFactory.unLockAsset(currentFile);
throw new ActionException();
}
}
// CHECK THE FOLDER PATTERN
if (UtilMethods.isSet(file.getFileName()) && !APILocator.getFolderAPI().matchFilter(folder, file.getFileName())) {
SessionMessages.add(req, "error", "message.file_asset.error.filename.filters");
// when there is an error saving should unlock working asset
WebAssetFactory.unLockAsset(currentFile);
throw new ActionException("message.file_asset.error.filename.filters");
}
// Checking permissions
_checkPermissions(currentFile, folder, user, httpReq);
//Setting some flags
boolean editing = (InodeUtils.isSet(currentFile.getInode()));
if(!haveUpload){
uploadedFile = APILocator.getFileAPI().getAssetIOFile(currentFile);
tmpFile = false;
}
// if we don't have a file anywhere, die
if(!(uploadedFile.exists() && uploadedFile.length()>0)){
SessionMessages.add(req, "error", "message.file_asset.error.nofile");
// when there is an error saving should unlock working asset
WebAssetFactory.unLockAsset(currentFile);
throw new ActionException("message.file_asset.error.nofile");
}
String fileName = (editing) ? currentFile.getFileName() : fileForm.getFileName();
//getting mime type
String mimeType = APILocator.getFileAPI().getMimeType(fileName);
file.setMimeType(mimeType);
if (editing && haveUpload && !
APILocator.getFileAPI().getMimeType(fileName).equals(APILocator.getFileAPI().getMimeType(uploadedFile.getName()))) {
SessionMessages.add(req, "error", "message.file_asset.error.mimetype");
// when there is an error saving should unlock working asset
Logger.error(this.getClass(), "MimeType Mismatch:" + fileName + " : " + uploadedFile.getName());
WebAssetFactory.unLockAsset(currentFile);
HibernateUtil.rollbackTransaction();
throw new ActionException("message.file_asset.error.mimetype");
}
// checks if another identifier with the same name exists in the same
// folder
if ((!editing) && (APILocator.getFileAPI().fileNameExists(folder, fileName))) {
SessionMessages.add(req, "error", "message.file_asset.error.filename.exists");
throw new ActionException("message.file_asset.error.filename.exists");
}
//sets new file properties
file.setFileName(fileName);
file.setModUser(userId);
if (haveUpload) {
file.setSize((int)uploadedFile.length());
}
else {
file.setSize(currentFile.getSize());
file.setWidth(currentFile.getWidth());
file.setHeight(currentFile.getHeight());
}
//Saving the file, this creates the new version and save the new data
File workingFile = null;
workingFile = APILocator.getFileAPI().saveFile(file, uploadedFile, folder, user, false);
APILocator.getVersionableAPI().setWorking(file);
APILocator.getVersionableAPI().setLocked(file, false, user);
if(uploadedFile != null && uploadedFile.exists() &&tmpFile){
uploadedFile.delete();
}
SessionMessages.add(req, "message", "message.file_asset.save");
// for file in a popup
if (req.getParameter("popup") != null) {
req.setAttribute("fileInode", file.getInode() + "");
req.setAttribute("fileName", file.getFileName() + "");
}
req.setAttribute(WebKeys.FILE_FORM_EDIT, workingFile);
// copies the information back into the form bean
BeanUtils.copyProperties(form, req.getAttribute(WebKeys.FILE_FORM_EDIT));
//Refreshing the menues
if (previousShowMenu != file.isShowOnMenu()) {
//existing folder with different show on menu ... need to regenerate menu
RefreshMenus.deleteMenu(file);
CacheLocator.getNavToolCache().removeNav(folder.getHostId(), folder.getInode());
}
} catch (Exception e) {
Logger.error(this, "\n\n\nEXCEPTION IN FILE SAVING!!! " + e.getMessage(), e);
throw new ActionException(e.getMessage());
}
}