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

📄 cmspropertydelete.java

📁 cms是开源的框架
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/content/CmsPropertyDelete.java,v $
 * Date   : $Date: 2006/03/31 13:59:16 $
 * Version: $Revision: 1.16 $
 *
 * 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.content;

import org.opencms.file.CmsProperty;
import org.opencms.file.CmsPropertyDefinition;
import org.opencms.file.CmsResource;
import org.opencms.file.CmsVfsException;
import org.opencms.i18n.CmsMessages;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.lock.CmsLock;
import org.opencms.main.CmsException;
import org.opencms.main.OpenCms;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsWorkplaceSettings;

import java.util.ArrayList;
import java.util.Collections;
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;

/**
 * Provides methods for the delete property definition dialog.<p> 
 *
 * @author  Andreas Zahner 
 * @author  Armen Markarian 
 * 
 * @version $Revision: 1.16 $ 
 * 
 * @since 6.0.0 
 */
public class CmsPropertyDelete extends CmsDialog {

    /** Value for the action: delete cascade. */
    public static final int ACTION_DELETE_CASCADE = 100;

    /** Request parameter value for the action: delete cascade. */
    public static final String DIALOG_DELETE_CASCADE = "deletecascade";

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

    /** Request parameter name for the property name. */
    public static final String PARAM_PROPERTYNAME = "propertyname";

    private String m_paramPropertyName;

    /**
     * Public constructor with JSP action element.<p>
     * 
     * @param jsp an initialized JSP action element
     */
    public CmsPropertyDelete(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 CmsPropertyDelete(PageContext context, HttpServletRequest req, HttpServletResponse res) {

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

    /**
     * Deletes the property definition.<p>
     * 
     * @throws JspException if problems including sub-elements occur
     */
    public void actionDelete() throws JspException {

        // save initialized instance of this class in request attribute for included sub-elements
        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
        try {
            getCms().deletePropertyDefinition(getParamPropertyName());
            // close the dialog
            actionCloseDialog();
        } catch (Throwable e) {
            // error while deleting property definition, show error dialog
            includeErrorpage(this, e);
        }
    }

    /**
     * Deletes the property definition by cascading the properties on resources.<p>
     * 
     * @throws JspException if problems including sub-elements occur
     */
    public void actionDeleteCascade() throws JspException {
        

        // save initialized instance of this class in request attribute for included sub-elements
        getJsp().getRequest().setAttribute(SESSION_WORKPLACE_CLASS, this);
        try {
            // list of all resources containing this propertydefinition
            List resourcesWithProperty = getCms().readResourcesWithProperty(getParamPropertyName());
            // list of all resources locked by another user, containing this propertydefinition
            List resourcesLockedByOtherUser = getResourcesLockedByOtherUser(resourcesWithProperty);
            // do the following operations only if all of the resources are not locked by another user
            if (resourcesLockedByOtherUser.isEmpty()) {
                // save the site root
                getCms().getRequestContext().saveSiteRoot();
                // change to the root site
                getCms().getRequestContext().setSiteRoot("/");
                try {
                    Iterator i = resourcesWithProperty.iterator();
                    while (i.hasNext()) {
                        CmsResource resource = (CmsResource)i.next();
                        // read the property object
                        CmsProperty property = getCms().readPropertyObject(
                            resource.getRootPath(),
                            getParamPropertyName(),
                            false);
                        // try to delete the property if it is not the NULL PROPERTY
                        // if the property is the NULL PROPERTY, it only had a shared 
                        // value which was deleted at a sibling which was already processed
                        if (!property.isNullProperty()) {
                            CmsLock lock = getCms().getLock(resource);
                            if (lock.getType() == CmsLock.TYPE_UNLOCKED) {
                                // lock the resource for the current (Admin) user
                                getCms().lockResource(resource.getRootPath());
                            }
                            property.setStructureValue(CmsProperty.DELETE_VALUE);
                            property.setResourceValue(CmsProperty.DELETE_VALUE);
                            // write the property with the null value to the resource and cascade it from the definition
                            getCms().writePropertyObject(resource.getRootPath(), property);
                            // unlock the resource
                            getCms().unlockResource(resource.getRootPath());
                        }
                    }
                    // delete the property definition at last
                    getCms().deletePropertyDefinition(getParamPropertyName());
                } finally {
                    // restore the siteroot
                    getCms().getRequestContext().restoreSiteRoot();
                    // close the dialog
                    actionCloseDialog();
                }
            } else {

                StringBuffer reason = new StringBuffer();
                reason.append(dialogWhiteBoxStart());
                reason.append(buildResourceList(resourcesLockedByOtherUser, true));
                reason.append(dialogWhiteBoxEnd());
                throw new CmsVfsException(Messages.get().container(
                    Messages.ERR_DEL_PROP_RESOURCES_LOCKED_1,
                    reason.toString()));
            }
        } catch (Throwable e) {
            // error while deleting property definition, show error dialog
            includeErrorpage(this, e);
        }
    }

⌨️ 快捷键说明

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