📄 topicbaseaction.java
字号:
package com.elan.forum.actions.topic;
import java.sql.Timestamp;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.elan.forum.actions.PubAction;
import com.elan.forum.util.Constents;
/**
* @author Elan
*
*/
public abstract class TopicBaseAction extends PubAction {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return super.execute(mapping, form, request, response);
}
protected ActionForward executeAction(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
String action = this.getAction(request);
System.out.println(action);
if ("showTopic".equals(action)) {
return showTopic(mapping, form, request, response);
} else if ("showPiece".equals(action)) {
return showPiece(mapping, form, request, response);
} else if ("replyTopic".equals(action)) {
if (!checkIsLogin(request)) {
return (mapping.findForward("userLogin"));
}
return replyTopic(mapping, form, request, response);
} else if ("replyForm".equals(action)) {
if (!checkIsLogin(request)) {
//System.out.println("用户没有登陆的啦");
return (mapping.findForward("userLogin"));
}
return replyForm(mapping, form, request, response);
} else if ("newForm".equals(action)) {
System.out.println("进入NEWFORM");
if (!checkIsLogin(request)) {
System.out.println("在一次111111111111111");
return (mapping.findForward("userLogin"));
}
return newForm(mapping, form, request, response);
} else if ("newTopic".equals(action)) {
if (!checkIsLogin(request)) {
return (mapping.findForward("userLogin"));
}
return newTopic(mapping, form, request, response);
} else if("quote".equals(action)) {
if (!checkIsLogin(request)) {
return (mapping.findForward("userLogin"));
}
return quoteReply(mapping, form, request, response);
} else if("hotTopic".equals(action)) {
return this.hotTopic(mapping, form, request, response);
} else if("newPostTopic".equals(action)) {
return this.newPostTopic(mapping, form, request, response);
} else if("search".equals(action)) {
return this.search(mapping, form, request, response);
} else if("essence".equals(action)) {
return this.essence(mapping, form, request, response);
}
return null;
}
protected abstract ActionForward essence(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response);
protected abstract ActionForward search(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response);
protected abstract ActionForward newPostTopic(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response);
protected abstract ActionForward hotTopic(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response);
protected abstract ActionForward quoteReply(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response);
protected abstract ActionForward replyTopic(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response);
protected abstract ActionForward replyForm(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response);
protected abstract ActionForward newTopic(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response);
protected abstract ActionForward newForm(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response);
protected abstract ActionForward showPiece(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response);
protected abstract ActionForward showTopic(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response);
// ///////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////
/**
* 只限制论坛用的
* @param request
* @param pieceId
* @param pieceName
* @param topicId
* @param topicTile
* @return String
*
*/
protected String constructPosition(HttpServletRequest request,
Integer pieceId, String pieceName, Integer topicId, String topicTile) {
StringBuffer strPath = new StringBuffer();
if (pieceId != null && pieceName != null) {
// 构造pieceStr
strPath.append("<a href=\"").append(Constents.CONTEXTPATH).append(
"/forum/topic.do?action=showPiece&pieceId=")
.append(pieceId).append("\">").append(pieceName).append(
"</a>>>");
}
if (topicId != null && topicTile != null) {
// 构造文章路径
strPath.append("<a href=\"").append(Constents.CONTEXTPATH).append(
"/forum/topic.do?action=showTopic&topicId=")
.append(topicId).append("\">").append(topicTile).append(
"</a>");
}
return strPath.toString();
}
// 通用方法
/**
*
* key: url
* value: 连接字符
* @param map
* @return String
*/
protected String construtctPostion(Map<String, String> map) {
StringBuffer strPath = new StringBuffer();
String[] key = (String[]) map.keySet().toArray();
String[] values = (String[]) map.values().toArray();
for (int i = 0; i < map.size(); i++) {
strPath.append("<a href=\"").append(key[i]).append(">").append(
values[i]).append("</a>>>");
}
return strPath.toString();
}
protected Integer getPage(HttpServletRequest request) throws RuntimeException {
Integer temp = new Integer(1);
String tempStr = request.getParameter("page");
if(tempStr != null) {
try {
temp = Integer.valueOf(tempStr);
} catch (RuntimeException re) {
throw re;
}
}
return temp;
}
/**
* sign: 1返回的是requet startYear
* sign: 2返回的是requet endYear
* @param request
* @param sign
* @return
*/
protected Timestamp createTimestamp(HttpServletRequest request, int sign ) {
Timestamp ts = new Timestamp(System.currentTimeMillis());
Integer year = 2008;
Integer month = 1;
Integer day = 1;
if(1 == sign) {
year = Integer.valueOf(request.getParameter("startYear"));
month = Integer.valueOf(request.getParameter("startMonth"));
day = Integer.valueOf(request.getParameter("startDay"));
} else {
year = Integer.valueOf(request.getParameter("endYear"));
month = Integer.valueOf(request.getParameter("endMonth"));
day = Integer.valueOf(request.getParameter("endDay"));
}
ts.setYear(year - 1900);
ts.setMonth(month);
ts.setDate(day);
return ts;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -