001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workplace.tools.searchindex;
029
030import org.opencms.jsp.CmsJspActionElement;
031import org.opencms.workplace.tools.CmsToolManager;
032
033import java.util.ArrayList;
034import java.util.List;
035
036import javax.servlet.http.HttpServletRequest;
037import javax.servlet.http.HttpServletResponse;
038import javax.servlet.jsp.PageContext;
039
040/**
041 * A <code>CmsWidgetDialog</code> that starts a (confirmed) delete dialog for
042 * a search index.<p>
043 *
044 * @since 6.0.0
045 */
046public class CmsDeleteSearchIndexDialog extends A_CmsEditSearchIndexDialog {
047
048    /**
049     * Public constructor with JSP action element.<p>
050     *
051     * @param jsp an initialized JSP action element
052     */
053
054    public CmsDeleteSearchIndexDialog(CmsJspActionElement jsp) {
055
056        super(jsp);
057
058    }
059
060    /**
061     * Public constructor with JSP variables.<p>
062     *
063     * @param context the JSP page context
064     * @param req the JSP request
065     * @param res the JSP response
066     */
067
068    public CmsDeleteSearchIndexDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
069
070        super(context, req, res);
071
072    }
073
074    /**
075     * Commits the edited search index to the search manager.<p>
076     */
077    @Override
078    public void actionCommit() {
079
080        List<Throwable> errors = new ArrayList<Throwable>();
081
082        try {
083
084            m_searchManager.removeSearchIndex(getSearchIndexIndex());
085            clearDialogObject();
086            writeConfiguration();
087            // if we go back to /searchindex/singleindex (overview) the deleted searchindex is not
088            // there any more in the CmsSearchManager and CmsOverviewSearchIndex.getUserObject will
089            // find null -> defineWidgets will provide null as bean...
090            setParamCloseLink(CmsToolManager.linkForToolPath(getJsp(), getParentPath()));
091        } catch (Throwable t) {
092            errors.add(t);
093        }
094        // set the list of errors to display when saving failed
095        setCommitErrors(errors);
096    }
097
098    /**
099     * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
100     *
101     * This overwrites the method from the super class to create a layout variation for the widgets.<p>
102     *
103     * @param dialog the dialog (page) to get the HTML for
104     * @return the dialog HTML for all defined widgets of the named dialog (page)
105     */
106    @Override
107    protected String createDialogHtml(String dialog) {
108
109        StringBuffer result = new StringBuffer(512);
110
111        result.append(createWidgetTableStart());
112        // show error header once if there were validation errors
113        result.append(createWidgetErrorHeader());
114
115        if (dialog.equals(PAGES[0])) {
116            // create the widgets for the first dialog page
117            result.append(dialogBlockStart(key(Messages.GUI_LIST_SEARCHINDEX_MACTION_DELETE_NAME_0)));
118            result.append(createWidgetTableStart());
119            result.append(key(
120                Messages.GUI_LIST_SEARCHINDEX_ACTION_DELETE_CONF_1,
121                new Object[] {getSearchIndexIndex().getName()}));
122            result.append(createWidgetTableEnd());
123            result.append(dialogBlockEnd());
124        }
125
126        result.append(createWidgetTableEnd());
127
128        // See CmsWidgetDialog.dialogButtonsCustom(): if no widgets are defined that are non-display-only widgets,
129        // no dialog buttons (Ok, Cancel) will be visible....
130        result.append(dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL}, new String[2]));
131        return result.toString();
132    }
133
134}