?? pubaction.java
字號:
package com.elan.forum.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.elan.forum.actions.util.ForumRole;
import com.elan.forum.elf.El;
/*對moduleId,
* pieceId,
* topicId
* action
* position
* TopicSessionContainer
* Check Session
* Check Admin
* 進行的相關INIT操作和給出get/set方法
*
* 子類需要實現executeAction方法,實現邏輯操作
*
*
*/
public abstract class PubAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
/*HttpSession session = null;
El el = null;
String action = request.getParameter("action");
String currentRequestUrl = null;
Integer moduleId = null;
Integer pieceId = null;
Integer topicId = null;*/
//初始化一下對象
/*init(request, session, el, currentRequestUrl, action, moduleId,
pieceId, topicId);*/
if (!processPreprocess(mapping, form, request, response)) {
return null;
}
//構造position字符竄應該放到其子類的實例中去構造,即葉子類圖的葉子節點
return executeAction(mapping, form, request, response);
}
protected abstract ActionForward executeAction(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) ;
protected boolean processPreprocess(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// 擴散函數,比如修改一些屬性
return true;
}
protected boolean checkIsLogin(HttpServletRequest request) {
if (!ForumRole.CheckIsLogin(request)) {
this.setPosition(request);
return false;
}
return true;
}
/**
* 設置上一次的URL
* @param request
*/
protected void setPosition(HttpServletRequest request) {
String queryString = request.getQueryString();
request.setAttribute("url", this.getCurrentRequestUrl(request) + (queryString.trim().length() > 0 ? ("?" + queryString) : ""));
System.out.println("url:" + request.getAttribute("url"));
}
protected HttpSession getSession(HttpServletRequest request) {
return request.getSession();
}
@SuppressWarnings("unused")
protected HttpSession getSession(HttpServletRequest request, boolean b) {
return request.getSession(b);
}
protected String getAction(HttpServletRequest request) {
String action = request.getParameter("action");
if (request.getAttribute("action") != null) {
action = (String) request.getAttribute("action");
}
request.setAttribute("action", action);
return action;
}
protected Integer getModuleId(HttpServletRequest request) {
String moduleIdStrPt = request.getParameter("moduleId");
Integer moduleIdStrRq = (Integer) request.getAttribute("moduleId");
String moduleIdStrSs = (String) getSession(request).getAttribute(
"moduleId");
Integer moduleId = null;
try {
if(moduleIdStrPt != null && !"".equals(moduleIdStrPt)) {
moduleId = Integer.valueOf(moduleIdStrPt);
}
if (moduleIdStrRq != null) {
moduleId = Integer.valueOf(moduleIdStrRq);
}
if (moduleIdStrSs != null && !"".equals(moduleIdStrRq)) {
moduleId = Integer.valueOf(moduleIdStrSs);
}
} catch (NumberFormatException nfe) {
throw nfe;
}
return moduleId;
}
protected Integer getPieceId(HttpServletRequest request) {
String pieceIdStrPt = request.getParameter("pieceId");
Integer pieceIdStrRq = (Integer) request.getAttribute("pieceId");
String pieceIdStrSs = (String) getSession(request).getAttribute(
"pieceId");
Integer pieceId = null;
try {
if(pieceIdStrPt != null && !"".equals(pieceIdStrPt)) {
pieceId = Integer.valueOf(pieceIdStrPt);
}
if(pieceIdStrRq != null) {
pieceId = Integer.valueOf(pieceIdStrRq);
}
if (pieceIdStrSs != null && !"".equals(pieceIdStrRq)) {
pieceId = Integer.valueOf(pieceIdStrSs);
}
} catch (NumberFormatException nfe) {
throw nfe;
}
return pieceId;
}
protected Integer getTopicId(HttpServletRequest request) {
String topicIdStrPt = request.getParameter("topicId");
Integer topicIdStrRq = (Integer) request.getAttribute("topicId");
String topicIdStrSs = (String) getSession(request).getAttribute(
"topicId");
Integer topicId = null;
try {
if(topicIdStrPt != null && !"".equals(topicIdStrPt)) {
topicId = Integer.valueOf(topicIdStrPt);
} else if(topicIdStrRq != null) {
topicId = Integer.valueOf(topicIdStrRq);
} else if (topicIdStrSs != null && !"".equals(topicIdStrRq)) {
topicId = Integer.valueOf(topicIdStrSs);
}
} catch (NumberFormatException nfe) {
throw nfe;
}
return topicId;
}
private String getCurrentRequestUrl(HttpServletRequest request) {
return request.getRequestURI();
}
/*protected void init(HttpServletRequest request, HttpSession session, El el,
String action, String currentRequestUrl,
Integer moduleId, Integer pieceId, Integer topicId) {
el = El.getEl();
session = getSession(request);
currentRequestUrl = request.getRequestURI();
action = this.getAction(request);
moduleId = this.getModuleId(request);
pieceId = this.getPieceId(request);
topicId = this.getTopicId(request);
}*/
protected void setAttribute(HttpServletRequest request,String name, Object value) {
request.setAttribute(name, value);
}
protected void setAttribute(HttpSession session,String name, Object value) {
session.setAttribute(name, value);
}
protected Integer getAuthorId(HttpServletRequest request) {
String authorId = null;
authorId = request.getParameter("authorId");
if(null != request.getAttribute("authorId")) {
authorId = (String) request.getAttribute("authorId");
}
if(authorId != null) {
return Integer.valueOf(authorId) < 1 ? null : Integer.valueOf(authorId);
}
return null;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -