SortOpt.java
资源名称:Myblog.rar [点击查看]
上传用户:wlfwy2004
上传日期:2016-12-12
资源大小:33978k
文件大小:4k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.opensource.blog.web.action;
- import javax.servlet.http.*;
- import org.apache.struts.action.*;
- import com.opensource.blog.comm.BlogUtil;
- import com.opensource.blog.comm.Constant;
- import com.opensource.blog.exception.*;
- import com.opensource.blog.model.Sort;
- import com.opensource.blog.service.*;
- import com.opensource.blog.web.form.*;
- import com.opensource.blog.web.servlet.*;
- public class SortOpt
- extends BaseAction {
- private SortService sortService;
- public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm,
- HttpServletRequest servletRequest,
- HttpServletResponse servletResponse) {
- SortForm form = (SortForm) actionForm;
- ActionMessages errors = new ActionMessages();
- UserSession us = this.getUserSession(servletRequest);
- if (form.getAction().equalsIgnoreCase("add")) {
- if (this.getSortService().getSortCountByBlogID(us.getBlog().getId().longValue()) >=
- Constant.SORT_MAX_NUM) {
- errors.add("error.sort.sortmax", new ActionMessage("error.sort.sortmax",
- String.valueOf(Constant.SORT_MAX_NUM)));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- Sort sort = new Sort();
- sort.setBlogid(us.getBlog().getId().longValue());
- sort.setSortname(form.getAddsortname());
- try {
- sort = this.getSortService().saveSort(sort);
- }
- catch (BlogException ex) {
- errors.add("error.sort.adderror", new ActionMessage("error.sort.adderror"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- ActionForward f = new ActionForward(BlogUtil.getResultUrl("sort.addok", "sort.do"), true);
- return f;
- }
- if (form.getAction().equalsIgnoreCase("up")) {
- Sort sort = this.getSortService().findSortByID_BlogID(form.getSortid(),
- us.getBlog().getId().longValue());
- if (sort == null) {
- errors.add("error.sort.getsort", new ActionMessage("error.sort.getsort"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- sort.setSortname(form.getUpsortname());
- try {
- sort = this.getSortService().saveSort(sort);
- }
- catch (BlogException ex1) {
- errors.add("error.sort.upsort", new ActionMessage("error.sort.upsort"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- ActionForward f = new ActionForward(BlogUtil.getResultUrl("sort.upok",
- "sort.do?action=show&sortid=" + form.getSortid()), true);
- return f;
- }
- if (form.getAction().equalsIgnoreCase("del")) {
- Sort sort = this.getSortService().findSortByID_BlogID(form.getSortid(),
- us.getBlog().getId().longValue());
- if (sort == null) {
- errors.add("error.sort.getsort", new ActionMessage("error.sort.getsort"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- try {
- this.getSortService().removeSort(sort);
- }
- catch (BlogException ex2) {
- errors.add("error.sort.delsort", new ActionMessage("error.sort.delsort"));
- saveErrors(servletRequest, errors);
- return actionMapping.findForward("error");
- }
- ActionForward f = new ActionForward(BlogUtil.getResultUrl("sort.delok", "sort.do"), true);
- return f;
- }
- return actionMapping.findForward("error");
- }
- public SortService getSortService() {
- return sortService;
- }
- public void setSortService(SortService sortService) {
- this.sortService = sortService;
- }
- }