?? replyaction.java
字號:
if (rbean.getSite().getId() != reply.getSid()) {
msg = getMessage(request, null, "error.param");
break;
}
if (!site.isOwner(loginUser)
&& !isReplyBelongToUser(rbean, loginUser.getId())) {
msg = getMessage(request, null, "error.access_deny");
break;
}
DiaryDAO.deleteDiaryReply(rbean);
break;
}
String fromPage = reply.getFromPage();
if (StringUtils.isNotEmpty(fromPage))
return msgbox(mapping, form, request, response, msg, fromPage);
return makeForward(mapping.findForward("diary"), reply.getSid());
}
protected boolean isReplyBelongToUser(_ReplyBean rb, int userid) {
return (rb.getUser() != null && rb.getUser().getId() == userid);
}
/**
* 發表日記評論
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
protected ActionForward doAddDiaryReply(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ReplyForm reply = (ReplyForm) form;
//驗證客戶端安全識別碼
validateClientId(request, reply);
ActionMessages msgs = new ActionMessages();
do{
if (StringUtils.isEmpty(reply.getContent())){
msgs.add("reply", new ActionMessage("error.empty_not_allowed"));
break;
}
if(reply.getContent().getBytes().length >= 3000){
msgs.add("reply", new ActionMessage("error.reply_too_long"));
break;
}
UserBean loginUser = super.getLoginUser(request, response);
SiteBean site = super.getSiteByID(reply.getSid());
if (site == null) {
msgs.add("reply", new ActionMessage("error.site_not_available"));
break;
}
//檢查黑名單
if(loginUser!=null && isUserInBlackList(site, loginUser)){
msgs.add("topic", new ActionMessage("error.user_in_blacklist"));
break;
}
DiaryOutlineBean diary = DiaryDAO.getDiaryOutlineByID(reply.getParentId());
if (diary == null || diary.getSite().getId() != reply.getSid()) {
msgs.add("reply", new ActionMessage("error.param"));
break;
}
if(diary.getLock()==1) {
msgs.add("reply", new ActionMessage("error.diary.locked"));
break;
}
// 補齊參數并寫入數據
DiaryReplyBean rbean = new DiaryReplyBean();
rbean.setUser(loginUser);
rbean.setAuthor(super.autoFiltrate(site,reply.getAuthor()));
if (StringUtils.isNotEmpty(reply.getAuthorURL()))
rbean.setAuthorURL(reply.getAuthorURL());
if (StringUtils.isNotEmpty(reply.getAuthorEmail()))
rbean.setAuthorEmail(reply.getAuthorEmail());
rbean.setClient(new ClientInfo(request, reply
.getClientType()));
String content = StringUtils.abbreviate(super.autoFiltrate(null,
reply.getContent()), MAX_REPLY_LENGTH);
rbean.setContent(super.filterScriptAndStyle(content));
rbean.setDiary(diary);
rbean.setReplyTime(new Date());
rbean.setSite(site);
rbean.setStatus(DiaryReplyBean.STATUS_NORMAL);
rbean.setOwnerOnly(reply.getOwnerOnly());
DiaryDAO.createDiaryReply(rbean);
// 判斷是否需要郵件提醒
if (diary.getReplyNotify() == 1) {
String email = diary.getOwner().getContactInfo()
.getEmail();
if (StringUtils.isEmail(email)) {
this.sendReplyNotify(request, rbean.getSite().getId(), rbean);
}
}
break;
}while(true);
if (!msgs.isEmpty()) {
saveMessages(request, msgs);
return mapping.findForward("diary-enter-reply");
}
return makeForward(mapping.findForward("showlog"), reply.getSid(),
"log_id", reply.getParentId());
}
/**
* 發表照片評論
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
protected ActionForward doAddPhotoReply(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ReplyForm reply = (ReplyForm) form;
//驗證客戶端安全識別碼
validateClientId(request, reply);
ActionMessages msgs = new ActionMessages();
PhotoReplyBean rbean = new PhotoReplyBean();
do{
if (StringUtils.isEmpty(reply.getContent())){
msgs.add("reply", new ActionMessage("error.empty_not_allowed"));
break;
}
if(reply.getContent().getBytes().length >= 3000){
msgs.add("reply", new ActionMessage("error.reply_too_long"));
break;
}
SiteBean site = super.getSiteByID(reply.getSid());
if (site == null) {
msgs.add("reply", new ActionMessage("error.site_not_available"));
break;
}
UserBean loginUser = super.getLoginUser(request, response);
//檢查黑名單
if(loginUser!=null && isUserInBlackList(site, loginUser)){
msgs.add("photo", new ActionMessage("error.user_in_blacklist"));
break;
}
PhotoOutlineBean photo = PhotoDAO.getPhotoOutlineByID(reply.getParentId());
if (photo == null || photo.getSite().getId() != reply.getSid()) {
msgs.add("reply", new ActionMessage("error.param"));
break;
}
if(photo.getLock()==1) {
msgs.add("reply", new ActionMessage("error.photo.locked"));
break;
}
// 補齊參數并寫入數據
rbean.setUser(loginUser);
rbean.setAuthor(super.autoFiltrate(site,reply.getAuthor()));
if (StringUtils.isNotEmpty(reply.getAuthorURL()))
rbean.setAuthorURL(reply.getAuthorURL());
if (StringUtils.isNotEmpty(reply.getAuthorEmail()))
rbean.setAuthorEmail(reply.getAuthorEmail());
rbean.setClient(new ClientInfo(request, reply
.getClientType()));
String content = StringUtils.abbreviate(super.autoFiltrate(null,
reply.getContent()), MAX_REPLY_LENGTH);
rbean.setContent(super.filterScriptAndStyle(content));
rbean.setPhoto(photo);
rbean.setReplyTime(new Date());
rbean.setSite(site);
rbean.setStatus(DiaryReplyBean.STATUS_NORMAL);
rbean.setOwnerOnly(reply.getOwnerOnly());
PhotoDAO.createPhotoReply(rbean);
break;
}while(true);
if (!msgs.isEmpty()) {
saveMessages(request, msgs);
return mapping.findForward("showphoto");
}
StringBuffer ext = new StringBuffer("pid=");
ext.append(reply.getParentId());
//ext.append('#');
//ext.append(rbean.getId());
return makeForward(mapping.findForward("showphoto"), reply.getSid(),
ext.toString());
}
/**
* 發送新評論郵件提醒
*
* @param request
* @param rbean
* @throws Exception
*/
protected void sendReplyNotify(HttpServletRequest request, final int site_id,
final DiaryReplyBean rbean) throws Exception {
final String contextPath = request.getContextPath();
final String urlPrefix = RequestUtils.getUrlPrefix(request);
final String template = super.getReplyNotifyTemplate();
new Thread() {
public void run() {
try {
StringBuffer url = new StringBuffer();
url.append(urlPrefix);
url.append(contextPath);
url.append("/html/diary/showlog.vm?sid=");
url.append(rbean.getSite().getId());
url.append("&log_id=");
url.append(rbean.getDiary().getId());
url.append("#");
url.append(rbean.getId());
String curTime = new SimpleDateFormat("yyyy-MM-dd HH:mm")
.format(new Date());
// 發送郵件提醒
String notify_content = MessageFormat.format(template,
new String[]{rbean.getDiary().getOwner().getNickname(),
rbean.getDiary().getTitle(), rbean.getAuthor(),
url.toString(), curTime, rbean.getContent()});
Parser html = new Parser();
html.setEncoding(Globals.ENC_8859_1);
html.setInputHTML(notify_content);
Node[] nodes = html.extractAllNodesThatMatch(
HtmlNodeFilters.titleFilter).toNodeArray();
String title = nodes[0].toPlainTextString();
MailSender sender = MailSender.getHtmlMailSender(null, 25,
null, null);
sender.setSubject(title);
sender.setSendDate(new Date());
sender.setMailContent(notify_content);
sender.setMailTo(new String[] { rbean.getDiary().getOwner()
.getContactInfo().getEmail() }, "to");
MailTransportQueue queue = (MailTransportQueue) getServlet()
.getServletContext().getAttribute(
Globals.MAIL_QUEUE);
// 寫入待發送郵件隊列
queue.write(site_id, sender
.getMimeMessage());
if(log.isDebugEnabled())
log.debug("Notification mail was written to the sending queue.");
} catch (Exception e) {
log.error("send notification mail failed.", e);
}
}
}.start();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -