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

📄 replyaction.java

📁 个人Blog java编写的Blog可以直接使用!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 *  ReplyAction.java
 *  
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *  
 *  Author: Winter Lau
 *  http://dlog4j.sourceforge.net
 *  
 */
package com.liusoft.dlog4j.action;

import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.htmlparser.Node;
import org.htmlparser.Parser;

import com.liusoft.dlog4j.Globals;
import com.liusoft.dlog4j.HtmlNodeFilters;
import com.liusoft.dlog4j.MailTransportQueue;
import com.liusoft.dlog4j.base.ClientInfo;
import com.liusoft.dlog4j.base._ReplyBean;
import com.liusoft.dlog4j.beans.DiaryOutlineBean;
import com.liusoft.dlog4j.beans.DiaryReplyBean;
import com.liusoft.dlog4j.beans.PhotoOutlineBean;
import com.liusoft.dlog4j.beans.PhotoReplyBean;
import com.liusoft.dlog4j.beans.SiteBean;
import com.liusoft.dlog4j.beans.UserBean;
import com.liusoft.dlog4j.dao.DiaryDAO;
import com.liusoft.dlog4j.dao.PhotoDAO;
import com.liusoft.dlog4j.dao.ReplyDAO;
import com.liusoft.dlog4j.formbean.ReplyForm;
import com.liusoft.dlog4j.util.RequestUtils;
import com.liusoft.dlog4j.util.StringUtils;

import com.liusoft.dlog4j.util.MailSender;

/**
 * 评论操作相关的Action类
 * 
 * @author liudong
 */
public class ReplyAction extends ActionBase {

	private final static Log log = LogFactory.getLog(ReplyAction.class);
	
	/**
	 * 修改照片评论
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	protected ActionForward doUpdatePhotoReply(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ReplyForm reply = (ReplyForm) form;
		//验证客户端安全识别码
		validateClientId(request, reply);
		ActionMessages msgs = new ActionMessages();
		UserBean loginUser = super.getLoginUser(request, response);
		while (loginUser != null) {
			if (StringUtils.isEmpty(reply.getContent())) {
				msgs.add("reply", new ActionMessage("error.empty_not_allowed"));
				break;
			}
			SiteBean site = super.getSiteByID(reply.getSid());
			if (site == null) {
				msgs.add("reply", new ActionMessage("error.site_not_available"));
				break;
			}
			_ReplyBean rbean = ReplyDAO.getReply(PhotoReplyBean.class, reply
					.getReply_id());
			if (rbean!=null && rbean.getSite().getId() == site.getId()) {
				String content = StringUtils.abbreviate(super.autoFiltrate(
					null, reply.getContent()), MAX_REPLY_LENGTH);
				rbean.setContent(super.filterScriptAndStyle(content));
				rbean.setAuthor(reply.getAuthor());				
				rbean.setOwnerOnly(reply.getOwnerOnly());
				if (StringUtils.isNotEmpty(reply.getAuthorURL()))
					rbean.setAuthorURL(reply.getAuthorURL());
				if (StringUtils.isNotEmpty(reply.getAuthorEmail()))
					rbean.setAuthorEmail(reply.getAuthorEmail());
				ReplyDAO.updateReply(rbean);
			}
			break;
		}
		if (!msgs.isEmpty()) {
			saveMessages(request, msgs);
			return mapping.findForward("showphoto");
		}
		StringBuffer ext = new StringBuffer("pid=");
		ext.append(reply.getParentId());
		ext.append('#');
		ext.append(reply.getReply_id());
		return makeForward(mapping.findForward("showphoto"), reply.getSid(),
				ext.toString());
	}

	/**
	 * 修改日记评论
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	protected ActionForward doUpdateDiaryReply(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ReplyForm reply = (ReplyForm) form;
		//验证客户端安全识别码
		validateClientId(request, reply);
		ActionMessages msgs = new ActionMessages();
		UserBean loginUser = super.getLoginUser(request, response);
		while (loginUser != null) {
			if (StringUtils.isEmpty(reply.getContent())) {
				msgs.add("reply", new ActionMessage("error.empty_not_allowed"));
				break;
			}
			SiteBean site = super.getSiteByID(reply.getSid());
			if (site == null) {
				msgs.add("reply", new ActionMessage("error.site_not_available"));
				break;
			}
			_ReplyBean rbean = ReplyDAO.getReply(DiaryReplyBean.class, reply.getReply_id());
			if (rbean!=null && rbean.getSite().getId() == site.getId()) {
				String content = StringUtils.abbreviate(super.autoFiltrate(
						null, reply.getContent()), MAX_REPLY_LENGTH);
				rbean.setContent(super.filterScriptAndStyle(content));
				rbean.setAuthor(reply.getAuthor());				
				rbean.setOwnerOnly(reply.getOwnerOnly());
				if (StringUtils.isNotEmpty(reply.getAuthorURL()))
					rbean.setAuthorURL(reply.getAuthorURL());
				if (StringUtils.isNotEmpty(reply.getAuthorEmail()))
					rbean.setAuthorEmail(reply.getAuthorEmail());
				ReplyDAO.updateReply(rbean);
			}
			break;
		}
		if (!msgs.isEmpty()) {
			saveMessages(request, msgs);
			return mapping.findForward("showlog");
		}
		return makeForward(mapping.findForward("showlog"), reply.getSid(),
				"log_id", reply.getParentId());
	}

	/**
	 * 删除照片评论
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	protected ActionForward doDeletePhotoReply(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response, String s_reply_id) throws Exception {
		String msg = null;
		ReplyForm reply = (ReplyForm) form;
		int reply_id = Integer.parseInt(s_reply_id);
		UserBean loginUser = super.getLoginUser(request, response);
		while (loginUser != null) {
			SiteBean site = super.getSiteByID(reply.getSid());
			if (site == null) {
				msg = getMessage(request, null, "error.site_not_available");
				break;
			}
			PhotoReplyBean rbean = (PhotoReplyBean) ReplyDAO.getReply(
					PhotoReplyBean.class, reply_id);
			if (rbean == null)
				break;
			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;
			}
			PhotoDAO.deletePhotoReply(rbean);
			break;
		}
		
		String fromPage = reply.getFromPage();
		
		if (StringUtils.isNotEmpty(fromPage))
			return msgbox(mapping, form, request, response, msg, fromPage);
		return makeForward(mapping.findForward("photo"), reply.getSid());
	}

	/**
	 * 删除日记评论
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	protected ActionForward doDeleteDiaryReply(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response, String s_reply_id) throws Exception {
		String msg = null;
		ReplyForm reply = (ReplyForm) form;
		int reply_id = Integer.parseInt(s_reply_id);
		UserBean loginUser = super.getLoginUser(request, response);
		while (loginUser != null) {
			SiteBean site = super.getSiteByID(reply.getSid());
			if (site == null) {
				msg = getMessage(request, null, "error.site_not_available");
				break;
			}
			DiaryReplyBean rbean = (DiaryReplyBean) ReplyDAO.getReply(
					DiaryReplyBean.class, reply_id);
			if (rbean == null)
				break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -