⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 replyaction.java

📁 个人Blog java编写的Blog可以直接使用!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			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 + -