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

📄 cmsschedulerlist.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/scheduler/CmsSchedulerList.java,v $
 * Date   : $Date: 2006/03/27 14:52:59 $
 * Version: $Revision: 1.27 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.workplace.tools.scheduler;

import org.opencms.configuration.CmsSystemConfiguration;
import org.opencms.i18n.CmsMessageContainer;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsRuntimeException;
import org.opencms.main.OpenCms;
import org.opencms.scheduler.CmsScheduledJobInfo;
import org.opencms.security.CmsRoleViolationException;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.list.A_CmsListDialog;
import org.opencms.workplace.list.CmsListColumnAlignEnum;
import org.opencms.workplace.list.CmsListColumnDefinition;
import org.opencms.workplace.list.CmsListDateMacroFormatter;
import org.opencms.workplace.list.CmsListDefaultAction;
import org.opencms.workplace.list.CmsListDirectAction;
import org.opencms.workplace.list.CmsListItem;
import org.opencms.workplace.list.CmsListItemActionIconComparator;
import org.opencms.workplace.list.CmsListItemDefaultComparator;
import org.opencms.workplace.list.CmsListItemDetails;
import org.opencms.workplace.list.CmsListItemDetailsFormatter;
import org.opencms.workplace.list.CmsListMetadata;
import org.opencms.workplace.list.CmsListMultiAction;
import org.opencms.workplace.list.CmsListOrderEnum;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;

/**
 * Main scheduled jobs management list view.<p>
 * 
 * Defines the list columns and possible actions for scheduled jobs.<p>
 * 
 * @author Michael Moossen 
 * @author Andreas Zahner  
 * 
 * @version $Revision: 1.27 $ 
 * 
 * @since 6.0.0 
 */
public class CmsSchedulerList extends A_CmsListDialog {

    /** List action activate. */
    public static final String LIST_ACTION_ACTIVATE = "aa";

    /** List action copy. */
    public static final String LIST_ACTION_COPY = "ac";

    /** List action deactivate. */
    public static final String LIST_ACTION_DEACTIVATE = "at";

    /** List action delete. */
    public static final String LIST_ACTION_DELETE = "ad";

    /** List action edit. */
    public static final String LIST_ACTION_EDIT = "ae";

    /** List column activate. */
    public static final String LIST_COLUMN_ACTIVATE = "ca";

    /** List column class. */
    public static final String LIST_COLUMN_CLASS = "cs";

    /** List column copy. */
    public static final String LIST_COLUMN_COPY = "cc";

    /** List column delete. */
    public static final String LIST_COLUMN_DELETE = "cd";

    /** List column edit. */
    public static final String LIST_COLUMN_EDIT = "ce";

    /** List column last execution. */
    public static final String LIST_COLUMN_LASTEXE = "cl";

    /** List column name. */
    public static final String LIST_COLUMN_NAME = "cn";

    /** List column next execution. */
    public static final String LIST_COLUMN_NEXTEXE = "cx";

    /** List action edit. */
    public static final String LIST_DEFACTION_EDIT = "de";

    /** List detail context info. */
    public static final String LIST_DETAIL_CONTEXTINFO = "dc";

    /** List detail parameter. */
    public static final String LIST_DETAIL_PARAMETER = "dp";

    /** List ID. */
    public static final String LIST_ID = "lj";

    /** List action multi activate. */
    public static final String LIST_MACTION_ACTIVATE = "ma";

    /** List action multi deactivate. */
    public static final String LIST_MACTION_DEACTIVATE = "mc";

    /** List action multi delete. */
    public static final String LIST_MACTION_DELETE = "md";

    /** Path to the list buttons. */
    public static final String PATH_BUTTONS = "tools/scheduler/buttons/";

    /**
     * Public constructor.<p>
     * 
     * @param jsp an initialized JSP action element
     */
    public CmsSchedulerList(CmsJspActionElement jsp) {

        super(
            jsp,
            LIST_ID,
            new CmsMessageContainer(Messages.get(), Messages.GUI_JOBS_LIST_NAME_0),
            LIST_COLUMN_NAME,
            CmsListOrderEnum.ORDER_ASCENDING,
            LIST_COLUMN_NAME);
    }

    /**
     * Public constructor with JSP variables.<p>
     * 
     * @param context the JSP page context
     * @param req the JSP request
     * @param res the JSP response
     */
    public CmsSchedulerList(PageContext context, HttpServletRequest req, HttpServletResponse res) {

        this(new CmsJspActionElement(context, req, res));
    }

