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

📄 cmspublishproject.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsPublishProject.java,v $
 * Date   : $Date: 2006/03/27 14:52:18 $
 * 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.commons;

import org.opencms.db.CmsPublishList;
import org.opencms.file.CmsProject;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.lock.CmsLock;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.security.CmsPermissionSet;
import org.opencms.util.CmsDateUtil;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsReport;
import org.opencms.workplace.CmsWorkplaceManager;
import org.opencms.workplace.CmsWorkplaceSettings;
import org.opencms.workplace.threads.CmsPublishThread;
import org.opencms.workplace.threads.CmsXmlDocumentLinkValidatorThread;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

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

import org.apache.commons.logging.Log;

/**
 * Creates the dialogs for publishing a project or a resource.<p> 
 * 
 * The following files use this class:
 * <ul>
 * <li>/commons/publishproject.jsp
 * <li>/commons/publishresource.jsp
 * </ul>
 * <p>
 *
 * @author  Andreas Zahner 
 * 
 * @version $Revision: 1.27 $ 
 * 
 * @since 6.0.0 
 */
public class CmsPublishProject extends CmsReport {

    /** Value for the action: show unlock confirmation. */
    public static final int ACTION_UNLOCK_CONFIRMATION = 200;

    /** Value for the action: unlock confirmed. */
    public static final int ACTION_UNLOCK_CONFIRMED = 210;

    /** The dialog type. */
    public static final String DIALOG_TYPE = "publishproject";

    /** Request parameter value for the action: show unlock confirmation. */
    public static final String DIALOG_UNLOCK_CONFIRMATION = "unlockconfirmation";

    /** Request parameter value for the action: unlock confirmed. */
    public static final String DIALOG_UNLOCK_CONFIRMED = "unlockconfirmed";
    
    /** Request parameter name for the publishsiblings parameter. */
    public static final String PARAM_PUBLISHSIBLINGS = "publishsiblings";
    
    /** Request parameter name for the subresources parameter. */
    public static final String PARAM_SUBRESOURCES = "subresources";

    /** The log object for this class. */
    private static final Log LOG = CmsLog.getLog(CmsPublishProject.class);

    private String m_paramDirectpublish;
    private String m_paramModifieddate;
    private String m_paramModifieduser;
    private String m_paramProjectid;
    private String m_paramProjectname;
    private String m_paramPublishsiblings;
    private String m_paramResourcename;
    private String m_paramSubresources;

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

