cmspublishproject.java

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

JAVA
945
字号
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsPublishProject.java,v $
 * Date   : $Date: 2007-08-30 10:38:19 $
 * Version: $Revision: 1.32 $
 *
 * 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.commons;

import org.opencms.configuration.CmsDefaultUserSettings;
import org.opencms.db.CmsPublishList;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsResourceFilter;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.lock.CmsLock;
import org.opencms.lock.CmsLockFilter;
import org.opencms.main.CmsException;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.report.CmsHtmlReport;
import org.opencms.security.CmsPermissionSet;
import org.opencms.security.CmsRole;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;
import org.opencms.workplace.CmsMultiDialog;
import org.opencms.workplace.CmsWorkplaceSettings;

import java.util.ArrayList;
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 
 * @author Michael Moossen
 * 
 * @version $Revision: 1.32 $ 
 * 
 * @since 6.0.0 
 */
public class CmsPublishProject extends CmsMultiDialog {

    /** Value for the action: delete the resource. */
    public static final int ACTION_PUBLISH = 110;

    /** Value for the action: resources confirmed. */
    public static final int ACTION_RESOURCES_CONFIRMED = 111;

    /** Request parameter value for the action: dialog resources confirmed. */
    public static final String DIALOG_RESOURCES_CONFIRMED = "resourcesconfirmed";

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

    /** Request parameter name for the publishsiblings parameter. */
    public static final String PARAM_PUBLISHSIBLINGS = "publishsiblings";

    /** Request parameter name for the relatedresources parameter. */
    public static final String PARAM_RELATEDRESOURCES = "relatedresources";

    /** 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);

    /** Parameter value for the direct publish flag. */
    private String m_paramDirectpublish;

    /** Parameter value for the progress key. */
    private String m_paramProgresskey;

    /** Parameter value for the project id. */
    private String m_paramProjectid;

    /** Parameter value for the project name. */
    private String m_paramProjectname;

    /** Parameter value for the publish siblings flag. */
    private String m_paramPublishsiblings;

    /** Parameter value for the publish related resources flag. */
    private String m_paramRelatedresources;

    /** Parameter value for the publish subresources flag. */
    private String m_paramSubresources;

    /** The progress bar for the dialog. */
    private CmsProgressWidget m_progress;

    /**
     * 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 action, will be called by the JSP page.<p>
     * 
     * @throws JspException if problems including sub-elements occur
     */
    public void actionPublish() throws JspException {

        try {
            boolean isFolder = false;
            if (!isMultiOperation()) {
                if (isDirectPublish()) {
                    isFolder = getCms().readResource(getParamResource(), CmsResourceFilter.ALL).isFolder();
                }
            }
            if (performDialogOperation()) {
                // if no exception is caused and "true" is returned publish operation was successful
                if (isMultiOperation() || isFolder) {
                    // set request attribute to reload the explorer tree view
                    List folderList = new ArrayList();
                    folderList.add(CmsResource.getParentFolder((String)getResourceList().get(0)));
                    Iterator it = getResourceList().iterator();
                    while (it.hasNext()) {
                        String res = (String)it.next();
                        if (CmsResource.isFolder(res)) {
                            folderList.add(res);
                        }
                    }
                    getJsp().getRequest().setAttribute(REQUEST_ATTRIBUTE_RELOADTREE, folderList);
                }
                actionCloseDialog();
            } else {
                // "false" returned, display "please wait" screen
                getJsp().include(FILE_DIALOG_SCREEN_WAIT);
            }
        } catch (Throwable e) {
            // prepare common message part
            includeErrorpage(this, e);
        }
    }

    /**
     * Returns the html for the confirmation message.<p>
     * 
     * @return the html for the confirmation message
     */
    public String buildConfirmation() {

        StringBuffer result = new StringBuffer(512);

        result.append("<p><div id='conf-msg'>\n");
        if (!isDirectPublish()) {
            result.append(key(Messages.GUI_PUBLISH_PROJECT_CONFIRMATION_1, new Object[] {getProjectname()}));
        } else {
            boolean isFolder = false;
            if (!isMultiOperation()) {
                try {
                    isFolder = getCms().readResource(getParamResource(), CmsResourceFilter.ALL).isFolder();
                } catch (CmsException e) {
                    // ignore
                }
            }
            if (isMultiOperation() || isFolder || (hasSiblings() && hasCorrectLockstate())) {
                result.append(key(Messages.GUI_PUBLISH_MULTI_CONFIRMATION_0));
            } else {
                result.append(key(Messages.GUI_PUBLISH_CONFIRMATION_0));
            }
        }
        result.append("\n</div></p>\n");
        return result.toString();
    }

