📄 viewthreadaction.java
字号:
/*
* XP Forum
*
* Copyright (c) 2002-2003 RedSoft Group. All rights reserved.
*
*/
package org.redsoft.forum.web;
import org.apache.struts.action.*;
import org.apache.struts.util.RequestUtils;
import org.redsoft.forum.dao.ThreadDAO;
import org.redsoft.forum.dao.DAOFactory;
import org.redsoft.forum.dao.PersistentThread;
import org.redsoft.forum.exception.ThreadNotFoundException;
import org.redsoft.forum.ForumConstants;
import org.redsoft.forum.util.StringUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Iterator;
import java.sql.SQLException;
/**
* View all the threads
*
* @author <a href="mailto:jwtronics@yahoo.com">John Wong</a>
*
* @version $Id: ViewThreadAction.java,v 1.1.1.1 2003/07/08 08:25:17 cinc Exp $
*/
public class ViewThreadAction extends Action {
public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
ActionErrors errors = new ActionErrors();
final ThreadDAO dao = DAOFactory.getInstance().getThreadDAO();
// If there are selected records for remove,remove selected threads
final String[] seletedThreads = request.getParameterValues( "remove" );
if( seletedThreads != null && seletedThreads.length > 0 ){
try{
for( int index = 0; index < seletedThreads.length; index++ ){
dao.removeThread( Long.parseLong( seletedThreads[ index ] ) );
}
}catch ( final SQLException sqlException ){
sqlException.printStackTrace();
return (mapping.findForward("error"));
}
}
final String parentId = request.getParameter(ForumConstants.PARENT_ID_PARAM);
if(parentId == null || parentId.equals("")) {
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError("error.parentId.invalid"));
}
long id = Long.parseLong(parentId);
try {
// update the click count
dao.updateClick(id);
Collection pts = dao.findByParnetID(id);
Collection threads = new ArrayList(pts.size());
Iterator itr = pts.iterator();
while(itr.hasNext()) {
PersistentThread pt = (PersistentThread) itr.next();
Thread t = new Thread(pt.getID(), pt.getTitle(),
pt.getContent(),
pt.getAuthor(),
pt.getTimeStamp(), pt.getParentID(),
pt.getCategory(), pt.getLastUpdated(),
pt.getReply(), pt.getClick(), pt.getRepliedThreadID() );
threads.add(t);
}
request.setAttribute(ForumConstants.THREADS_COLLECTION_KEY, threads);
} catch (SQLException sqle) {
sqle.printStackTrace();
return (mapping.findForward("error"));
} catch (ThreadNotFoundException tnfe) {
tnfe.printStackTrace();
return (mapping.findForward("error"));
}
// Report any errors we have discovered back to the original form
if (!errors.empty()) {
saveErrors(request, errors);
}
// Forward control to the specified success URI
return (mapping.findForward("success"));
}
}//EOC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -