對天乙社區bbscs8實現的詳細分析二十一

我們選擇一幅圖片,就觸發了previewPic('upload'),它在photoview處顯示了圖片:
function previewPic(upfilename){              //過濾功能!!!
window.parent.upIframeSize();
var upfile = document.getElementById(upfilename);
if (upfile != "") {
    var extname = getExtName(upfile.value);
    if(extname != "jpg" && extname != "gif" && extname != "jpeg"){
      upfile.value = "";
      alert("<s:text name="face.jpggif"/>"); //不是圖片
    }else{
      preViewPic('photoview', null, upfile.value, 0, null, 0, 120);
    }
}
}

//圖片預覽
function preViewPic(picDivName,imgName,fn,iBorder,iBorderColor,iWidth,iHeight){
    //var picdiv=document.all(picDivName);
    var picdiv = document.getElementById(picDivName);
    if(picdiv != null && fn != null && fn!=''){
      if(imgName ==null) imgName = "picname";
      if(iBorder == null) iBorder=0;
      if(iBorderColor == null) iBorderColor="#CCCCCC";
      var strw,strh
      if(iWidth == null || iWidth == 0) strw = "";
      else strw = " width="+iWidth+" ";
      if(iHeight == null || iHeight == 0) strh = "";
      else strh = " height=" + iHeight + " ";
      picdiv.innerHTML="<img name='"+imgName+"' alt='預覽狀態...' "+strw+strh+" border="+iBorder+
            " src='"+fn+"' style='border-color:"+iBorderColor+"'>";
      document.focus();
    }
}
當我們點擊上傳頭像時,觸發了/useFace?action=up~~~~當然不是get,而是post方法了哦~
public String up() {
// System.out.println(this.getUpload());用於測試
// System.out.println(this.getUploadFileName());
if (this.getUpload() == null || StringUtils.isBlank(this.getUploadFileName())) {
   this.setAjaxCodeid("1");
   this.setAjaxMsg(this.getText("error.userupimg.null"));
   return "userFaceUpComponent";
}
if (!BBSCSUtil.isAllowPicFile(this.getUploadFileName()) || this.getUpload().length() == 0
    || this.getUpload().length() > this.getSysConfig().getFaceSize() * 1024) {//大於50K
   this.setAjaxCodeid("2");
   this.setAjaxMsg(this.getText("error.userupimg.upnotice", new String[] { String.valueOf(this.getSysConfig()
     .getFaceSize()) }));
   return "userFaceUpComponent";
}
UserInfo ui = this.getUserService().findUserInfoById(this.getUserSession().getId());
if (ui == null) {//用於不存在
   this.setAjaxCodeid("3");
   this.setAjaxMsg(this.getText("error.userupimg.uperror"));
}
String distFileName = ui.getId() + System.currentTimeMillis() + "."
    + FilenameUtils.getExtension(this.getUploadFileName());
try {
   this.getUserService().createUserFacePic(ui, distFileName, new FileInputStream(this.getUpload()));//注意this.getUpload...
/**
private File upload;
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
*/
   this.setAjaxCodeid("0");
   this.setAjaxMsg(this.getText("userupimg.up.ok"));
} catch (FileNotFoundException ex) {
   this.setAjaxCodeid("3");
   this.setAjaxMsg(this.getText("error.userupimg.uperror"));
} catch (BbscsException ex) {
   this.setAjaxCodeid("4");
   this.setAjaxMsg(this.getText("error.userupimg.uperror"));
}
return "userFaceUpComponent";
}
我們看我們在iframe中的提交爲什麼能更新上面框架的內容,我們看userFaceUpComponent:
<%@page contentType="text/html; charset=UTF-8"%>
<%@taglib uri="/WEB-INF/struts-tags.tld" prefix="s"%>
<script language="JavaScript" type="text/javascript">
window.parent.OnUploadCompleted("<s:property value="%{ajaxCodeid}"/>","<s:property value="%{ajaxMsg}"/>");
</script>
哦,這裏觸發了上層的js:
function OnUploadCompleted(codeid,msg){
var objif = document.getElementById('upfileIframe');
objif.height = 120;
objif.src= getActionMappingURL("/userFace?action=uppage"); //還原爲原來的樣子!
if (codeid == "0") {
    //alert(msg);
    userFaceShow();
}
if (codeid == "1") {
    alert(msg); //提示錯誤信息
}
if (codeid == "2") {
    alert(msg);
}
if (codeid == "3") {
    alert(msg);
}
if (codeid == "4") {
    alert(msg);
}
}
function userFaceShow() { //顯示出來!
$('userFaceDiv').innerHTML = pageLoadingCenter;
var userId = "<s:property value="%{userSession.id}"/>";
var urls = getActionMappingURL("/userFace");
var pars = "action=showface&ajax=shtml&userId=" + userId;
var myAjax = new Ajax.Updater("userFaceDiv", urls, {method: 'get', parameters: pars});
}
-->
public String showface() {
this.setUserId(this.getUserSession().getId());
return "showface";
}
看下showFace.jsp:
<%
request.setAttribute("decorator", "none");
response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
<bbscs:face value="%{userId}"/>
對於刪除功能我們不再加以分析!
我們看userDetailSet.bbscs?action=index:
<action name="userDetailSet" class="userDetailSetAction">
   <interceptor-ref name="mainUserAuthInterceptorStack"></interceptor-ref>
   <interceptor-ref name="remoteAddrInterceptor"></interceptor-ref>
   <result name="input">/WEB-INF/jsp/userDetailSet.jsp</result>//注意這裏是input