    /**
     * Returns the html code to build the confirmation messages.<p>
     * 
     * @return html code
     */
    public String buildLockConfirmationMessageJS() {

        StringBuffer html = new StringBuffer(512);
        html.append("<script type='text/javascript'><!--\n");
        html.append("function setConfirmationMessage(locks, blockinglocks) {\n");
        html.append("\tvar confMsg = document.getElementById('conf-msg');\n");
        html.append("\tif (locks > -1) {\n");
        html.append("\t\tdocument.getElementById('butClose').className = 'hide';\n");
        html.append("\t\tdocument.getElementById('butContinue').className = '';\n");
        html.append("\t\tif (locks > 0) {\n");
        html.append("\t\t\tshowAjaxReportContent();\n");
        html.append("\t\t\tconfMsg.innerHTML = '");
        html.append(key(Messages.GUI_PUBLISH_UNLOCK_CONFIRMATION_0));
        html.append("';\n");
        html.append("\t\t} else {\n");
        html.append("\t\tshowAjaxOk();\n");
        html.append("\t\t\tconfMsg.innerHTML = '");
        html.append(key(Messages.GUI_PUBLISH_NO_LOCKS_CONFIRMATION_0));
        html.append("';\n");
        html.append("\t\t}\n");
        html.append("\t} else {\n");
        html.append("\t\tdocument.getElementById('butClose').className = '';\n");
        html.append("\t\tdocument.getElementById('butContinue').className = 'hide';\n");
        html.append("\t\tconfMsg.innerHTML = '");
        html.append(key(org.opencms.workplace.Messages.GUI_AJAX_REPORT_WAIT_0));
        html.append("';\n");
        html.append("\t}\n");
        html.append("}\n");
        html.append("// -->\n");
        html.append("</script>\n");
        return html.toString();
    }

    /**
     * Returns the html code to build the lock dialog.<p>
     * 
     * @return html code
     * 
     * @throws CmsException if something goes wrong
     */
    public String buildLockDialog() throws CmsException {

        CmsLockFilter nonBlockingFilter = CmsLockFilter.FILTER_ALL;
        nonBlockingFilter = nonBlockingFilter.filterLockableByUser(getCms().getRequestContext().currentUser());
        nonBlockingFilter = nonBlockingFilter.filterSharedExclusive();
        if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamProjectid())) {
            nonBlockingFilter = nonBlockingFilter.filterProject(new CmsUUID(getParamProjectid()));
        }
        return buildLockDialog(nonBlockingFilter, getBlockingFilter(), 0, true);
    }

    /**
     * @see org.opencms.workplace.CmsMultiDialog#buildLockHeaderBox()
     */
    public String buildLockHeaderBox() throws CmsException {

        if (isDirectPublish()) {
            return super.buildLockHeaderBox();
        }
        StringBuffer html = new StringBuffer(512);
        // include resource info  
        html.append(dialogBlockStart(null));
        html.append(key(org.opencms.workplace.Messages.GUI_LABEL_PROJECT_0));
        html.append(": ");
        html.append(getProjectname());
        html.append(dialogBlockEnd());
        return html.toString();
    }

    /**
     * Override to display additional options in the lock dialog.<p>
     * 
     * @return html code to display additional options
     */
    public String buildPublishOptions() {

        // show only for direct publish actions
        StringBuffer result = new StringBuffer(128);
        boolean showOptionSiblings = (isMultiOperation() || isOperationOnFolder() || (isDirectPublish()
            && hasSiblings() && hasCorrectLockstate()));
        boolean showOptionSubresources = (isMultiOperation() || isOperationOnFolder());

        result.append("<p>");
        if (showOptionSiblings) {
            // show only for multi resource operation or if resource has siblings and correct lock state
            if (!isMultiOperation() && !isOperationOnFolder()) {
                result.append(key(Messages.GUI_DELETE_WARNING_SIBLINGS_0));
                result.append("<br>");

⌨️ 快捷键说明

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