        super(jsp);
    }

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

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

    /**
     * Performs the publish report, will be called by the JSP page.<p>
     * 
     * @throws JspException if problems including sub-elements occur
     */
    public void actionReport() throws JspException {

        // save initialized instance of this class in request attribute for included sub-elements
        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
        switch (getAction()) {
            case ACTION_REPORT_END:
                actionCloseDialog();
                break;
            case ACTION_REPORT_UPDATE:
                setParamAction(REPORT_UPDATE);
                getJsp().include(FILE_REPORT_OUTPUT);

                break;
            case ACTION_REPORT_BEGIN:
            case ACTION_CONFIRMED:
            default:
                try {
                    List publishResources = null;
                    boolean directPublish = Boolean.valueOf(getParamDirectpublish()).booleanValue();

                    if (directPublish) {
                        // get the offline resource(s) in direct publish mode
                        publishResources = new ArrayList(getResourceList().size());
                        Iterator i = getResourceList().iterator();
                        while (i.hasNext()) {
                            String resName = (String)i.next();
                            try {
                                CmsResource res = getCms().readResource(resName, CmsResourceFilter.ALL);
                                publishResources.add(res);
                                // check if the resource is locked                   
                                CmsLock lock = getCms().getLock(resName);
                                if (! lock.isNullLock()) {
                                    // resource is locked, so unlock it
                                    getCms().unlockResource(resName);
                                }
                            } catch (CmsException e) {
                                addMultiOperationException(e);
                            }
                        }
                        // for error(s) unlocking resource(s), throw exception
                        checkMultiOperationException(Messages.get(), Messages.ERR_PUBLISH_MULTI_UNLOCK_0);
                    } else {
                        if (getCms().getRequestContext().currentProject().getType() == CmsProject.PROJECT_TYPE_TEMPORARY) {
                            // set the flag that this is a temporary project
                            setParamRefreshWorkplace(CmsStringUtil.TRUE);
                        }
                    }

                    if (showUnlockConfirmation()) {
                        // some subresources are locked, unlock them before publishing                                 
                        if (directPublish) {
                            // unlock subresources of a folder
                            Iterator i = getResourceList().iterator();
                            while (i.hasNext()) {
                                String resName = (String)i.next();
                                try {
                                    CmsResource res = getCms().readResource(resName, CmsResourceFilter.ALL);
                                    if (res.isFolder()) {
                                        String folderName = resName;
                                        if (!folderName.endsWith("/")) {
                                            folderName += "/";
                                        }
                                        getCms().lockResource(folderName);
                                        getCms().unlockResource(folderName);
                                    }
                                } catch (CmsException e) {
                                    addMultiOperationException(e);
                                }
                            }
                            // for error(s) unlocking resource(s), throw exception
                            checkMultiOperationException(Messages.get(), Messages.ERR_PUBLISH_MULTI_UNLOCK_0);
                        } else {
                            // unlock all project resources
                            getCms().unlockProject(Integer.parseInt(getParamProjectid()));
                        }
                    }
                    
                    CmsPublishList publishList = null;
                    if (directPublish) {
                        // create publish list for direct publish
                        boolean publishSubResources = Boolean.valueOf(getParamSubresources()).booleanValue();
                        publishList = getCms().getPublishList(
                            publishResources,
                            Boolean.valueOf(getParamPublishsiblings()).booleanValue(),
                            publishSubResources);
                        getCms().checkPublishPermissions(publishList);
                    }
                    
                    // start the link validation thread before publishing
                    CmsXmlDocumentLinkValidatorThread thread = new CmsXmlDocumentLinkValidatorThread(
                        getCms(),
                        publishList,
                        getSettings());
                    setParamAction(REPORT_BEGIN);
                    setParamThread(thread.getUUID().toString());

                    // set the flag that another thread is following
                    setParamThreadHasNext(CmsStringUtil.TRUE);
                    // set the key name for the continue checkbox
                    setParamReportContinueKey(Messages.GUI_PUBLISH_CONTINUE_BROKEN_LINKS_0);
                    getJsp().include(FILE_REPORT_OUTPUT);

                } catch (Throwable e) {
                    // error while unlocking resources, show error screen
                    includeErrorpage(this, e);
                }
        }
    }

    /**
     * Builds the HTML for the "publish siblings" and "publish sub resources" checkboxes when direct publishing a file.<p>
     * 
     * @return the HTMl for the "publish siblings" and "publish sub resources" checkboxes  
     */
    public String buildCheckSiblings() {

        CmsResource res = null;
        if (! isMultiOperation()) {
            try {
                res = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
            } catch (CmsException e) {
                // res will be null
                if (LOG.isInfoEnabled()) {
                    LOG.info(e.getLocalizedMessage());
                }
            }
        }
        StringBuffer result = new StringBuffer(128);
        boolean showSiblingCheckBox = false;
        if (isMultiOperation() || (res != null && res.isFile() && res.getSiblingCount() > 1) || (res != null && res.isFolder())) {
            // resource is file and has siblings, so create checkbox
            
            result.append(dialogSpacer());
            result.append("<input type=\"checkbox\" name=\"");
            result.append(PARAM_PUBLISHSIBLINGS);
            result.append("\" value=\"true\"");
            // set the checkbox state to the default value defined in the opencms.properties
            if (getSettings().getUserSettings().getDialogPublishSiblings()) {
                result.append(" checked=\"checked\"");
            }
            result.append(">&nbsp;");
            result.append(key(Messages.GUI_PUBLISH_ALLSIBLINGS_0));
            showSiblingCheckBox = true;
        }
        if (isOperationOnFolder()) {
            // at least one folder is selected, show "publish subresources" checkbox
            if (showSiblingCheckBox) {
                result.append("<br>");
            }
            result.append("<input type=\"checkbox\" name=\"");
            result.append(PARAM_SUBRESOURCES);
            result.append("\" value=\"true\" checked=\"checked\">&nbsp;");
            if (isMultiOperation()) {
                result.append(key(Messages.GUI_PUBLISH_MULTI_SUBRESOURCES_0));
            } else {
                result.append(key(Messages.GUI_PUBLISH_SUBRESOURCES_0));
            }
        }
        return result.toString();
    }

    /**
     * Returns if a resource will be directly published.<p>
     * 
     * @return <code>"true"</code> if a resource will be directly published
     */
    public String getParamDirectpublish() {

        return m_paramDirectpublish;
    }

    /**
     * Returns the last modification date of the resource which will be published.<p>

⌨️ 快捷键说明

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