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

📄 catalogaction.java

📁 关于 Jaoso新闻文章发布系统 --- --- --- --- --- --- --- --- --- --- --- --- --- -- 版本信息:Jaoso新闻文章发布系统 0.9.1b
💻 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 {

    //~ Instance fields ========================================================

    /**  DOCUMENT ME! */
    private CatalogService catalogService = (CatalogService) getServiceLocator()
                                                                 .getService("gbCatalogService");

    //~ Methods ================================================================

    /**
     * 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 = catalogService.findAll();
        Message[] messages;
        Integer msgCount;

        if (MyUtils.isBlank(id)) {

            catalog = catalogs[0];
        } else {

            catalog = catalogService.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 = catalogService.getMessages(args);
        msgCount = catalogService.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 = catalogService.findAll();
        Message[] messages;
        Integer msgCount;

        if (MyUtils.isBlank(id)) {

            catalog = catalogs[0];
        } else {

            catalog = catalogService.getCatalog(id);
        }

        msg.setCreateDate(new Date());
        catalogService.addMessage(catalog.getId(), msg, parent);
        catalog = catalogService.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 = catalogService.getMessages(args);
        msgCount = catalogService.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 {

            catalogService.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", catalogService.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", catalogService.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");
        catalogService.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");
        catalogService.removeMessage(msgId);

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

        if (MyUtils.isBlank(id)) {

            catalog = catalogs[0];
        } else {

            catalog = catalogService.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 = catalogService.getMessages(args);
        msgCount = catalogService.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 {

            catalogService.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 + -