cmspublishqueuelist.java

来自「找了很久才找到到源代码」· Java 代码 · 共 531 行 · 第 1/2 页

JAVA
531
字号
/*
 * File   : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/publishqueue/CmsPublishQueueList.java,v $
 * Date   : $Date: 2007-08-13 16:29:52 $
 * Version: $Revision: 1.4 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 2002 - 2007 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.publishqueue;

import org.opencms.db.CmsPublishList;
import org.opencms.file.CmsResource;
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.publish.CmsPublishJobBase;
import org.opencms.publish.CmsPublishJobEnqueued;
import org.opencms.publish.CmsPublishJobRunning;
import org.opencms.security.CmsRole;
import org.opencms.util.CmsUUID;
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.CmsListItemDetails;
import org.opencms.workplace.list.CmsListItemDetailsFormatter;
import org.opencms.workplace.list.CmsListMetadata;
import org.opencms.workplace.list.CmsListOrderEnum;
import org.opencms.workplace.list.I_CmsListFormatter;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

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

/**
 * Provides a list for the global publish queue.<p> 
 *
 * @author Raphael Schnuck
 * 
 * @version $Revision: 1.4 $ 
 * 
 * @since 6.5.5
 */
public class CmsPublishQueueList extends A_CmsListDialog {

    /** list id constant. */
    public static final String LIST_ID = "lpq";

    /** The path to the publish report view icon. */
    public static final String PUBLISHQUEUE_CANCEL_BUTTON = "tools/publishqueue/buttons/cancel.png";

    /** The path to the publish report view icon. */
    public static final String PUBLISHQUEUE_STATE_PROCEED_BUTTON = "tools/publishqueue/buttons/publish_current.png";

    /** Constant for the state of a list entry. */
    public static final int STATE_OTHER = 1;

    /** Constant for the state of a list entry. */
    public static final int STATE_OWN = 0;

    /** Constant for the state of a list entry. */
    public static final int STATE_PROCEED = 2;

    /** list action id constant. */
    private static final String LIST_ACTION_CANCEL = "ac";

    /** list action id constant. */
    private static final String LIST_ACTION_NUMBER = "an";

    /** list action id constant. */
    private static final String LIST_ACTION_PROJECT = "ap";

    /** list action id constant. */
    private static final String LIST_ACTION_RESCOUNT = "ar";

    /** list action id constant. */
    private static final String LIST_ACTION_STARTTIME = "at";

    /** list action id constant. */
    private static final String LIST_ACTION_STATE = "as";

    /** list action id constant. */
    private static final String LIST_ACTION_USER = "au";

    /** list column id constant. */
    private static final String LIST_COLUMN_NUMBER = "cn";

    /** list column id constant. */
    private static final String LIST_COLUMN_PROJECT = "cp";

    /** list column id constant. */
    private static final String LIST_COLUMN_RESCOUNT = "cr";

    /** list column id constant. */
    private static final String LIST_COLUMN_STARTTIME = "ct";

    /** list column id constant. */
    private static final String LIST_COLUMN_STATE = "cs";

    /** list column id constant. */
    private static final String LIST_COLUMN_USER = "cu";

    /** list detail id constant. */
    private static final String LIST_DETAIL_RESOURCES = "dr";

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

        this(jsp, LIST_ID);
    }

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

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

    /**
     * Protected constructor.<p>
     * 
     * @param jsp an initialized JSP action element
     * @param listId the id of the specialized list
     */
    protected CmsPublishQueueList(CmsJspActionElement jsp, String listId) {

        super(
            jsp,
            listId,
            Messages.get().container(Messages.GUI_PUBLISHQUEUE_LIST_NAME_0),
            LIST_COLUMN_NUMBER,
            CmsListOrderEnum.ORDER_ASCENDING,
            null);
    }

    /**
     * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
     */
    public void executeListMultiActions() throws CmsRuntimeException {

        throwListUnsupportedActionException();
    }

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

        if (getParamListAction().equals(LIST_ACTION_NUMBER)
            || getParamListAction().equals(LIST_ACTION_PROJECT)
            || getParamListAction().equals(LIST_ACTION_RESCOUNT)
            || getParamListAction().equals(LIST_ACTION_STATE)
            || getParamListAction().equals(LIST_ACTION_USER)
            || getParamListAction().equals(LIST_ACTION_STARTTIME)) {
            try {
                getToolManager().jspForwardTool(this, "/publishqueue/live", null);
            } catch (Exception e) {
                // Should never happen
            }
        } else if (getParamListAction().equals(LIST_ACTION_CANCEL)) {
            // search for the publish job to cancel
            String userName = (String)getSelectedItem().get(LIST_COLUMN_USER);
            long enqueueTime = ((Date)getSelectedItem().get(LIST_COLUMN_STARTTIME)).getTime();
            Iterator itJobs = OpenCms.getPublishManager().getPublishQueue().iterator();
            while (itJobs.hasNext()) {
                CmsPublishJobEnqueued publishJob = (CmsPublishJobEnqueued)itJobs.next();
                if (userName.equals(publishJob.getUserName(getCms())) && (enqueueTime == publishJob.getEnqueueTime())) {
                    try {
                        OpenCms.getPublishManager().abortPublishJob(getCms(), publishJob, true);
                    } catch (CmsException e) {
                        throw new CmsRuntimeException(e.getMessageContainer(), e);
                    }
                    break;
                }
            }
        } else {
            throwListUnsupportedActionException();
        }
    }

    /**
     * @see org.opencms.workplace.list.A_CmsListDialog#defaultActionHtmlEnd()
     */
    protected String defaultActionHtmlEnd() {

        return "&nbsp;<br>";
    }

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

        // get content
        List publishJobs = getList().getAllContent();
        Iterator itPublishJobs = publishJobs.iterator();
        while (itPublishJobs.hasNext()) {
            CmsListItem item = (CmsListItem)itPublishJobs.next();
            int state = ((Integer)item.get(LIST_COLUMN_STATE)).intValue();
            boolean enabled = ((state == STATE_PROCEED) && (OpenCms.getRoleManager().hasRole(
                getCms(),
                CmsRole.ROOT_ADMIN) || getCms().getRequestContext().currentUser().getName().equals(
                item.get(LIST_COLUMN_USER))));
            enabled = enabled
                || (OpenCms.getRoleManager().hasRole(getCms(), CmsRole.ROOT_ADMIN) || (state == STATE_OWN));
            if (!enabled) {
                continue;
            }
            CmsUUID publishHistoryId = new CmsUUID(item.getId());
            CmsPublishJobBase publishJob = OpenCms.getPublishManager().getJobByPublishHistoryId(publishHistoryId);
            StringBuffer html = new StringBuffer(32);
            if (publishJob != null && detailId.equals(LIST_DETAIL_RESOURCES)) {
                // resources
                CmsPublishList publishList;
                if (publishJob instanceof CmsPublishJobEnqueued) {
                    publishList = ((CmsPublishJobEnqueued)publishJob).getPublishList();
                } else if (publishJob instanceof CmsPublishJobRunning) {
                    publishList = ((CmsPublishJobRunning)publishJob).getPublishList();
                } else {
                    continue;
                }
                List resources = new ArrayList(publishList.size());
                resources.addAll(publishList.getFolderList());

⌨️ 快捷键说明

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