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

📄 postthreadaction.java

📁 Chinaxp 论坛源代码
💻 JAVA
字号:
package org.redsoft.forum.web;import org.apache.struts.action.*;import org.redsoft.forum.dao.*;import org.redsoft.forum.exception.AccountNotFoundException;import org.redsoft.forum.exception.DAOException;import org.redsoft.forum.exception.ThreadNotFoundException;import org.redsoft.forum.mail.MailAgent;import org.redsoft.forum.util.StringUtils;import javax.servlet.ServletException;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import java.io.IOException;/** * Post a thread * * @author Charles Huang * @version 1,March 10,2002 */public final class   PostThreadAction extends Action {   /**     * Process the specified HTTP request, and create the corresponding HTTP     * response (or forward to another web component that will create it).     * Return an <code>ActionForward</code> instance describing where and how     * control should be forwarded, or <code>null</code> if the response has     * already been completed.     *     * @param mapping The ActionMapping used to select this instance     * @param form The optional ActionForm bean for this request (if any)     * @param request The HTTP request we are processing     * @param response The HTTP response we are creating     *     * @exception IOException if an input/output error occurs     * @exception ServletException if a servlet exception occurs     */    public ActionForward execute(ActionMapping mapping,				 ActionForm form,				 HttpServletRequest request,				 HttpServletResponse response)	throws IOException, ServletException {    final ActionErrors errors = new ActionErrors();    final String author = ((PostThreadForm) form).getAuthor();	String content = ((PostThreadForm) form).getContent();	String subject = ((PostThreadForm) form).getSubject();    final String parentID = ((PostThreadForm) form).getParentID();    final String category = ((PostThreadForm) form).getCategory();    final String repliedThreadID = ((PostThreadForm) form).getRepliedThreadID();    final String notifyString = ((PostThreadForm) form).getNotify();    boolean notify = false;    if( notifyString != null &&  notifyString.equals("Y") ){		notify = true;	}   	HttpSession session = request.getSession();    // Create a persistent thread object with the input data    // The reply is set to 1 by default for a new thread    long currentTime = System.currentTimeMillis();    final org.redsoft.forum.dao.Thread newThread        = new org.redsoft.forum.dao.Thread( subject,                                content,                                author,                                currentTime,                                Long.parseLong( parentID ),                                Integer.parseInt( category ),                                0,// reply                                0,                                Long.parseLong( repliedThreadID ), //reply                                notify );    // Persist the thread object using ThreadDAO    try{        final ThreadDAO dao = DAOFactory.getInstance().getThreadDAO();        dao.addThread( newThread );        // If this is a reply post,check if we need to send out a notification email        if( Long.parseLong( repliedThreadID ) != -1 ){            final PersistentThread thread = dao.findByUID( Long.parseLong( repliedThreadID ) );            // If this thread allows notification,we send the author an email            if( thread.isNotify() ){                final AccountDAO accountDAO = DAOFactory.getInstance().getAccountDAO();                final Account account = accountDAO.findByUserName( thread.getAuthor() );                final String url = "http://www.chinaxp.org/forum/viewThread.go?parentId=" + Long.parseLong( parentID ) + "&forum=" + Integer.parseInt( category );                final String messageBody = "<b>" + subject + "</b>"                        + StringUtils.escapeHTMLTagsButHref( content )                        + "<br>" + "<a href='" + url + "'>" + url + "</a>" ;                // Spwan a thread to send email to avoid blocking                new MailAgent(                        account.getEmail(),                        "chinaxp@chinaxp.org",                        subject,                        MailAgent.createHtmlMailBody( messageBody )                ).start();            }        }    } catch (DAOException e) {        e.printStackTrace();        return (mapping.findForward("error"));    }catch( final ThreadNotFoundException threadNotFound ){        threadNotFound.printStackTrace();        return (mapping.findForward("error"));    }catch( final AccountNotFoundException accountNotFound ){        accountNotFound.printStackTrace();        return (mapping.findForward("error"));    }    // Report any errors we have discovered back to the original form	if (!errors.isEmpty()) {	    saveErrors(request, errors);	    return (new ActionForward(mapping.getInput()));	}    // Remove the obsolete form bean	if (mapping.getAttribute() != null) {            if ("request".equals(mapping.getScope()))                request.removeAttribute(mapping.getAttribute());            else                session.removeAttribute(mapping.getAttribute());        }	// Forward control to the specified success URI	return ( new ActionForward( mapping.findForward("success").getPath()+"?forum=" + category, true));    }}

⌨️ 快捷键说明

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