</action>
十分簡單哦我們看index方法中關鍵的代碼:
UserInfo ui = this.getUserService().findUserInfoById(this.getUserSession().getId());
if (ui == null) {
   this.addActionError(this.getText("error.user.noexist"));
   return ERROR;
}
setRadioSexListValues();
/**
List<RadioInt> radioSexList = new ArrayList<RadioInt>();

private void setRadioSexListValues() {
radioSexList.add(new RadioInt(1, this.getText("bbscs.man")));
radioSexList.add(new RadioInt(2, this.getText("bbscs.woman")));
}
*/
this.setAction("edit");//action!
this.setBirthDay(ui.getBirthDay());
this.setBirthMonth(ui.getBirthMonth());
this.setBirthYear(String.valueOf(ui.getBirthYear()));
另外,值得注意的是這個action類中還有一些yearValues,monthValues,dayValues:
private List<OptionsString> yearValues = Constant.YEARS;
private List<OptionsInt> monthValues = Constant.MONTH;
private List<OptionsInt> dayValues = Constant.DAY;
-->
public static List<OptionsString> YEARS = new ArrayList<OptionsString>();//OptionString!
public static List<OptionsInt> MONTH = new ArrayList<OptionsInt>();
public static List<OptionsInt> DAY = new ArrayList<OptionsInt>();
我們看userDetailSet.jsp:
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
    <td>
      <s:actionerror theme="bbscs0"/>
    </td>
</tr>
<tr>
    <td>
      <s:actionmessage theme="bbscs0"/> //顯示數據更新成功的提示!
    </td>
</tr>
</table>
我們在template.bbscs0中找到actionmessage.ftl:
<#if (actionMessages?exists && actionMessages?size > 0)>
<div class="msg3">
<#list actionMessages as message>
   <span class="actionMessage">${message}</span><br/>
</#list>
</div>
</#if>

<td class="bgColor2">
          <s:select list="yearValues" name="birthYear" id="birthYear" cssClass="select1" listKey="key" listValue="value"></s:select>
          <s:text name="bbscs.year"/>
          <s:select list="monthValues" name="birthMonth" id="birthMonth" cssClass="select1" listKey="key" listValue="value"></s:select>
          <s:text name="bbscs.mon"/>
          <s:select list="dayValues" name="birthDay" id="birthDay" cssClass="select1" listKey="key" listValue="value"></s:select>
          <s:text name="bbscs.day"/>
        </td>
對應年月日的顯示!注意這個頁面的修改提交沒用ajax!
好,我們看最後一個個人中心的設置了:boardSaveManage.bbscs
<action name="boardSaveManage" class="boardSaveManageAction">
   <interceptor-ref name="mainUserAuthInterceptorStack"></interceptor-ref>
   <result name="success">/WEB-INF/jsp/boardSaveManage.jsp</result>
   <result name="list" type="redirect-action">boardSaveManage?action=index</result>
</action>
進入index方法中:
public String index() {
this.setAction("dels");
List bslist = this.getBoardSaveService().findBoardSavesByUid(this.getUserSession().getId());
this.setBoardList(this.getBoardService().findBoardsInIDs(this.getBoardIds(bslist)));
return SUCCESS;
}
==>private List getBoardIds(List bslist) {
List<Long> blist = new ArrayList<Long>();
for (int i = 0; i < bslist.size(); i++) {
   BoardSave bs = (BoardSave) bslist.get(i);
   blist.add(new Long(bs.getBoardID()));//將BoardID寫入到blist中!
}
return blist;
}
而boardSaveManage.jsp遍歷結果加以顯示出來!
<td valign="middle" class="bgColor4">
          <div align="center">
            <input type="checkbox" name="ids" value="<s:property value="#b.id"/>"/>
          </div>
        </td>
