adminboardtag.java

来自「一个jsp写的bbs」· Java 代码 · 共 176 行

JAVA
176
字号
package com.laoer.bbscs.web.action;

import java.util.*;
import javax.servlet.http.*;

import org.apache.commons.lang.*;
import org.apache.struts.action.*;
import com.laoer.bbscs.bean.*;
import com.laoer.bbscs.comm.*;
import com.laoer.bbscs.service.*;
import org.apache.struts.util.MessageResources;
import com.laoer.bbscs.exception.BbscsException;

public class AdminBoardTag
    extends AdminBaseAction {

  private BoardService boardService;

  private AjaxMessagesXML ajaxMessagesXML;

  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                               HttpServletResponse response) {
    DynaActionForm dynaActionForm = (DynaActionForm) form;
    String action = (String) dynaActionForm.get("action");
    long bid = ( (Long) dynaActionForm.get("bid")).longValue();
    if (action.equalsIgnoreCase("list")) {
      Board b = this.getBoardService().getBoardByID(bid);
      Set tags = b.getBoardTag();
      request.setAttribute("tags", tags);
      request.setAttribute("bid", new Long(bid));

      return mapping.findForward("adminBoardTags");
    }

    if (action.equalsIgnoreCase("new")) {
      dynaActionForm.set("action", "add");
      dynaActionForm.set("orders", new Integer(0));
      Board b = this.getBoardService().getBoardByID(bid);
      request.setAttribute("board", b);
      return mapping.findForward("adminBoardTagSet");
    }

    if (action.equalsIgnoreCase("add")) {
      MessageResources mr = this.getResources(request);
      Locale locale = this.getLocale(request);
      String tagName = (String) dynaActionForm.get("tagName");
      if (StringUtils.isBlank(tagName)) {
        this.getAjaxMessagesXML().setMessage("E_BTAG_001", mr.getMessage(locale, "error.admin.btag.namenull"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward("ajaxjsp");
      }
      int orders = ( (Integer) dynaActionForm.get("orders")).intValue();
      Board b = this.getBoardService().getBoardByID(bid);
      BoardTag boardTag = new BoardTag();
      boardTag.setBoard(b);
      boardTag.setBoardID(bid);
      boardTag.setOrders(orders);
      boardTag.setTagName(tagName);

      b.getBoardTag().add(boardTag);

      try {
        this.getBoardService().saveBoard(b);
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK, mr.getMessage(locale, "admin.btag.add.ok"));
      }
      catch (BbscsException ex) {
        this.getAjaxMessagesXML().setMessage("E_BTAG_002", mr.getMessage(locale, "error.admin.btag.adderror"));
      }

      this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
      return mapping.findForward("ajaxjsp");

    }

    if (action.equalsIgnoreCase("edit")) {
      String id = (String) dynaActionForm.get("id");
      Board b = this.getBoardService().getBoardByID(bid);
      Iterator it = b.getBoardTag().iterator();
      BoardTag bt = null;
      while (it.hasNext()) {
        bt = (BoardTag) it.next();
        if (bt.getId().equals(id)) {
          break;
        }
      }
      dynaActionForm.set("id", bt.getId());
      dynaActionForm.set("action", "editdo");
      dynaActionForm.set("orders", new Integer(bt.getOrders()));
      dynaActionForm.set("tagName", bt.getTagName());
      request.setAttribute("board", b);
      return mapping.findForward("adminBoardTagSet");
    }

    if (action.equalsIgnoreCase("editdo")) {
      MessageResources mr = this.getResources(request);
      Locale locale = this.getLocale(request);
      String id = (String) dynaActionForm.get("id");
      Board b = this.getBoardService().getBoardByID(bid);
      BoardTag bt = null;
      Iterator it = b.getBoardTag().iterator();
      while (it.hasNext()) {
        bt = (BoardTag) it.next();
        if (bt.getId().equals(id)) {
          break;
        }
      }
      if (bt != null) {
        String tagName = (String) dynaActionForm.get("tagName");
        if (StringUtils.isBlank(tagName)) {
          this.getAjaxMessagesXML().setMessage("E_BTAG_001",
                                               mr.getMessage(locale, "error.admin.btag.namenull"));
          this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
          return mapping.findForward("ajaxjsp");
        }
        int orders = ( (Integer) dynaActionForm.get("orders")).intValue();
        bt.setTagName(tagName);
        bt.setOrders(orders);
      }
      try {
        this.getBoardService().saveBoard(b);
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK, mr.getMessage(locale, "admin.btag.edit.ok"));
      }
      catch (BbscsException ex1) {
        this.getAjaxMessagesXML().setMessage("E_BTAG_003", mr.getMessage(locale, "error.admin.btag.editerror"));
      }
      this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
      return mapping.findForward("ajaxjsp");
    }

    if (action.equalsIgnoreCase("del")) {
      MessageResources mr = this.getResources(request);
      Locale locale = this.getLocale(request);
      String id = (String) dynaActionForm.get("id");
      Board b = this.getBoardService().getBoardByID(bid);
      /*
             BoardTag bt = null;
             Iterator it = b.getBoardTag().iterator();
             while (it.hasNext()) {
        bt = (BoardTag) it.next();
        if (bt.getId().equals(id)) {
          b.getBoardTag().remove(bt);
          break;
        }
             }*/
      try {
        //this.getBoardService().saveBoard(b);
        this.getBoardService().removeBoardTag(b, id);
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK, mr.getMessage(locale, "admin.btag.del.ok"));
      }
      catch (BbscsException ex1) {
        this.getAjaxMessagesXML().setMessage("E_BTAG_004", mr.getMessage(locale, "error.admin.del.editerror"));
      }
      this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
      return mapping.findForward("ajaxjsp");
    }

    return mapping.findForward("error");
  }

  public BoardService getBoardService() {
    return boardService;
  }

  public AjaxMessagesXML getAjaxMessagesXML() {
    return ajaxMessagesXML;
  }

  public void setBoardService(BoardService boardService) {
    this.boardService = boardService;
  }

  public void setAjaxMessagesXML(AjaxMessagesXML ajaxMessagesXML) {
    this.ajaxMessagesXML = ajaxMessagesXML;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?