    /**
     * This method should handle every defined list multi action,
     * by comparing <code>{@link #getParamListAction()}</code> with the id 
     * of the action to execute.<p> 
     * 
     * @throws CmsRuntimeException to signal that an action is not supported
     * 
     */
    public void executeListMultiActions() throws CmsRuntimeException {

        CmsListItem listItem = null;
        if (getParamListAction().equals(LIST_MACTION_DELETE)) {
            // execute the delete multiaction
            List removedItems = new ArrayList();
            try {
                Iterator itItems = getSelectedItems().iterator();
                while (itItems.hasNext()) {
                    listItem = (CmsListItem)itItems.next();
                    OpenCms.getScheduleManager().unscheduleJob(getCms(), listItem.getId());
                    removedItems.add(listItem.getId());
                }
                // update the XML configuration
                writeConfiguration(false);
            } catch (CmsException e) {
                throw new CmsRuntimeException(Messages.get().container(
                    Messages.ERR_UNSCHEDULE_JOB_1,
                    (listItem == null) ? (Object)"?" : new Integer(listItem.getId())), e);
            } finally {
                getList().removeAllItems(removedItems, getLocale());
            }
        } else if (getParamListAction().equals(LIST_MACTION_ACTIVATE)
            || getParamListAction().equals(LIST_MACTION_DEACTIVATE)) {
            // execute the activate or deactivate multiaction
            try {
                Iterator itItems = getSelectedItems().iterator();
                boolean activate = getParamListAction().equals(LIST_MACTION_ACTIVATE);
                while (itItems.hasNext()) {
                    // toggle the active state of the selected item(s)
                    listItem = (CmsListItem)itItems.next();
                    CmsScheduledJobInfo job = (CmsScheduledJobInfo)OpenCms.getScheduleManager().getJob(listItem.getId()).clone();
                    job.setActive(activate);
                    OpenCms.getScheduleManager().scheduleJob(getCms(), job);
                }
                // update the XML configuration
                writeConfiguration(true);
            } catch (CmsException e) {
                throw new CmsRuntimeException(Messages.get().container(
                    Messages.ERR_SCHEDULE_JOB_1,
                    (listItem == null) ? (Object)"?" : new Integer(listItem.getId())), e);
            }
        } else {
            throwListUnsupportedActionException();
        }
        listSave();
    }

    /**
     * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
     */
    public void executeListSingleActions() throws IOException, ServletException {

        if (getParamListAction().equals(LIST_ACTION_EDIT) || getParamListAction().equals(LIST_DEFACTION_EDIT)) {
            // edit a job from the list
            String jobId = getSelectedItem().getId();
            // forward to the edit job screen with additional parameters               
            Map params = new HashMap();
            params.put(CmsEditScheduledJobInfoDialog.PARAM_JOBID, jobId);
            // set action parameter to initial dialog call
            params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL);
            getToolManager().jspForwardTool(this, "/scheduler/edit", params);
        } else if (getParamListAction().equals(LIST_ACTION_COPY)) {
            // copy a job from the list
            String jobId = getSelectedItem().getId();
            // forward to the edit job screen with additional parameters
            Map params = new HashMap();
            params.put(CmsEditScheduledJobInfoDialog.PARAM_JOBID, jobId);
            // set action parameter to copy job action
            params.put(CmsDialog.PARAM_ACTION, CmsEditScheduledJobInfoDialog.DIALOG_COPYJOB);
            getToolManager().jspForwardTool(this, "/scheduler/new", params);
        } else if (getParamListAction().equals(LIST_ACTION_ACTIVATE)) {
            // activate a job from the list
            String jobId = getSelectedItem().getId();
            CmsScheduledJobInfo job = (CmsScheduledJobInfo)OpenCms.getScheduleManager().getJob(jobId).clone();
            job.setActive(true);
            try {
                OpenCms.getScheduleManager().scheduleJob(getCms(), job);
                // update the XML configuration
                writeConfiguration(true);
            } catch (CmsException e) {
                // should never happen
                throw new CmsRuntimeException(Messages.get().container(Messages.ERR_SCHEDULE_JOB_1, jobId), e);
            }
        } else if (getParamListAction().equals(LIST_ACTION_DEACTIVATE)) {
            // deactivate a job from the list
            String jobId = getSelectedItem().getId();
            CmsScheduledJobInfo job = (CmsScheduledJobInfo)OpenCms.getScheduleManager().getJob(jobId).clone();
            job.setActive(false);
            try {
                OpenCms.getScheduleManager().scheduleJob(getCms(), job);
                // update the XML configuration
                writeConfiguration(true);
            } catch (CmsException e) {
                // should never happen
                throw new CmsRuntimeException(Messages.get().container(Messages.ERR_UNSCHEDULE_JOB_1, jobId), e);
            }
        } else if (getParamListAction().equals(LIST_ACTION_DELETE)) {
            // delete a job from the list
            String jobId = getSelectedItem().getId();
            try {
                OpenCms.getScheduleManager().unscheduleJob(getCms(), jobId);
                // update the XML configuration
                writeConfiguration(false);
                getList().removeItem(jobId, getLocale());
            } catch (CmsRoleViolationException e) {
                // should never happen
                throw new CmsRuntimeException(Messages.get().container(Messages.ERR_DELETE_JOB_1, jobId), e);
            }
        } else {
            throwListUnsupportedActionException();
        }
        listSave();
    }

    /**
     * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
     */
    protected void fillDetails(String detailId) {

⌨️ 快捷键说明

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