<td colspan="4" class="bgColor4">
          <s:submit cssClass="button1" value="%{getText('bbscs.del')}"></s:submit>
        </td>
這個是刪除功能:/boardSaveManage?action=dels:
public String dels() {
if (this.getIds() == null || this.getIds().isEmpty()) {
   this.addActionError(this.getText("error.parametererror"));
   return ERROR;
}
try {
   this.getBoardSaveService().removeBoardSaveByBidsUid(this.getUserSession().getId(), this.getIds());
   return "list";
} catch (BbscsException e) {
   logger.error(e);
   this.addActionError(this.getText("error.boardsave.del"));
   return ERROR;
}
}
OK!十分簡單!我們看logout.bbscs先!
<action name="logout" class="logoutAction">
      <interceptor-ref name="defaultStack"></interceptor-ref>
   <interceptor-ref name="userLoginInterceptor"></interceptor-ref>
   <interceptor-ref name="userSessionInterceptor"></interceptor-ref>
   <interceptor-ref name="requestBasePathInterceptor"></interceptor-ref>
   <result name="success" type="redirect">${logoutUrl}</result>
</action>
它是在main package中的,但它繼承了BaseAction,實現了UserSessionAware, RequestBasePathAware, SessionAware,好我們看其execute方法:
public String execute() {
UserOnline uo = this.getUserOnlineService().findUserOnlineByUserID(userSession.getId());
if (uo != null) {
   try {
    this.getUserOnlineService().removeUserOnline(uo);
   } catch (BbscsException e) {
    logger.error(e);
   }
}
this.getSession().remove(Constant.USER_SESSION_KEY);
userCookie.removeAllCookies();

if (StringUtils.isNotBlank(this.getAction()) && this.getAction().equalsIgnoreCase("pass")) {
   userCookie.removePassCookies();
}

if (StringUtils.isBlank(this.getSysConfig().getLogoutUrl())
    || this.getSysConfig().getLogoutUrl().startsWith("/")) {
   String url = this.getSysConfig().getLogoutUrl().substring(1, this.getSysConfig().getLogoutUrl().length());
   url = BBSCSUtil.getActionMappingURLWithoutPrefix(url);

   this.setLogoutUrl(this.basePath + url);//logout url!
} else {
   this.setLogoutUrl(this.getSysConfig().getLogoutUrl());
}
return SUCCESS;
}
在首頁中,我們先分析在線online.bbscs?action=user及online.bbscs?action=friend:
<action name="online" class="onlineAction">
   <interceptor-ref name="mainUserAuthInterceptorStack"></interceptor-ref>
   <result name="success">/WEB-INF/jsp/onlineList.jsp</result>
</action>
在Online.java中:
public String user() {
long atime = this.getTime();
/**
private long getTime() {
return System.currentTimeMillis() - (this.getSysConfig().getUserOnlineTime() * 1000);
}
*/
this.setOnlineList(this.getUserOnlineService().findUserOnlines(atime, 0, 0, Constant.NORMAL_USER_GROUPS));//普通用戶組"from UserOnline where onlineTime >= ?";
/**Criteria c = s.createCriteria(UserOnline.class);
        c.add(Restrictions.ge("onlineTime", new Long(atime)));
        if (boardID != 0) {
          c.add(Restrictions.eq("boardID", new Long(boardID)));
        }
        if (hiddenUser != -1) {
          c.add(Restrictions.eq("hiddenUser", new Integer(hiddenUser)));
        }
        if (groups != null && !groups.isEmpty()) {
          c.add(Restrictions.in("userGroupID", groups));
        }
        return c.list();
*/
return SUCCESS;
}
另外一個:action=friend
public String friend() {
long atime = this.getTime();
this.setOnlineList(this.getUserOnlineService().findUserOnlinesInIds(atime,
    this.getFriendService().fileToFriendIDs(this.getUserSession().getId()), 0, 0,
    Constant.NORMAL_USER_GROUPS));
/**
public List fileToFriendIDs(String ownId) {
    List<String> l = new ArrayList<String>();
    File fromFile = new File(this.getUserConfig().getUserFilePath(ownId) + Constant.USER_FRIEND_FILE);//public static final String USER_FRIEND_FILE = "UserFriendFile.txt";
    try {
String fids = FileUtils.readFileToString(fromFile, Constant.CHARSET);
String[] ids = fids.split(",");
if (ids != null) {
    for (int i = 0; i < ids.length; i++) {
      //System.out.println(ids[i]);
      l.add(ids[i]);
    }
}
} catch (IOException e) {
logger.error(e);
}
    return l;
}
*/
return SUCCESS;
}
OK!對於用戶信息的顯示也有兩類:我們先看URL:http://bbs.laoer.com/userInfo.bbscs?action=name&username=laoer以及http://bbs.laoer.com/userInfo.bbscs?action=id&id=4028818208ed006b0108ed020bd50001
進入userInfo:
<action name="userInfo" class="userInfoAction">
   <interceptor-ref name="mainUserAuthInterceptorStack"></interceptor-ref>
   <result name="success">/WEB-INF/jsp/showUserInfo.jsp</result>
   <result name="bookMarkInUserInfo">/WEB-INF/jsp/bookMarkInUserInfo.jsp</result>
