001/*
002 * File   : $Source$
003 * Date   : $Date$
004 * Version: $Revision$
005 *
006 * This library is part of OpenCms -
007 * the Open Source Content Management System
008 *
009 * Copyright (C) 2002 - 2009 Alkacon Software (http://www.alkacon.com)
010 *
011 * This library is free software; you can redistribute it and/or
012 * modify it under the terms of the GNU Lesser General Public
013 * License as published by the Free Software Foundation; either
014 * version 2.1 of the License, or (at your option) any later version.
015 *
016 * This library is distributed in the hope that it will be useful,
017 * but WITHOUT ANY WARRANTY; without even the implied warranty of
018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019 * Lesser General Public License for more details.
020 *
021 * For further information about Alkacon Software, please see the
022 * company website: http://www.alkacon.com
023 *
024 * For further information about OpenCms, please see the
025 * project website: http://www.opencms.org
026 *
027 * You should have received a copy of the GNU Lesser General Public
028 * License along with this library; if not, write to the Free Software
029 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
030 */
031
032package org.opencms.workplace.tools.sites;
033
034import org.opencms.file.CmsObject;
035import org.opencms.jsp.CmsJspActionElement;
036import org.opencms.main.CmsException;
037import org.opencms.main.OpenCms;
038import org.opencms.report.A_CmsReportThread;
039import org.opencms.report.I_CmsReport;
040import org.opencms.report.I_CmsReportThread;
041import org.opencms.util.CmsStringUtil;
042import org.opencms.workplace.list.A_CmsListReport;
043
044import javax.servlet.http.HttpServletRequest;
045import javax.servlet.http.HttpServletResponse;
046import javax.servlet.jsp.PageContext;
047
048/**
049 * Provides a report for removing sites.<p>
050 *
051 * @since 9.0.0
052 */
053public class CmsSitesRemoveReport extends A_CmsListReport {
054
055    /**
056     * Removes a site from the configuration.<p>
057     *
058     * @since 9.0.0
059     */
060    private class CmsSitesRemoveThread extends A_CmsReportThread {
061
062        /** The sites to remove. */
063        private String m_sites;
064
065        /**
066         * Public constructor.<p>
067         *
068         * @param cms the cms object
069         * @param sites the name of the thread
070         */
071        protected CmsSitesRemoveThread(CmsObject cms, String sites) {
072
073            super(cms, "site-remove-thread");
074            m_sites = sites;
075            initHtmlReport(cms.getRequestContext().getLocale());
076        }
077
078        /**
079         * @see org.opencms.report.A_CmsReportThread#getReportUpdate()
080         */
081        @Override
082        public String getReportUpdate() {
083
084            return getReport().getReportUpdate();
085        }
086
087        /**
088         * @see java.lang.Thread#run()
089         */
090        @Override
091        public void run() {
092
093            if (m_sites != null) {
094                for (String sitePath : CmsStringUtil.splitAsList(m_sites, ",")) {
095                    try {
096                        OpenCms.getSiteManager().removeSite(
097                            getCms(),
098                            OpenCms.getSiteManager().getSiteForSiteRoot(sitePath));
099                        getReport().println(
100                            Messages.get().container(Messages.RPT_REMOVED_SITE_SUCCESSFUL_1, sitePath),
101                            I_CmsReport.FORMAT_OK);
102                    } catch (CmsException e) {
103                        getReport().println(e);
104                    }
105                }
106            }
107        }
108    }
109
110    /** The paths of the sites to remove. */
111    private String m_paramSites;
112
113    /**
114     * Public constructor with JSP action element.<p>
115     *
116     * @param jsp an initialized JSP action element
117     */
118    public CmsSitesRemoveReport(CmsJspActionElement jsp) {
119
120        super(jsp);
121    }
122
123    /**
124     * Public constructor with JSP variables.<p>
125     *
126     * @param context the JSP page context
127     * @param req the JSP request
128     * @param res the JSP response
129     */
130    public CmsSitesRemoveReport(PageContext context, HttpServletRequest req, HttpServletResponse res) {
131
132        this(new CmsJspActionElement(context, req, res));
133    }
134
135    /**
136     * Returns the paths of the sites to remove.<p>
137     *
138     * @return the paths of the sites to remove
139     */
140    public String getParamSites() {
141
142        return m_paramSites;
143    }
144
145    /**
146     *
147     * @see org.opencms.workplace.list.A_CmsListReport#initializeThread()
148     */
149    @Override
150    public I_CmsReportThread initializeThread() {
151
152        return new CmsSitesRemoveThread(getCms(), m_paramSites);
153    }
154
155    /**
156     * Sets the sites parameter.<p>
157     *
158     * @param paramSites the paths of the sites to remove
159     */
160    public void setParamSites(String paramSites) {
161
162        m_paramSites = paramSites;
163    }
164}