?? adminactionbase.java
字號:
/*
* AdminActionBase.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.util.Iterator;
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 org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import com.liusoft.dlog4j.formbean.FormBean;
/**
* 必須是站長才能執行的方法 該類實現了統一判斷是否具有站長的權限
*
* @author Winter Lau
*/
public abstract class AdminActionBase extends ActionBase {
/**
* 返回不需要經過管理員權限驗證的方法名
* @return
*/
protected String[] methodsIgnore(){
return null;
}
/*
* 判斷當前操作用戶是否擁有站長的權限
*
* @see com.liusoft.dlog4j.action.ActionBase#execute(org.apache.struts.action.ActionMapping,
* org.apache.struts.action.ActionForm,
* javax.servlet.http.HttpServletRequest,
* javax.servlet.http.HttpServletResponse)
*/
protected ActionForward beforeExecute(ActionMapping mapping, ActionForm form,
HttpServletRequest req, HttpServletResponse res) throws Exception
{
if(needVerify(req)){
FormBean fbean = (FormBean)form;
ActionMessages msgs = validateSiteOwner(req, res, fbean);
if(!msgs.isEmpty()){
Iterator iter = msgs.get();
String msg = null;
if(iter.hasNext()){
ActionMessage am = (ActionMessage)iter.next();
msg = super.getMessage(req, null, am.getKey());
}
String page = (fbean != null) ? fbean.getFromPage() : (req
.getContextPath() + "/index.vm");
return msgbox(mapping,form,req,res,msg,page);
}
}
//否則繼續父類的處理方法
return null;
}
/**
* 判斷當前請求是否需要進行管理員的權限判斷
* @param req
* @return
*/
private final boolean needVerify(HttpServletRequest req){
String[] methods = methodsIgnore();
for(int i=0;methods!=null&&i<methods.length;i++){
String m_name = SUBMIT_BUTTON_PREFIX + methods[i];
if(req.getParameter(m_name)!=null)
return false;
}
return true;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -