⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 catalogaction.java

📁 Jaoso新闻文章发布系统 0.9.1final 程序架构: Struts+Spring+Hibernate 主要功能:   ·新闻采用在线编辑器,可以象使用word一样编辑新闻,可简繁
💻 JAVA
字号:
package jaoso.guestbook.web.action;

import jaoso.framework.util.MyUtils;

import jaoso.framework.web.action.BaseAction;

import jaoso.guestbook.domain.GbCatalog;
import jaoso.guestbook.domain.Message;

import jaoso.guestbook.service.CatalogService;

import jaoso.news.exception.CatalogExistException;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * @author Edgeloner edgeloner@163.com
 * @since 2004-7-3
 */
public class CatalogAction extends BaseAction {
    private CatalogService gbCatalogService;


    public void setGbCatalogService(CatalogService gbCatalogService) {
        this.gbCatalogService = gbCatalogService;
    }
    /**
     * get all catalog and message
     *
     * @param mapping
     *            DOCUMENT ME!
     * @param form
     *            DOCUMENT ME!
     * @param request
     *            DOCUMENT ME!
     * @param response
     *            DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public final ActionForward getMessage(final ActionMapping mapping,
        final ActionForm form, final HttpServletRequest request,
        final HttpServletResponse response) {
        String id = request.getParameter("id");
        GbCatalog catalog;
        GbCatalog[] catalogs = gbCatalogService.findAll();
        Message[] messages;
        Integer msgCount;

        if (MyUtils.isBlank(id)) {
            catalog = catalogs[0];
        } else {
            catalog = gbCatalogService.getCatalog(id);
        }

        //��ѯ�ؼ���
        String para = request.getParameter("para");

        //��ѯ��Ŀ¼
        String catalogId = request.getParameter("catalogId");

        //��ʲô����
        String orderby = request.getParameter("orderby");

        //�����
        String sort = request.getParameter("sort");

        //�ڼ�ҳ
        String page = request.getParameter("pager.offset");

        String[] args = { para, catalog.getId(), orderby, sort, page };
        messages = gbCatalogService.getMessages(args);
        msgCount = gbCatalogService.getResultCount(args);

        // Remove the obsolete form bean
        removeAttribute(mapping, request);
        request.setAttribute("messages", messages);
        request.setAttribute("msgCount", msgCount);
        request.setAttribute("catalog", catalog);
        request.setAttribute("catalogs", catalogs);

        return (mapping.findForward("success"));
    }

    /**
     * DOCUMENT ME!
     *
     * @param mapping
     *            DOCUMENT ME!
     * @param form
     *            DOCUMENT ME!
     * @param request
     *            DOCUMENT ME!
     * @param response
     *            DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public final ActionForward addMessage(final ActionMapping mapping,
        final ActionForm form, final HttpServletRequest request,
        final HttpServletResponse response) {
        Message msg = (Message) ((DynaActionForm) form).get("message");
        String id = request.getParameter("id");
        String parent = request.getParameter("parent");
        parent = MyUtils.isBlank(parent) ? null : parent;
        msg.setContent(MyUtils.htmlEncode(msg.getContent()));

        GbCatalog catalog;
        GbCatalog[] catalogs = gbCatalogService.findAll();
        Message[] messages;
        Integer msgCount;

        if (MyUtils.isBlank(id)) {
            catalog = catalogs[0];
        } else {
            catalog = gbCatalogService.getCatalog(id);
        }

        msg.setCreateDate(new Date());
        gbCatalogService.addMessage(catalog.getId(), msg, parent);
        catalog = gbCatalogService.getCatalog(catalog.getId());

        //��ѯ�ؼ���
        String para = request.getParameter("para");

        //��ѯ��Ŀ¼
        String catalogId = request.getParameter("catalogId");

        //��ʲô����
        String orderby = request.getParameter("orderby");

        //�����
        String sort = request.getParameter("sort");

        //�ڼ�ҳ
        String page = request.getParameter("pager.offset");

        String[] args = { para, catalog.getId(), orderby, sort, page };
        messages = gbCatalogService.getMessages(args);
        msgCount = gbCatalogService.getResultCount(args);

        // Remove the obsolete form bean
        removeAttribute(mapping, request);
        request.setAttribute("messages", messages);
        request.setAttribute("amsgCount", msgCount);
        request.setAttribute("catalog", catalog);
        request.setAttribute("catalogs", catalogs);

        return (mapping.findForward("success"));
    }

    /**
     * create new catalog
     *
     * @param mapping
     *            DOCUMENT ME!
     * @param form
     *            DOCUMENT ME!
     * @param request
     *            DOCUMENT ME!
     * @param response
     *            DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public final ActionForward create(final ActionMapping mapping,
        final ActionForm form, final HttpServletRequest request,
        final HttpServletResponse response) {
        ActionErrors errors = new ActionErrors();
        GbCatalog catalog = (GbCatalog) ((DynaActionForm) form).get("catalog");
        catalog.setId(null);

        try {
            gbCatalogService.createCatalog(catalog);
        } catch (CatalogExistException e) {
            errors.add("create error", new ActionError("errors.CatalogExist"));
        }

        if (!errors.isEmpty()) {
            saveErrors(request, errors);
            saveToken(request);

            return (mapping.getInputForward());
        } else {
            // Remove the obsolete form bean
            removeAttribute(mapping, request);

            return (mapping.findForward("success"));
        }
    }

    /**
     * load all catalog for edit
     *
     * @param mapping
     *            DOCUMENT ME!
     * @param form
     *            DOCUMENT ME!
     * @param request
     *            DOCUMENT ME!
     * @param response
     *            DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public final ActionForward load4edit(final ActionMapping mapping,
        final ActionForm form, final HttpServletRequest request,
        final HttpServletResponse response) {
        // Remove the obsolete form bean
        removeAttribute(mapping, request);
        request.setAttribute("catalogs", gbCatalogService.findAll());

        return (mapping.findForward("success"));
    }

    /**
     * load all catalog for remove
     *
     * @param mapping
     *            DOCUMENT ME!
     * @param form
     *            DOCUMENT ME!
     * @param request
     *            DOCUMENT ME!
     * @param response
     *            DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public final ActionForward load4remove(final ActionMapping mapping,
        final ActionForm form, final HttpServletRequest request,
        final HttpServletResponse response) {
        // Remove the obsolete form bean
        removeAttribute(mapping, request);
        request.setAttribute("catalogs", gbCatalogService.findAll());

        return (mapping.findForward("success"));
    }

    /**
     * remove catalog
     *
     * @param mapping
     *            DOCUMENT ME!
     * @param form
     *            DOCUMENT ME!
     * @param request
     *            DOCUMENT ME!
     * @param response
     *            DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public final ActionForward remove(final ActionMapping mapping,
        final ActionForm form, final HttpServletRequest request,
        final HttpServletResponse response) {
        String id = request.getParameter("catalog.id");
        gbCatalogService.removeCatalog(id);

        // Remove the obsolete form bean
        removeAttribute(mapping, request);

        return (mapping.findForward("success"));
    }

    /**
     * remove message
     *
     * @param mapping
     *            DOCUMENT ME!
     * @param form
     *            DOCUMENT ME!
     * @param request
     *            DOCUMENT ME!
     * @param response
     *            DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public final ActionForward removeMessage(final ActionMapping mapping,
        final ActionForm form, final HttpServletRequest request,
        final HttpServletResponse response) {
        String msgId = request.getParameter("msgId");
        String id = request.getParameter("id");
        gbCatalogService.removeMessage(msgId);

        GbCatalog catalog;
        GbCatalog[] catalogs = gbCatalogService.findAll();
        Message[] messages;
        Integer msgCount;

        if (MyUtils.isBlank(id)) {
            catalog = catalogs[0];
        } else {
            catalog = gbCatalogService.getCatalog(id);
        }

        //��ѯ�ؼ���
        String para = request.getParameter("para");

        //��ѯ��Ŀ¼
        String catalogId = request.getParameter("catalogId");

        //��ʲô����
        String orderby = request.getParameter("orderby");

        //�����
        String sort = request.getParameter("sort");

        //�ڼ�ҳ
        String page = request.getParameter("pager.offset");

        String[] args = { para, catalog.getId(), orderby, sort, page };
        messages = gbCatalogService.getMessages(args);
        msgCount = gbCatalogService.getResultCount(args);

        // Remove the obsolete form bean
        removeAttribute(mapping, request);
        request.setAttribute("messages", messages);
        request.setAttribute("msgCount", msgCount);
        request.setAttribute("catalog", catalog);
        request.setAttribute("catalogs", catalogs);

        return (mapping.findForward("success"));
    }

    /**
     * update catalog
     *
     * @param mapping
     *            DOCUMENT ME!
     * @param form
     *            DOCUMENT ME!
     * @param request
     *            DOCUMENT ME!
     * @param response
     *            DOCUMENT ME!
     *
     * @return DOCUMENT ME!
     */
    public final ActionForward update(final ActionMapping mapping,
        final ActionForm form, final HttpServletRequest request,
        final HttpServletResponse response) {
        ActionErrors errors = new ActionErrors();
        GbCatalog catalog = (GbCatalog) ((DynaActionForm) form).get("catalog");

        try {
            gbCatalogService.updateCatalog(catalog);
        } catch (CatalogExistException e) {
            errors.add("create error", new ActionError("errors.CatalogExist"));
        }

        if (!errors.isEmpty()) {
            saveErrors(request, errors);
            saveToken(request);

            return (mapping.getInputForward());
        } else {
            // Remove the obsolete form bean
            removeAttribute(mapping, request);

            return (mapping.findForward("success"));
        }
    }
}

⌨️ 快捷键说明

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