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.configuration.CmsSearchConfiguration;
031import org.opencms.i18n.CmsMessageContainer;
032import org.opencms.jsp.CmsJspActionElement;
033import org.opencms.main.CmsRuntimeException;
034import org.opencms.main.OpenCms;
035import org.opencms.search.CmsSearchIndexSource;
036import org.opencms.search.CmsSearchManager;
037import org.opencms.search.I_CmsSearchIndex;
038import org.opencms.search.fields.CmsLuceneField;
039import org.opencms.search.fields.CmsSearchField;
040import org.opencms.search.fields.CmsSearchFieldMapping;
041import org.opencms.search.fields.I_CmsSearchFieldConfiguration;
042import org.opencms.search.fields.I_CmsSearchFieldMapping;
043import org.opencms.util.CmsStringUtil;
044import org.opencms.workplace.list.A_CmsListDialog;
045import org.opencms.workplace.list.CmsListColumnAlignEnum;
046import org.opencms.workplace.list.CmsListColumnDefinition;
047import org.opencms.workplace.list.CmsListDefaultAction;
048import org.opencms.workplace.list.CmsListDirectAction;
049import org.opencms.workplace.list.CmsListItem;
050import org.opencms.workplace.list.CmsListItemDetails;
051import org.opencms.workplace.list.CmsListItemDetailsFormatter;
052import org.opencms.workplace.list.CmsListMetadata;
053import org.opencms.workplace.list.CmsListMultiAction;
054import org.opencms.workplace.list.CmsListOrderEnum;
055import org.opencms.workplace.tools.CmsToolDialog;
056
057import java.io.IOException;
058import java.util.ArrayList;
059import java.util.HashMap;
060import java.util.Iterator;
061import java.util.List;
062import java.util.Map;
063
064import javax.servlet.ServletException;
065import javax.servlet.http.HttpServletRequest;
066import javax.servlet.http.HttpServletResponse;
067import javax.servlet.jsp.PageContext;
068
069/**
070 * A list that displays all search indexes of the OpenCms installation and offers
071 * operations on them.<p>
072 *
073 * @since 6.0.0
074 */
075public class CmsSearchIndexList extends A_CmsListDialog {
076
077    /** list action id constant. */
078    public static final String LIST_ACTION_DELETE = "ad";
079
080    /** list action id constant. */
081    public static final String LIST_ACTION_EDIT = "ae";
082
083    /** list action id constant. */
084    public static final String LIST_ACTION_INDEXSOURCES = "ais";
085
086    /** list action id constant. */
087    public static final String LIST_ACTION_REBUILD = "ar";
088
089    /** list action id constant. */
090    public static final String LIST_ACTION_SEARCH = "as";
091
092    /** list action id constant. */
093    public static final String LIST_ACTION_SEARCHINDEX_OVERVIEW = "asio";
094
095    /** list column id constant. */
096    public static final String LIST_COLUMN_CONFIGURATION = "cc";
097
098    /** list column id constant. */
099    public static final String LIST_COLUMN_DELETE = "cad";
100
101    /** list column id constant. */
102    public static final String LIST_COLUMN_EDIT = "cae";
103
104    /** list column id constant. */
105    public static final String LIST_COLUMN_INDEXSOURCES = "cis";
106
107    /** list column id constant. */
108    public static final String LIST_COLUMN_LOCALE = "cl";
109
110    /** list column id constant. */
111    public static final String LIST_COLUMN_NAME = "cn";
112
113    /** list column id constant. */
114    public static final String LIST_COLUMN_PROJECT = "cp";
115
116    /** list column id constant. */
117    public static final String LIST_COLUMN_REBUILD = "car";
118
119    /** list column id constant. */
120    public static final String LIST_COLUMN_REBUILDMODE = "cr";
121
122    /** list column id constant. */
123    public static final String LIST_COLUMN_SEARCH = "cas";
124
125    /** list item detail id constant. */
126    public static final String LIST_DETAIL_FIELDCONFIGURATION = "df";
127
128    /** list item detail id constant. */
129    public static final String LIST_DETAIL_INDEXSOURCE = "di";
130
131    /** list id constant. */
132    public static final String LIST_ID = "lssi";
133
134    /** list action id constant. */
135    public static final String LIST_MACTION_DELETE = "mad";
136
137    /** list action id constant. */
138    public static final String LIST_MACTION_REBUILD = "mar";
139
140    /** The path to the searchindex list icon (edit column). */
141    protected static final String LIST_ICON_INDEX = "tools/searchindex/icons/small/searchindex.png";
142
143    /** The path to the indexsource list icon. */
144    protected static final String LIST_ICON_INDEXSOURCE = "tools/searchindex/icons/small/indexsource.png";
145
146    /** The path to the rebuild multiple indexes icon. */
147    protected static final String LIST_ICON_REBUILD_MULTI = "tools/searchindex/icons/small/multi-rebuild.png";
148
149    /** The path to the rebuild single indexes icon. */
150    protected static final String LIST_ICON_REBUILD_SINGLE = "tools/searchindex/icons/small/rebuild.png";
151
152    /** The path to the search (within indexsource) list icon. */
153    protected static final String LIST_ICON_SEARCH = "buttons/preview.png";
154
155    /**
156     * Public constructor.<p>
157     *
158     * @param jsp an initialized JSP action element
159     */
160    public CmsSearchIndexList(CmsJspActionElement jsp) {
161
162        this(jsp, LIST_ID, Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_NAME_0));
163    }
164
165    /**
166     * Public constructor.<p>
167     *
168     * @param jsp an initialized JSP action element
169     * @param listId the id of the list
170     * @param listName the list name
171     */
172    public CmsSearchIndexList(CmsJspActionElement jsp, String listId, CmsMessageContainer listName) {
173
174        this(jsp, listId, listName, LIST_COLUMN_NAME, CmsListOrderEnum.ORDER_ASCENDING, null);
175    }
176
177    /**
178     * Public constructor.<p>
179     *
180     * @param jsp an initialized JSP action element
181     * @param listId the id of the displayed list
182     * @param listName the name of the list
183     * @param sortedColId the a priory sorted column
184     * @param sortOrder the order of the sorted column
185     * @param searchableColId the column to search into
186     */
187    public CmsSearchIndexList(
188        CmsJspActionElement jsp,
189        String listId,
190        CmsMessageContainer listName,
191        String sortedColId,
192        CmsListOrderEnum sortOrder,
193        String searchableColId) {
194
195        super(jsp, listId, listName, sortedColId, sortOrder, searchableColId);
196
197    }
198
199    /**
200     * Public constructor.<p>
201     *
202     * Public constructor with JSP variables.<p>
203     *
204     * @param context the JSP page context
205     * @param req the JSP request
206     * @param res the JSP response
207     */
208    public CmsSearchIndexList(PageContext context, HttpServletRequest req, HttpServletResponse res) {
209
210        this(new CmsJspActionElement(context, req, res));
211    }
212
213    /**
214     * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
215     */
216    @Override
217    public void executeListMultiActions() throws IOException, ServletException, CmsRuntimeException {
218
219        CmsSearchManager searchManager = OpenCms.getSearchManager();
220        Iterator<CmsListItem> itItems = getSelectedItems().iterator();
221        if (getParamListAction().equals(LIST_MACTION_DELETE)) {
222            // execute the delete multiaction
223            List<String> removedItems = new ArrayList<String>();
224            while (itItems.hasNext()) {
225                CmsListItem listItem = itItems.next();
226                searchManager.removeSearchIndex(searchManager.getIndex((String)listItem.get(LIST_COLUMN_NAME)));
227                removedItems.add(listItem.getId());
228            }
229            writeConfiguration(false);
230        } else if (getParamListAction().equals(LIST_MACTION_REBUILD)) {
231            // execute the rebuild multiaction
232            StringBuffer items = new StringBuffer();
233            while (itItems.hasNext()) {
234                CmsListItem listItem = itItems.next();
235                items.append(listItem.getId());
236                if (itItems.hasNext()) {
237                    items.append(',');
238                }
239            }
240            Map<String, String[]> params = new HashMap<String, String[]>();
241            params.put(CmsRebuildReport.PARAM_INDEXES, new String[] {items.toString()});
242            params.put(PARAM_ACTION, new String[] {DIALOG_INITIAL});
243            params.put(PARAM_STYLE, new String[] {CmsToolDialog.STYLE_NEW});
244            getToolManager().jspForwardTool(this, "/searchindex/singleindex/rebuildreport", params);
245        }
246        listSave();
247    }
248
249    /**
250     * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
251     */
252    @Override
253    public void executeListSingleActions() throws IOException, ServletException, CmsRuntimeException {
254
255        CmsSearchManager searchManager = OpenCms.getSearchManager();
256        String index = getSelectedItem().getId();
257
258        getCms().getRequestContext().setAttribute(A_CmsEditSearchIndexDialog.PARAM_INDEXNAME, index);
259
260        Map<String, String[]> params = new HashMap<String, String[]>();
261        params.put(CmsRebuildReport.PARAM_INDEXES, new String[] {index});
262        params.put(PARAM_ACTION, new String[] {DIALOG_INITIAL});
263        params.put(PARAM_STYLE, new String[] {CmsToolDialog.STYLE_NEW});
264        params.put(A_CmsEditSearchIndexDialog.PARAM_INDEXNAME, new String[] {index});
265
266        String action = getParamListAction();
267        if (action.equals(LIST_ACTION_DELETE)) {
268            searchManager.removeSearchIndex(searchManager.getIndex(index));
269            writeConfiguration(false);
270        } else if (action.equals(LIST_ACTION_REBUILD)) {
271            // forward to the rebuild index screen
272            getToolManager().jspForwardTool(this, "/searchindex/singleindex/rebuildreport", params);
273        } else if (action.equals(LIST_ACTION_SEARCH)) {
274            // forward to the search screen
275            getToolManager().jspForwardTool(this, "/searchindex/singleindex/search", params);
276        } else if (action.equals(LIST_ACTION_EDIT)) {
277            // forward to the edit index screen
278            params.remove(PARAM_ACTION);
279            getToolManager().jspForwardTool(this, "/searchindex/singleindex/edit", params);
280        } else if (action.equals(LIST_ACTION_SEARCHINDEX_OVERVIEW)) {
281            // forward to the index overview screen
282            getToolManager().jspForwardTool(this, "/searchindex/singleindex", params);
283        } else if (action.equals(LIST_ACTION_INDEXSOURCES)) {
284            // forward to the index source assignment screen
285            getToolManager().jspForwardTool(this, "/searchindex/singleindex/indexsources", params);
286        }
287        listSave();
288    }
289
290    /**
291     * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
292     */
293    @Override
294    protected void fillDetails(String detailId) {
295
296        // get content
297        List<CmsListItem> items = getList().getAllContent();
298        Iterator<CmsListItem> itItems = items.iterator();
299        CmsListItem item;
300        while (itItems.hasNext()) {
301            item = itItems.next();
302            if (detailId.equals(LIST_DETAIL_INDEXSOURCE)) {
303                fillDetailIndexSource(item, detailId);
304            } else if (detailId.equals(LIST_DETAIL_FIELDCONFIGURATION)) {
305                fillDetailFieldConfiguration(item, detailId);
306            }
307        }
308    }
309
310    /**
311     * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
312     */
313    @Override
314    protected List<CmsListItem> getListItems() {
315
316        List<CmsListItem> result = new ArrayList<CmsListItem>();
317        // get content
318        List<I_CmsSearchIndex> indexes = OpenCms.getSearchManager().getSearchIndexesAll();
319        for (I_CmsSearchIndex idx : indexes) {
320            I_CmsSearchIndex index = idx;
321            CmsListItem item = getList().newItem(index.getName());
322            item.set(LIST_COLUMN_NAME, index.getName());
323            item.set(LIST_COLUMN_CONFIGURATION, index.getFieldConfiguration().getName());
324            item.set(LIST_COLUMN_REBUILDMODE, index.getRebuildMode());
325            item.set(LIST_COLUMN_PROJECT, index.getProject());
326            item.set(LIST_COLUMN_LOCALE, index.getLocale().toString());
327            result.add(item);
328        }
329        return result;
330    }
331
332    /**
333     * @see org.opencms.workplace.CmsWorkplace#initMessages()
334     */
335    @Override
336    protected void initMessages() {
337
338        // add specific dialog resource bundle
339        addMessages(Messages.get().getBundleName());
340        // add default resource bundles
341        super.initMessages();
342    }
343
344    /**
345     * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
346     */
347    @Override
348    protected void setColumns(CmsListMetadata metadata) {
349
350        // create column for edit
351        CmsListColumnDefinition editCol = new CmsListColumnDefinition(LIST_COLUMN_EDIT);
352        editCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_EDIT_NAME_0));
353        editCol.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_EDIT_HELP_0));
354        editCol.setWidth("20");
355        editCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
356        editCol.setSorteable(false);
357        // add edit action
358        CmsListDirectAction editAction = new CmsListDirectAction(LIST_ACTION_EDIT);
359        editAction.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_ACTION_EDIT_NAME_0));
360        editAction.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_ACTION_EDIT_HELP_0));
361        editAction.setIconPath(LIST_ICON_INDEX);
362        editCol.addDirectAction(editAction);
363        // add it to the list definition
364        metadata.addColumn(editCol);
365
366        // create column for indexsource assignment
367        CmsListColumnDefinition sourceCol = new CmsListColumnDefinition(LIST_COLUMN_INDEXSOURCES);
368        sourceCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_INDEXSOURCES_NAME_0));
369        sourceCol.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_INDEXSOURCES_NAME_HELP_0));
370        sourceCol.setWidth("20");
371        sourceCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
372        sourceCol.setSorteable(false);
373        // add assign indexsource action
374        CmsListDirectAction sourceAction = new CmsListDirectAction(LIST_ACTION_INDEXSOURCES);
375        sourceAction.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_ACTION_INDEXSOURCES_NAME_0));
376        sourceAction.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_INDEXSOURCES_NAME_HELP_0));
377        sourceAction.setIconPath(LIST_ICON_INDEXSOURCE);
378        sourceCol.addDirectAction(sourceAction);
379        // add it to the list definition
380        metadata.addColumn(sourceCol);
381
382        // create column for deletion
383        CmsListColumnDefinition deleteCol = new CmsListColumnDefinition(LIST_COLUMN_DELETE);
384        deleteCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_DELETE_NAME_0));
385        deleteCol.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_DELETE_HELP_0));
386        deleteCol.setWidth("20");
387        deleteCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
388        deleteCol.setSorteable(false);
389        // add delete action
390        CmsListDirectAction deleteAction = new CmsListDirectAction(LIST_ACTION_DELETE);
391        deleteAction.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_ACTION_DELETE_NAME_0));
392        deleteAction.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_ACTION_DELETE_HELP_0));
393        deleteAction.setConfirmationMessage(
394            Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_ACTION_DELETE_CONF_0));
395        deleteAction.setIconPath(ICON_DELETE);
396        deleteCol.addDirectAction(deleteAction);
397        // add it to the list definition
398        metadata.addColumn(deleteCol);
399
400        // rebuild column
401        CmsListColumnDefinition rebuildCol = new CmsListColumnDefinition(LIST_COLUMN_REBUILD);
402        rebuildCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_REBUILD_NAME_0));
403        rebuildCol.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_REBUILD_HELP_0));
404        rebuildCol.setWidth("20");
405        rebuildCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
406        rebuildCol.setSorteable(false);
407        // add search action
408        CmsListDirectAction rebuildAction = new CmsListDirectAction(LIST_ACTION_REBUILD);
409        rebuildAction.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_ACTION_REBUILD_NAME_0));
410        rebuildAction.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_ACTION_REBUILD_HELP_0));
411        rebuildAction.setConfirmationMessage(
412            Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_ACTION_REBUILD_CONF_0));
413        rebuildAction.setIconPath(LIST_ICON_REBUILD_SINGLE);
414        rebuildCol.addDirectAction(rebuildAction);
415        // add it to the list definition
416        metadata.addColumn(rebuildCol);
417
418        // search column
419        CmsListColumnDefinition searchCol = new CmsListColumnDefinition(LIST_COLUMN_SEARCH);
420        searchCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_SEARCH_NAME_0));
421        searchCol.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_SEARCH_HELP_0));
422        searchCol.setWidth("20");
423        searchCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
424        searchCol.setSorteable(false);
425        // add search action
426        CmsListDirectAction searchAction = new CmsListDirectAction(LIST_ACTION_SEARCH) {
427
428            @Override
429            public boolean isEnabled() {
430
431                return CmsSearchManager.isLuceneIndex((String)getItem().get(LIST_COLUMN_NAME));
432            }
433        };
434        searchAction.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_ACTION_SEARCH_NAME_0));
435        searchAction.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_ACTION_SEARCH_HELP_0));
436        searchAction.setIconPath(LIST_ICON_SEARCH);
437        searchCol.addDirectAction(searchAction);
438        // add it to the list definition
439        metadata.addColumn(searchCol);
440
441        // add column for name
442        CmsListColumnDefinition nameCol = new CmsListColumnDefinition(LIST_COLUMN_NAME);
443        nameCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
444        nameCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_NAME_0));
445        nameCol.setWidth("35%");
446        // a default action for the link to overview
447        CmsListDefaultAction defEditAction = new CmsListDefaultAction(LIST_ACTION_SEARCHINDEX_OVERVIEW);
448        defEditAction.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_OVERVIEW_NAME_0));
449        defEditAction.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_OVERVIEW_HELP_0));
450        nameCol.addDefaultAction(defEditAction);
451        metadata.addColumn(nameCol);
452
453        // add column for field configuration
454        CmsListColumnDefinition configCol = new CmsListColumnDefinition(LIST_COLUMN_CONFIGURATION);
455        configCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
456        configCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_CONFIGURATION_0));
457        configCol.setWidth("15%");
458        metadata.addColumn(configCol);
459
460        // add column for rebuild mode
461        CmsListColumnDefinition rebuildModeCol = new CmsListColumnDefinition(LIST_COLUMN_REBUILDMODE);
462        rebuildModeCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
463        rebuildModeCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_REBUILDMODE_0));
464        rebuildModeCol.setWidth("5%");
465        metadata.addColumn(rebuildModeCol);
466
467        // add column for project
468        CmsListColumnDefinition projectCol = new CmsListColumnDefinition(LIST_COLUMN_PROJECT);
469        projectCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
470        projectCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_PROJECT_0));
471        projectCol.setWidth("30%");
472        metadata.addColumn(projectCol);
473
474        // add column for locale
475        CmsListColumnDefinition localeCol = new CmsListColumnDefinition(LIST_COLUMN_LOCALE);
476        localeCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT);
477        localeCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_LOCALE_0));
478        localeCol.setWidth("10%");
479        metadata.addColumn(localeCol);
480    }
481
482    /**
483     * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
484     */
485    @Override
486    protected void setIndependentActions(CmsListMetadata metadata) {
487
488        // add index source details
489        CmsListItemDetails indexDetails = new CmsListItemDetails(LIST_DETAIL_INDEXSOURCE);
490        indexDetails.setAtColumn(LIST_COLUMN_NAME);
491        indexDetails.setVisible(false);
492        indexDetails.setShowActionName(
493            Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_DETAIL_INDEXSOURCE_SHOW_0));
494        indexDetails.setShowActionHelpText(
495            Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_DETAIL_INDEXSOURCE_SHOW_HELP_0));
496        indexDetails.setHideActionName(
497            Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_DETAIL_INDEXSOURCE_HIDE_0));
498        indexDetails.setHideActionHelpText(
499            Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_DETAIL_INDEXSOURCE_HIDE_HELP_0));
500        indexDetails.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_DETAIL_INDEXSOURCE_NAME_0));
501        indexDetails.setFormatter(
502            new CmsListItemDetailsFormatter(
503                Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_DETAIL_INDEXSOURCE_NAME_0)));
504        metadata.addItemDetails(indexDetails);
505
506        // add field configuration details
507        CmsListItemDetails configDetails = new CmsListItemDetails(LIST_DETAIL_FIELDCONFIGURATION);
508        configDetails.setAtColumn(LIST_COLUMN_NAME);
509        configDetails.setVisible(false);
510        configDetails.setShowActionName(
511            Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_DETAIL_FIELDCONFIGURATION_SHOW_0));
512        configDetails.setShowActionHelpText(
513            Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_DETAIL_FIELDCONFIGURATION_SHOW_HELP_0));
514        configDetails.setHideActionName(
515            Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_DETAIL_FIELDCONFIGURATION_HIDE_0));
516        configDetails.setHideActionHelpText(
517            Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_DETAIL_FIELDCONFIGURATION_HIDE_HELP_0));
518        configDetails.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_DETAIL_FIELDCONFIGURATION_NAME_0));
519        configDetails.setFormatter(
520            new CmsListItemDetailsFormatter(
521                Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_DETAIL_FIELDCONFIGURATION_NAME_0)));
522        metadata.addItemDetails(configDetails);
523    }
524
525    /**
526     * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
527     */
528    @Override
529    protected void setMultiActions(CmsListMetadata metadata) {
530
531        // add delete multi action
532        CmsListMultiAction deleteMultiAction = new CmsListMultiAction(LIST_MACTION_DELETE);
533        deleteMultiAction.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_MACTION_DELETE_NAME_0));
534        deleteMultiAction.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_MACTION_DELETE_HELP_0));
535        deleteMultiAction.setConfirmationMessage(
536            Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_MACTION_DELETE_CONF_0));
537        deleteMultiAction.setIconPath(ICON_MULTI_DELETE);
538        metadata.addMultiAction(deleteMultiAction);
539
540        // add rebuild multi action
541        CmsListMultiAction rebuildMultiAction = new CmsListMultiAction(LIST_MACTION_REBUILD);
542        rebuildMultiAction.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_MACTION_REBUILD_NAME_0));
543        rebuildMultiAction.setHelpText(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_MACTION_REBUILD_HELP_0));
544        rebuildMultiAction.setConfirmationMessage(
545            Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_MACTION_REBUILD_CONF_0));
546        rebuildMultiAction.setIconPath(LIST_ICON_REBUILD_MULTI);
547        metadata.addMultiAction(rebuildMultiAction);
548
549    }
550
551    /**
552     * Writes the updated search configuration back to the XML
553     * configuration file and refreshes the complete list.<p>
554     *
555     * @param refresh if true, the list items are refreshed
556     */
557    protected void writeConfiguration(boolean refresh) {
558
559        // update the XML configuration
560        OpenCms.writeConfiguration(CmsSearchConfiguration.class);
561        if (refresh) {
562            refreshList();
563        }
564    }
565
566    /**
567     * Fills details of the field configuration into the given item. <p>
568     *
569     * @param item the list item to fill
570     * @param detailId the id for the detail to fill
571     */
572    private void fillDetailFieldConfiguration(CmsListItem item, String detailId) {
573
574        // search for the corresponding A_CmsSearchIndex:
575        String idxName = (String)item.get(LIST_COLUMN_NAME);
576        I_CmsSearchIndex idx = OpenCms.getSearchManager().getIndex(idxName);
577        if (idx != null) {
578            StringBuffer html = new StringBuffer();
579            I_CmsSearchFieldConfiguration idxFieldConfiguration = idx.getFieldConfiguration();
580            List<CmsSearchField> fields = idxFieldConfiguration.getFields();
581
582            html.append("<ul>\n");
583            html.append("  <li>\n").append("    ").append("name      : ").append(
584                idxFieldConfiguration.getName()).append("\n");
585            html.append("  </li>");
586            html.append("  <li>\n").append("    ").append("fields : ").append("\n");
587            html.append("    <ul>\n");
588
589            Iterator<CmsSearchField> itFields = fields.iterator();
590            while (itFields.hasNext()) {
591                CmsLuceneField field = (CmsLuceneField)itFields.next();
592                String fieldName = field.getName();
593                boolean fieldStore = field.isStored();
594                String fieldIndex = field.getIndexed();
595                boolean fieldExcerpt = field.isInExcerpt();
596                String fieldDefault = field.getDefaultValue();
597
598                html.append("  <li>\n").append("    ");
599                html.append("name=").append(fieldName);
600                if (fieldStore) {
601                    html.append(", ").append("store=").append(fieldStore);
602                }
603                if (!fieldIndex.equals("false")) {
604                    html.append(", ").append("index=").append(fieldIndex);
605                }
606                if (fieldExcerpt) {
607                    html.append(", ").append("excerpt=").append(fieldExcerpt);
608                }
609                if (fieldDefault != null) {
610                    html.append(", ").append("default=").append(field.getDefaultValue());
611                }
612                html.append("\n").append("    <ul>\n");
613
614                Iterator<I_CmsSearchFieldMapping> itMappings = field.getMappings().iterator();
615                while (itMappings.hasNext()) {
616                    CmsSearchFieldMapping mapping = (CmsSearchFieldMapping)itMappings.next();
617                    html.append("  <li>\n").append("    ");
618                    html.append(mapping.getType().toString());
619                    if (CmsStringUtil.isNotEmpty(mapping.getParam())) {
620                        html.append("=").append(mapping.getParam()).append("\n");
621                    }
622                    html.append("  </li>");
623                }
624                html.append("    </ul>\n");
625                html.append("  </li>");
626            }
627            html.append("    </ul>\n");
628            html.append("  </li>");
629            html.append("</ul>\n");
630            item.set(detailId, html.toString());
631        }
632    }
633
634    /**
635     * Fills details of the index source into the given item. <p>
636     *
637     * @param item the list item to fill
638     * @param detailId the id for the detail to fill
639     *
640     */
641    private void fillDetailIndexSource(CmsListItem item, String detailId) {
642
643        StringBuffer html = new StringBuffer();
644        // search for the corresponding A_CmsSearchIndex:
645        I_CmsSearchIndex idx = OpenCms.getSearchManager().getIndex((String)item.get(LIST_COLUMN_NAME));
646
647        html.append("<ul>\n");
648        // get the index sources (nice API)
649        for (CmsSearchIndexSource idxSource : idx.getSources()) {
650            html.append("  <li>\n").append("    ").append("name      : ").append(idxSource.getName()).append("\n");
651            html.append("  </li>");
652
653            html.append("  <li>\n").append("    ").append("indexer   : ").append(
654                idxSource.getIndexerClassName()).append("\n");
655            html.append("  </li>");
656
657            html.append("  <li>\n").append("    ").append("resources : ").append("\n");
658            html.append("    <ul>\n");
659            List<String> resources = idxSource.getResourcesNames();
660            Iterator<String> itResources = resources.iterator();
661            while (itResources.hasNext()) {
662                html.append("    <li>\n").append("      ").append(itResources.next()).append("\n");
663                html.append("    </li>\n");
664            }
665            html.append("    </ul>\n");
666            html.append("  </li>");
667
668            html.append("  <li>\n").append("    ").append("doctypes : ").append("\n");
669            html.append("    <ul>\n");
670            resources = idxSource.getDocumentTypes();
671            itResources = resources.iterator();
672            while (itResources.hasNext()) {
673                html.append("    <li>\n").append("      ").append(itResources.next()).append("\n");
674                html.append("    </li>\n");
675            }
676            html.append("    </ul>\n");
677            html.append("  </li>");
678        }
679
680        html.append("</ul>\n");
681        item.set(detailId, html.toString());
682    }
683}