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.CmsToolDialog;
032
033import java.util.ArrayList;
034import java.util.HashMap;
035import java.util.List;
036import java.util.Map;
037
038import javax.servlet.http.HttpServletRequest;
039import javax.servlet.http.HttpServletResponse;
040import javax.servlet.jsp.PageContext;
041
042/**
043 * A <code>CmsWidgetDialog</code> that starts a (confirmed) rebuild dialog for
044 * a search index.<p>
045 *
046 * @since 6.0.0
047 */
048public class CmsRebuildSearchIndexDialog extends A_CmsEditSearchIndexDialog {
049
050    /**
051     * Public constructor with JSP action element.<p>
052     *
053     * @param jsp an initialized JSP action element
054     */
055
056    public CmsRebuildSearchIndexDialog(CmsJspActionElement jsp) {
057
058        super(jsp);
059
060    }
061
062    /**
063     * Public constructor with JSP variables.<p>
064     *
065     * @param context the JSP page context
066     * @param req the JSP request
067     * @param res the JSP response
068     */
069
070    public CmsRebuildSearchIndexDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
071
072        super(context, req, res);
073
074    }
075
076    /**
077     * Commits the edited search index to the search manager.<p>
078     */
079    @Override
080    public void actionCommit() {
081
082        List<Throwable> errors = new ArrayList<Throwable>();
083
084        try {
085            // forward to the rebuild report page
086            Map<String, String[]> params = new HashMap<String, String[]>();
087            // rebuild report built for several indexes (comma-separated value string)
088            params.put(CmsRebuildReport.PARAM_INDEXES, new String[] {getSearchIndexIndex().getName()});
089            params.put(PARAM_STYLE, new String[] {CmsToolDialog.STYLE_NEW});
090            getToolManager().jspForwardTool(this, "/searchindex/singleindex/rebuildreport", params);
091
092        } catch (Throwable t) {
093            errors.add(t);
094        }
095        // set the list of errors to display when saving failed
096        setCommitErrors(errors);
097    }
098
099    /**
100     * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
101     *
102     * This overwrites the method from the super class to create a layout variation for the widgets.<p>
103     *
104     * @param dialog the dialog (page) to get the HTML for
105     * @return the dialog HTML for all defined widgets of the named dialog (page)
106     */
107    @Override
108    protected String createDialogHtml(String dialog) {
109
110        StringBuffer result = new StringBuffer(512);
111
112        result.append(createWidgetTableStart());
113        // show error header once if there were validation errors
114        result.append(createWidgetErrorHeader());
115
116        if (dialog.equals(PAGES[0])) {
117            // create the widgets for the first dialog page
118            result.append(dialogBlockStart(key(Messages.GUI_LIST_SEARCHINDEX_ACTION_REBUILD_NAME_0)));
119            result.append(createWidgetTableStart());
120            result.append(key(
121                Messages.GUI_LIST_SEARCHINDEX_ACTION_REBUILD_NAME_CONF_1,
122                new Object[] {getSearchIndexIndex().getName()}));
123            result.append(createWidgetTableEnd());
124            result.append(dialogBlockEnd());
125        }
126
127        result.append(createWidgetTableEnd());
128
129        // See CmsWidgetDialog.dialogButtonsCustom(): if no widgets are defined that are non-display-only widgets,
130        // no dialog buttons (Ok, Cancel) will be visible....
131        result.append(dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL}, new String[2]));
132        return result.toString();
133    }
134
135}