</action>
我們直接看代碼:
public String name() {
this.ui = this.getUserService().findUserInfoByUserName(this.getUsername());
if (this.ui == null) {
   this.addActionError(this.getText("error.user.noexist"));
   return ERROR;
}

this.setUserDetail(ui.getUserDetail());

Pages pages = new Pages();
pages.setPage(1);
pages.setPerPageNum(10);
pages.setTotalNum(10);

PageList pl = this.getForumService().findForumsOwner(ui.getId(), 1, pages);//isNew=1代表主貼
this.setOwnMainList(pl.getObjectList());

pages = new Pages();
pages.setPage(1);
pages.setPerPageNum(10);
pages.setTotalNum(10);

pl = this.getForumService().findForumsOwner(ui.getId(), 0, pages);//0代表回覆
this.setOwnReList(pl.getObjectList());

return SUCCESS;
}
id方法類似,注意其中的一段:
ui.getUserDetail().setBrief(BBSCSUtil.filterText(ui.getUserDetail().getBrief(), false, false, true));
另外,有個bookMark方法,它是用於找到用戶的共享bookMark!
public String bookmark() {
Pages pages = new Pages();
pages.setPage(this.getPage());
pages.setPerPageNum(10);
pages.setFileName(BBSCSUtil.getActionMappingURLWithoutPrefix("userInfo?action=" + this.getAction() + "&id="
    + this.getId() + "&ajax=shtml"));
this.setPageList(this.getBookMarkService().findBookMarksByUserIDShare(this.getId(), 1, pages));//PageList設置了哦~~
return "bookMarkInUserInfo";
}
我們先看bookMarkInUserInfo.jsp:
<s:iterator value="%{pageList.objectList}" id="bookMark">

      <tr>
        <td class="bgColor4">
          <span class="font1">
            <a href="<s:property value="#bookMark.url"/>" title="<s:property value="#bookMark.alt"/>" target="_blank"><s:property value="#bookMark.bookMarkName"/></a>
          </span>
        </td>
      </tr>
      </s:iterator>
      <tr>
        <td class="bgColor3"><s:text name="bbscs.pagebreak"/>:<bbscs:pages value="%{pageList.pages}" javaScript="loadBookMarkListPageUrl"/></td>
      </tr>
-->
function loadBookMarkListPageUrl(url) {   //注意這個函數是在showUserInfo.jsp中的
$('bookMarkListDiv').innerHTML = pageLoadingCenter;
var urls = getActionName(url);
var pars = getActionPars(url);
var myAjax = new Ajax.Updater("bookMarkListDiv", urls, {method: 'get', parameters: pars});
}
好,我們進而分析showUserInfo.jsp它的body onload="loadBookMarkListPage();"
var userid = "<s:property value="%{ui.id}"/>";
function loadBookMarkListPage() {
$('bookMarkListDiv').innerHTML = pageLoadingCenter;
var urls = getActionMappingURL("/userInfo");
var pars = "action=bookmark&ajax=shtml&id="+userid;
var myAjax = new Ajax.Updater("bookMarkListDiv", urls, {method: 'get', parameters: pars});
}
我們注意到,在用戶信息頁面上還有一個給該用戶留言功能,這個功能點擊後將顯示一個div,它與前面的note類似!因此這個文件<script type="text/javascript" src="js/note.js"></script>還有<div id="noteSendDiv"></div>用戶提供界面的顯示哦~
OK!我們將分析下關鍵的forum-index-15.index(或froum?action=index&bid=15),我們還是從struts.xml文件中看起吧。在struts.xml中,專門定義了用於整個forum package!
<package name="forum" extends="bbscs-default" namespace="/">
<default-interceptor-ref name="boardInterceptorStack"></default-interceptor-ref>
<action name="forum" class="forumAction">
   <interceptor-ref name="boardInterceptorStack"></interceptor-ref>
   <interceptor-ref name="requestBasePathInterceptor"></interceptor-ref>
   <result name="forumBoard">/WEB-INF/jsp/forumBoard.jsp</result>
   <result name="forum">/WEB-INF/jsp/forum.jsp</result>
   <result name="forumHistory">/WEB-INF/jsp/forumHistory.jsp</result>
