<commit_before>/*
 * File   : $Source$
 * Date   : $Date$
 * Version: $Revision$
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (C) 2002 - 2009 Alkacon Software (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, 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.sites;

import org.opencms.configuration.CmsSystemConfiguration;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsRuntimeException;
import org.opencms.main.OpenCms;
import org.opencms.site.CmsSite;
import org.opencms.site.CmsSiteMatcher;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.list.A_CmsListDialog;
import org.opencms.workplace.list.CmsListColumnAlignEnum;
import org.opencms.workplace.list.CmsListColumnDefinition;
import org.opencms.workplace.list.CmsListDefaultAction;
import org.opencms.workplace.list.CmsListDirectAction;
import org.opencms.workplace.list.CmsListItem;
import org.opencms.workplace.list.CmsListItemActionIconComparator;
import org.opencms.workplace.list.CmsListItemDetails;
import org.opencms.workplace.list.CmsListItemDetailsFormatter;
import org.opencms.workplace.list.CmsListMetadata;
import org.opencms.workplace.list.CmsListMultiAction;
import org.opencms.workplace.list.CmsListOrderEnum;
import org.opencms.workplace.tools.CmsToolDialog;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

/**
 * Main site management view.<p>
 * 
 * @since 9.0.0 
 */
public class CmsSitesOverviewList extends A_CmsListDialog {

    /** The message key prefix to be used for widget labels. */
    public static final String KEY_PREFIX_SITES = "sites";

    /** The inactive icon for single delete action. */
    protected static final String ICON_DELETE_INACTIVE = "list/delete_inactive.png";

    /** List column id. */
    protected static final String LIST_COLUMN_ACTIVE = "wsi";

    /** The path of the fav icon. */
    protected static final String LIST_ICON_FAVICON = "tools/sites/icons/small/default-favicon.png";

    /** Holds - keys: site roots and values: favicon links. */
    protected static Map<String, String> m_icons = new HashMap<String, String>();

    /** A parameter name for the title of the site. */
    protected static final String PARAM_SITE_TITLE = "sitetitle";

    /** A parameter name for a comma separated list of site paths. */
    protected static final String PARAM_SITES = "sites";

    /** Path to the reports. */
    protected static final String PATH_REPORTS = "/system/workplace/admin/sites/reports/";

    /** The favorite upload dialog. */
    private static final String DIALOG_FAV = "fav";

    /** List action id. */
    private static final String LIST_ACTION_ACTIVATE = "wsa";

    /** List action id. */
    private static final String LIST_ACTION_DEACTIVATE = "wsd";

    /** List default action for editing a site. */
    private static final String LIST_ACTION_DEFAULT = "da";

    /** List action for editing a site. */
    private static final String LIST_ACTION_EDIT = "ea";

    /** List action for uploading a favicon. */
    private static final String LIST_ACTION_FAVICON = "fa";

    /** List action for removing a site. */
    private static final String LIST_ACTION_REMOVE = "ra";

    /** List column id. */
    private static final String LIST_COLUMN_ACTIVATE = "wsc";

    /** List column id for editing a site. */
    private static final String LIST_COLUMN_EDIT = "ce";

    /** List column id for the favicon. */
    private static final String LIST_COLUMN_FAVICON = "fav";

    /** List column id for the site path. */
    private static final String LIST_COLUMN_PATH = "cp";

    /** List column id for removing a site. */
    private static final String LIST_COLUMN_REMOVE = "cr";

    /** List column id for the site server's URL. */
    private static final String LIST_COLUMN_SERVER = "cs";

    /** List column id for the site name. */
    private static final String LIST_COLUMN_TITLE = "cn";

    /** Identifier for the show aliases action. */
    private static final String LIST_DETAIL_ALIASES = "ad";

    /** Identifier for the show secure sites action. */
    private static final String LIST_DETAIL_SECURE = "sd";

