SortOpt.java
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:4k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package com.opensource.blog.web.action;
  2. import javax.servlet.http.*;
  3. import org.apache.struts.action.*;
  4. import com.opensource.blog.comm.BlogUtil;
  5. import com.opensource.blog.comm.Constant;
  6. import com.opensource.blog.exception.*;
  7. import com.opensource.blog.model.Sort;
  8. import com.opensource.blog.service.*;
  9. import com.opensource.blog.web.form.*;
  10. import com.opensource.blog.web.servlet.*;
  11. public class SortOpt
  12.     extends BaseAction {
  13.   private SortService sortService;
  14.   public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
  15.                                HttpServletRequest servletRequest,
  16.                                HttpServletResponse servletResponse) {
  17.     SortForm form = (SortForm) actionForm;
  18.     ActionMessages errors = new ActionMessages();
  19.     UserSession us = this.getUserSession(servletRequest);
  20.     if (form.getAction().equalsIgnoreCase("add")) {
  21.       if (this.getSortService().getSortCountByBlogID(us.getBlog().getId().longValue()) >=
  22.           Constant.SORT_MAX_NUM) {
  23.         errors.add("error.sort.sortmax", new ActionMessage("error.sort.sortmax",
  24.             String.valueOf(Constant.SORT_MAX_NUM)));
  25.         saveErrors(servletRequest, errors);
  26.         return actionMapping.findForward("error");
  27.       }
  28.       Sort sort = new Sort();
  29.       sort.setBlogid(us.getBlog().getId().longValue());
  30.       sort.setSortname(form.getAddsortname());
  31.       try {
  32.         sort = this.getSortService().saveSort(sort);
  33.       }
  34.       catch (BlogException ex) {
  35.         errors.add("error.sort.adderror", new ActionMessage("error.sort.adderror"));
  36.         saveErrors(servletRequest, errors);
  37.         return actionMapping.findForward("error");
  38.       }
  39.       ActionForward f = new ActionForward(BlogUtil.getResultUrl("sort.addok", "sort.do"), true);
  40.       return f;
  41.     }
  42.     if (form.getAction().equalsIgnoreCase("up")) {
  43.       Sort sort = this.getSortService().findSortByID_BlogID(form.getSortid(),
  44.           us.getBlog().getId().longValue());
  45.       if (sort == null) {
  46.         errors.add("error.sort.getsort", new ActionMessage("error.sort.getsort"));
  47.         saveErrors(servletRequest, errors);
  48.         return actionMapping.findForward("error");
  49.       }
  50.       sort.setSortname(form.getUpsortname());
  51.       try {
  52.         sort = this.getSortService().saveSort(sort);
  53.       }
  54.       catch (BlogException ex1) {
  55.         errors.add("error.sort.upsort", new ActionMessage("error.sort.upsort"));
  56.         saveErrors(servletRequest, errors);
  57.         return actionMapping.findForward("error");
  58.       }
  59.       ActionForward f = new ActionForward(BlogUtil.getResultUrl("sort.upok",
  60.           "sort.do?action=show&sortid=" + form.getSortid()), true);
  61.       return f;
  62.     }
  63.     if (form.getAction().equalsIgnoreCase("del")) {
  64.       Sort sort = this.getSortService().findSortByID_BlogID(form.getSortid(),
  65.           us.getBlog().getId().longValue());
  66.       if (sort == null) {
  67.         errors.add("error.sort.getsort", new ActionMessage("error.sort.getsort"));
  68.         saveErrors(servletRequest, errors);
  69.         return actionMapping.findForward("error");
  70.       }
  71.       try {
  72.         this.getSortService().removeSort(sort);
  73.       }
  74.       catch (BlogException ex2) {
  75.         errors.add("error.sort.delsort", new ActionMessage("error.sort.delsort"));
  76.         saveErrors(servletRequest, errors);
  77.         return actionMapping.findForward("error");
  78.       }
  79.       ActionForward f = new ActionForward(BlogUtil.getResultUrl("sort.delok", "sort.do"), true);
  80.       return f;
  81.     }
  82.     return actionMapping.findForward("error");
  83.   }
  84.   public SortService getSortService() {
  85.     return sortService;
  86.   }
  87.   public void setSortService(SortService sortService) {
  88.     this.sortService = sortService;
  89.   }
  90. }