cmsdeletebrokenrelationslist.java

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

JAVA
386
字号
/*
 * File   : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsDeleteBrokenRelationsList.java,v $
 * Date   : $Date: 2007-08-29 13:30:25 $
 * Version: $Revision: 1.6 $
 *
 * 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.db.CmsUserSettings;
import org.opencms.file.CmsResource;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.OpenCms;
import org.opencms.relations.CmsRelation;
import org.opencms.relations.CmsRelationDeleteValidator;
import org.opencms.relations.CmsRelationValidatorInfoEntry;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.explorer.CmsResourceUtil;
import org.opencms.workplace.list.A_CmsListDialog;
import org.opencms.workplace.list.A_CmsListExplorerDialog;
import org.opencms.workplace.list.A_CmsListIndependentJsAction;
import org.opencms.workplace.list.CmsListColumnDefinition;
import org.opencms.workplace.list.CmsListIndependentAction;
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.I_CmsListAction;
import org.opencms.workplace.list.I_CmsListResourceCollector;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * List for resources with links that could get broken after deletion.<p>
 * 
 * @author Michael Moossen  
 * 
 * @version $Revision: 1.6 $ 
 * 
 * @since 6.5.4 
 */
public class CmsDeleteBrokenRelationsList extends A_CmsListExplorerDialog {

    /** list action id constant. */
    public static final String LIST_DETAIL_RELATIONS = "dr";

    /** list action id constant. */
    public static final String LIST_DETAIL_RELATIONS_HIDE = "drh";

    /** list action id constant. */
    public static final String LIST_DETAIL_RELATIONS_SHOW = "drs";

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

    /** The internal collector instance. */
    private I_CmsListResourceCollector m_collector;

    /** The broken relations validator object. */
    private CmsRelationDeleteValidator m_validator;

    /**
     * Public constructor.<p>
     * 
     * @param jsp an initialized JSP action element
     * @param resources the list of resources to check
     * @param includeSiblings if siblings should included
     */
    public CmsDeleteBrokenRelationsList(CmsJspActionElement jsp, List resources, boolean includeSiblings) {

        super(jsp, LIST_ID, Messages.get().container(Messages.GUI_DELETE_BROKENRELATIONS_LIST_NAME_0));
        String relativeTo = CmsResource.getParentFolder((String)resources.get(0));

        m_validator = new CmsRelationDeleteValidator(getCms(), resources, includeSiblings);
        List resourceList = new ArrayList(m_validator.keySet());
        Collections.sort(resourceList);

        m_collector = new CmsDeleteBrokenRelationsCollector(this, resourceList);

        // prevent paging
        getList().setMaxItemsPerPage(Integer.MAX_VALUE);

        // set the right resource util parameters
        CmsResourceUtil resUtil = getResourceUtil();
        resUtil.setAbbrevLength(50);
        resUtil.setRelativeTo(getCms().getRequestContext().addSiteRoot(relativeTo));
        resUtil.setSiteMode(CmsResourceUtil.SITE_MODE_MATCHING);
    }

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

        throwListUnsupportedActionException();
    }

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

        throwListUnsupportedActionException();
    }

    /**
     * @see org.opencms.workplace.list.A_CmsListExplorerDialog#getCollector()
     */
    public I_CmsListResourceCollector getCollector() {

        return m_collector;
    }

    /**
     * Returns the validator.<p>
     *
     * @return the validator
     */
    public CmsRelationDeleteValidator getValidator() {

        return m_validator;
    }

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

        // get content
        List resourceNames = getList().getAllContent();
        Iterator itResourceNames = resourceNames.iterator();
        while (itResourceNames.hasNext()) {
            CmsListItem item = (CmsListItem)itResourceNames.next();
            String resourceName = getResourceUtil(item).getResource().getRootPath();

            StringBuffer html = new StringBuffer(128);
            if (detailId.equals(LIST_DETAIL_RELATIONS)) {
                // relations
                CmsRelationValidatorInfoEntry infoEntry = m_validator.getInfoEntry(resourceName);
                Iterator itRelations = infoEntry.getRelations().iterator();

                // show all links that will get broken
                while (itRelations.hasNext()) {
                    CmsRelation relation = (CmsRelation)itRelations.next();
                    String relationName = relation.getSourcePath();
                    if (relationName.startsWith(infoEntry.getSiteRoot())) {
                        // same site
                        relationName = relationName.substring(infoEntry.getSiteRoot().length());
                        relationName = CmsStringUtil.formatResourceName(relationName, 50);
                    } else {
                        // other site
                        String site = OpenCms.getSiteManager().getSiteRoot(relationName);
                        String siteName = site;
                        if (site != null) {
                            relationName = relationName.substring(site.length());
                            siteName = OpenCms.getSiteManager().getSiteForSiteRoot(site).getTitle();
                        } else {
                            siteName = "/";
                        }
                        relationName = CmsStringUtil.formatResourceName(relationName, 50);
                        relationName = key(Messages.GUI_DELETE_SITE_RELATION_2, new Object[] {siteName, relationName});
                    }
                    html.append(relationName);
                    html.append("&nbsp;<span style='color: #666666;'>(");

⌨️ 快捷键说明

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