</action>
....
我們先看boardInterceptorStack:
<interceptor-stack name="boardInterceptorStack">
    <interceptor-ref name="defaultStack"></interceptor-ref>
    <interceptor-ref name="userLoginInterceptor"></interceptor-ref>
    <interceptor-ref name="userOnlineInterceptor"></interceptor-ref>
    <interceptor-ref name="boardInterceptor"></interceptor-ref>
   </interceptor-stack>
注意到它沒有了userSessionInterceptor以及userPermissionInterceptor這兩個權限檢查的功能了!而增加了一個boardInterceptor,我們可以到com.laoer.bbscs.web.interceptor中找到這個攔截器,這個攔截器在進入版區之前就會進行調用,首先根據action提供的ajax,action,bid等值進入判斷參數是否充分!如bid==0是不正確的,還有就是根據bid找到版區,沒有的話,也報錯!我們可在url分別輸入http://bbs.laoer.com/forum.bbscs?action=index&bid=100&ajax=shtml 沒有格式輸出
http://bbs.laoer.com/forum.bbscs?action=index&bid=100&ajax=html 有html格式
http://bbs.laoer.com/forum.bbscs?action=index&bid=100 //用默認的String ajax = "html";
進行對比,就知道顯示效果了!
   if (action instanceof BoardAware) {
    ((BoardAware) action).setBoard(board);

   }
接下來:
if (us.getBid() != bid) {
    us.getBoardPermission().clear();
    us.getBoardSpecialPermission().clear();

    us.setBid(bid); //將bid寫入us
    us.setBoardPass("");
    Map[] maps = boardService.getBoardPermission(bid, us.getGroupID()); // 取得版區用戶組權限

    us.setBoardPermissionArray(maps);//寫入權限!

    BoardMaster bm = (BoardMaster) board.getBoardMaster().get(us.getUserName());
    if (bm != null) {// 是斑竹
     Map[] bmpMap = boardService.getBoardMasterPermission(bm.getRoleID()); // 取得斑竹權限
     us.setBoardPermissionArray(bmpMap);
    }

    for (int i = 0; i < board.getParentIDs().size(); i++) {
     Board pboard = boardService.getBoardByID(((Long) (board.getParentIDs().get(i))).longValue());
     BoardMaster pbm = (BoardMaster) pboard.getBoardMaster().get(us.getUserName());//上級的權限!
     if (pbm != null && pbm.getOverChildPurview() == 1) {
      Map[] bmpMap = boardService.getBoardMasterPermission(pbm.getRoleID()); // 取得斑竹權限
      us.setBoardPermissionArray(bmpMap);
     }
    }
ac.getSession().put(Constant.USER_SESSION_KEY, us);
UserOnlineService userOnlineService = (UserOnlineService) wc.getBean("userOnlineService");

    UserOnline uo = userOnlineService.findUserOnlineByUserID(us.getId()); // 取得用戶在線信息
    if (uo != null) {
     uo.setAtPlace(board.getBoardName());
     uo.setBoardID(bid);
     try {
      userOnlineService.saveUserOnline(uo);
     } catch (BbscsException ex) {
      logger.error(ex);
     }
    }

   }