    /** Path to the edit icon. */
    private static final String LIST_ICON_EDIT = "tools/sites/icons/small/sites.png";

    /** Identifier for the remove multi action. */
    private static final String LIST_MACTION_REMOVE = "rma";

    /** Id for the list of sites. */
    private static final String LIST_SITES_ID = "sites";

    /** A parameter name for the edit action. */
    private static final String PARAM_EDIT_ACTION = "editaction";

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

        super(
            jsp,
            LIST_SITES_ID,
            Messages.get().container(Messages.GUI_SITES_LIST_NAME_0),
            LIST_COLUMN_PATH,
            CmsListOrderEnum.ORDER_ASCENDING,
            null);
    }

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

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

    /**
     * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
     */
    @Override
    public void executeListMultiActions() throws IOException, ServletException {

        if (getParamListAction().equals(LIST_MACTION_REMOVE)) {
            List<String> selectedSites = new ArrayList<String>();
            for (CmsListItem item : getSelectedItems()) {
                selectedSites.add(item.getId());
            }
            Map<String, String[]> params = new HashMap<String, String[]>();
            params.put(PARAM_SITES, new String[] {CmsStringUtil.listAsString(selectedSites, ",")});
            params.put(PARAM_ACTION, new String[] {DIALOG_INITIAL});
            params.put(PARAM_STYLE, new String[] {CmsToolDialog.STYLE_NEW});
            getToolManager().jspForwardPage(this, PATH_REPORTS + "remove.jsp", params);
        }
        listSave();
    }

    /**
     * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
     */
    @Override
    public void executeListSingleActions() throws IOException, ServletException {<commit_msg>Also prevent deletion of the default site for multi-action.<commit_after>/*
 * File   : $Source$
 * Date   : $Date$
 * Version: $Revision$
 *
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (C) 2002 - 2009 Alkacon Software (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, 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.sites;

import org.opencms.configuration.CmsSystemConfiguration;
import org.opencms.file.CmsObject;
import org.opencms.file.CmsResource;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.main.CmsException;
import org.opencms.main.CmsRuntimeException;
import org.opencms.main.OpenCms;
import org.opencms.site.CmsSite;
import org.opencms.site.CmsSiteMatcher;
import org.opencms.util.CmsStringUtil;
import org.opencms.workplace.CmsWorkplace;
import org.opencms.workplace.list.A_CmsListDialog;
import org.opencms.workplace.list.CmsListColumnAlignEnum;
import org.opencms.workplace.list.CmsListColumnDefinition;
import org.opencms.workplace.list.CmsListDefaultAction;
import org.opencms.workplace.list.CmsListDirectAction;
import org.opencms.workplace.list.CmsListItem;
import org.opencms.workplace.list.CmsListItemActionIconComparator;
import org.opencms.workplace.list.CmsListItemDetails;
import org.opencms.workplace.list.CmsListItemDetailsFormatter;
import org.opencms.workplace.list.CmsListMetadata;
import org.opencms.workplace.list.CmsListMultiAction;
import org.opencms.workplace.list.CmsListOrderEnum;
import org.opencms.workplace.tools.CmsToolDialog;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

/**
 * Main site management view.<p>
 * 
 * @since 9.0.0 
 */
public class CmsSitesOverviewList extends A_CmsListDialog {

    /** The message key prefix to be used for widget labels. */
    public static final String KEY_PREFIX_SITES = "sites";

    /** The inactive icon for single delete action. */
    protected static final String ICON_DELETE_INACTIVE = "list/delete_inactive.png";

    /** List column id. */
    protected static final String LIST_COLUMN_ACTIVE = "wsi";

    /** The path of the fav icon. */
    protected static final String LIST_ICON_FAVICON = "tools/sites/icons/small/default-favicon.png";

    /** Holds - keys: site roots and values: favicon links. */
    protected static Map<String, String> m_icons = new HashMap<String, String>();

    /** A parameter name for the title of the site. */
    protected static final String PARAM_SITE_TITLE = "sitetitle";

    /** A parameter name for a comma separated list of site paths. */
    protected static final String PARAM_SITES = "sites";

    /** Path to the reports. */
    protected static final String PATH_REPORTS = "/system/workplace/admin/sites/reports/";

    /** The favorite upload dialog. */
    private static final String DIALOG_FAV = "fav";

    /** List action id. */
    private static final String LIST_ACTION_ACTIVATE = "wsa";

    /** List action id. */
    private static final String LIST_ACTION_DEACTIVATE = "wsd";

    /** List default action for editing a site. */
    private static final String LIST_ACTION_DEFAULT = "da";

    /** List action for editing a site. */
    private static final String LIST_ACTION_EDIT = "ea";

    /** List action for uploading a favicon. */
    private static final String LIST_ACTION_FAVICON = "fa";

    /** List action for removing a site. */
    private static final String LIST_ACTION_REMOVE = "ra";

    /** List column id. */
    private static final String LIST_COLUMN_ACTIVATE = "wsc";

    /** List column id for editing a site. */
    private static final String LIST_COLUMN_EDIT = "ce";

    /** List column id for the favicon. */
    private static final String LIST_COLUMN_FAVICON = "fav";

    /** List column id for the site path. */
    private static final String LIST_COLUMN_PATH = "cp";

    /** List column id for removing a site. */
    private static final String LIST_COLUMN_REMOVE = "cr";

    /** List column id for the site server's URL. */
    private static final String LIST_COLUMN_SERVER = "cs";

    /** List column id for the site name. */
    private static final String LIST_COLUMN_TITLE = "cn";

    /** Identifier for the show aliases action. */
    private static final String LIST_DETAIL_ALIASES = "ad";

    /** Identifier for the show secure sites action. */
    private static final String LIST_DETAIL_SECURE = "sd";

    /** Path to the edit icon. */
    private static final String LIST_ICON_EDIT = "tools/sites/icons/small/sites.png";

    /** Identifier for the remove multi action. */
    private static final String LIST_MACTION_REMOVE = "rma";

    /** Id for the list of sites. */
    private static final String LIST_SITES_ID = "sites";

    /** A parameter name for the edit action. */
    private static final String PARAM_EDIT_ACTION = "editaction";

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

        super(
            jsp,
            LIST_SITES_ID,
            Messages.get().container(Messages.GUI_SITES_LIST_NAME_0),
            LIST_COLUMN_PATH,
            CmsListOrderEnum.ORDER_ASCENDING,
            null);
    }

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

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

    /**
     * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
     */
    @Override
    public void executeListMultiActions() throws IOException, ServletException {

        if (getParamListAction().equals(LIST_MACTION_REMOVE)) {
            List<String> selectedSites = new ArrayList<String>();
            for (CmsListItem item : getSelectedItems()) {
                if (!OpenCms.getSiteManager().getDefaultSite().getSiteRoot().equals(item.getId())) {
                    selectedSites.add(item.getId());
                }
            }
            Map<String, String[]> params = new HashMap<String, String[]>();
            params.put(PARAM_SITES, new String[] {CmsStringUtil.listAsString(selectedSites, ",")});
            params.put(PARAM_ACTION, new String[] {DIALOG_INITIAL});
            params.put(PARAM_STYLE, new String[] {CmsToolDialog.STYLE_NEW});
            getToolManager().jspForwardPage(this, PATH_REPORTS + "remove.jsp", params);
        }
        listSave();
    }

    /**
     * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
     */
    @Override
    public void executeListSingleActions() throws IOException, ServletException {
{'fraction_non_alphanumeric': 0.09704668148618609, 'fraction_numerical': 0.003556684661797396, 'mean_word_length': 3.3617728531855957, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3437797', 'n_tokens_mistral': 4746, 'n_tokens_neox': 4583, 'n_words': 1394}