final HttpServletResponse response) throws Exception
{
PhotoForm photo1 = (PhotoForm)form;
validateClientId(request, photo1);
ActionMessages msgs = new ActionMessages();
do{
FormFile[] files = new FormFile[5];
files[0] = photo1.getImage();
files[1] = photo1.getImage2();
files[2] = photo1.getImage3();
files[3] = photo1.getImage4();
files[4] = photo1.getImage5();
//����ಾ�Ƿ���Ч
AlbumBean album = AlbumDAO.getAlbumByID(photo1.getAlbum());
if (album == null) {
msgs.add(ERROR_KEY, new ActionMessage(
"error.object_not_found", String.valueOf(photo1
.getAlbum())));
break;
}
SiteBean site = super.getSiteBean(request);
UserBean loginUser = super.getLoginUserAfterValidateSiteOwner(request);
String photo_desc;
if(StringUtils.isNotEmpty(photo1.getDesc())){
photo_desc = StringUtils.abbreviate(super.autoFiltrate(
site, photo1.getDesc()), MAX_PHOTO_DESC_LENGTH);
photo_desc = super.filterScriptAndStyle(photo_desc);
}
else
photo_desc = " ";
for(int i=0;i<files.length;i++){
if(files[i]==null || files[i].getFileSize()<=0 || StringUtils.isEmpty(files[i].getFileName()))
continue;
//�жϵ���ͼƬ�Ĵ�С
/*
if(files[i].getFileSize()>4194304){//4*1024*1024
msgs.add(ERROR_KEY, new ActionMessage("error.file_too_large"));
break;
}*/
if(!accept(files[i])){
msgs.add(ERROR_KEY, new ActionMessage("error.upload_file_not_supported"));
break;
}
//����ϴ��ռ�����
int photo_size = DLOG4JUtils.sizeInKbytes(files[i].getFileSize());
int max_photo_size = site.getCapacity().getPhotoTotal();
if(max_photo_size >= 0){
int current_size = site.getCapacity().getPhotoUsed();
if((current_size + photo_size) > max_photo_size){
msgs.add(ERROR_KEY, new ActionMessage("error.photo_space_full"));
break;
}
}
//������Ƭ����������ͼ
Photo img = null;
try{
img = getPhotoSaver().save(
getHttpContext(mapping, form, request, response),
files[i], photo1.getAutoRotate() == 1);
if(img == null){
msgs.add(ERROR_KEY, new ActionMessage("error.upload_failed"));
break;
}
//д�뵽���ݿ�
PhotoBean pbean = new PhotoBean();
pbean.setSite(site);
pbean.setUser(loginUser);
if(StringUtils.isNotEmpty(photo1.getName())){
pbean.setName(super.autoFiltrate(site, photo1.getName()));
}
else
pbean.setName(img.getName());
pbean.setDesc(photo_desc);
if(StringUtils.isNotEmpty(photo1.getKeyword())){
if(site.isFlagSet(SiteBean.Flag.ILLEGAL_GLOSSARY_IGNORE))
pbean.setKeyword(photo1.getKeyword());
else
pbean.setKeyword(DLOGSecurityManager.IllegalGlossary
.deleteIllegalWord(photo1.getKeyword()));
}
pbean.setPreviewURL(img.getPreviewURL());
pbean.setImageURL(img.getImageURL());
pbean.setPhotoInfo(img);
pbean.setFileName(super.autoFiltrate(site,img.getFileName()));
pbean.setStatus(photo1.getStatus());//������������
PhotoDAO.create(album, pbean, (photo1.getCover()==1));
}catch(IllegalAccessException e){
msgs.add(ERROR_KEY, new ActionMessage("error.access_deny", e.getMessage()));
break;
}catch(Exception e){
log.error("Upload photo file failed.", e);
msgs.add(ERROR_KEY, new ActionMessage("error.upload_failed", e.getMessage()));
break;
}
}
break;
}while(true);
if(!msgs.isEmpty()){
saveMessages(request, msgs);
ActionForward upload = makeForward(mapping.findForward("photo_upload"), photo1.getSid());
upload.setRedirect(false);
return upload;
}