if (board.getNeedPasswd() == 1 && StringUtils.isNotBlank(board.getPasswd())) {// 版區需要密碼訪問
    if (!us.isHaveBoardSpecialPermission(Constant.SPERMISSION_INBOARD_NOT_NEEDPASSWD)) {
     if (StringUtils.isBlank(us.getBoardPass())) {
      return "boardPasswd";
     } else if (!(bid + ":" + board.getPasswd()).equals(us.getBoardPass())) {//訪問密碼不對的話!
      // 版區需要密碼,需要跳轉
      ((ActionSupport) action).addActionError(messageSource.getMessage("error.board.passwd", null, ac
        .getLocale()));
      return "boardPasswd";
     }
    }
   }
這裏有個<result name="boardPasswd">/WEB-INF/jsp/boardPasswd.jsp</result>
<s:form action="boardPasswd">
<s:hidden name="action" value="pass"></s:hidden>
<s:hidden name="bid" value="%{bid}"></s:hidden>
....
注意到struts.xml中boardPasswd是個special package中的一個action:
<package name="special" extends="bbscs-default" namespace="/">
     <action name="boardPasswd" class="boardPasswdAction">
   <interceptor-ref name="userSessionInterceptorStack"></interceptor-ref>
   <interceptor-ref name="requestBasePathInterceptor"></interceptor-ref>
   <result name="success" type="redirect">${forwardUrl}</result>
</action>
</package>
我們看boardPasswd這個action中的pass方法:
public String pass() {
if (StringUtils.isBlank(this.getPasswd())) {
   this.addActionError(this.getText("error.nullerror"));
   return "boardPasswd";
}
this.getUserSession().setBoardPass(this.getBid() + ":" + this.getPasswd());
this.setForwardUrl(this.getBasePath()
    + BBSCSUtil.getActionMappingURLWithoutPrefix("forum?action=index&bid=" + this.getBid()));
return SUCCESS;
}
回過頭來!
if (board.getIsAuth() == 1) {// 版區需要授權訪問
    BoardMaster bm = (BoardMaster) board.getBoardMaster().get(us.getUserName());
    if (bm == null && !us.isHaveBoardSpecialPermission(Constant.SPERMISSION_INBOARD_NOT_NEEDAUTH)) { // 不是斑竹,並且沒有不需要授權就可以進入的權限
     // 版區需要授權
     BoardAuthUserService boardAuthUserService = (BoardAuthUserService) wc
       .getBean("boardAuthUserService");
     if (boardAuthUserService.findBoardAuthUserByBidUid(bid, us.getId()) == null) {
      // 不是授權用戶,需要跳轉
      String errorMsg = messageSource.getMessage("error.user.not.auth", null, ac.getLocale());
      if (ajax.equalsIgnoreCase("html")) {
       ac.getValueStack().set("interceptError", errorMsg);
       return "intercepthtml";
      } else if (ajax.equalsIgnoreCase("shtml")) {
       ac.getValueStack().set("interceptError", errorMsg);
       return "interceptshtml";
      } else {
       AjaxMessagesJson ajaxMessagesJson = (AjaxMessagesJson) wc.getBean("ajaxMessagesJson");
       ajaxMessagesJson.setMessage("E_BOARDID_AUTH", errorMsg);
       ac.getValueStack().set("ajaxMessagesJson", ajaxMessagesJson);
       return "ajaxjson";
      }
     }
    }
   }

   boolean havePermission = false;
   Permission permission = (Permission) us.getBoardPermission().get(actionName + "?action=*");//具體地權限對比一下!
   if (permission != null) {
    havePermission = true;
   } else {
    permission = (Permission) us.getBoardPermission().get(actionName + "?action=" + saction);
    if (permission != null) {
     havePermission = true;
    } else {
     havePermission = false;
    }
   }
   if (havePermission) {
    if (action instanceof BoardAware) {
     ((BoardAware) action).setUserCookie(userCookie);
     ((BoardAware) action).setUserSession(us);
    }
    return invocation.invoke();
最後我們來看看BoardAware:
public interface BoardAware {
public void setBoard(Board board);
public void setUserCookie(UserCookie userCookie);
public void setUserSession(UserSession userSession);//其實也和session cookie有關係了!
}
好,我們看forum.bbscs,注意它是從BaseBoardAction繼承過來的,也實現了RequestBasePathAware方法,我們先看BaseBoardAction:public class BaseBoardAction extends BaseAction implements BoardAware,也要注意到它有以下屬性和execute方法(這個和BaseMainAction一樣):
private Board board;
private UserCookie userCookie;
private UserSession userSession;
private long bid = 0;
private String tagId = "0";
public String execute() {
try {
   return this.executeMethod(this.getAction());
} catch (Exception e) {
   logger.error(e);
   return ERROR;
}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章