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.CmsLog; 034import org.opencms.main.OpenCms; 035import org.opencms.search.CmsSearchManager; 036import org.opencms.search.fields.CmsLuceneField; 037import org.opencms.search.fields.CmsSearchField; 038import org.opencms.search.fields.CmsSearchFieldMapping; 039import org.opencms.search.fields.I_CmsSearchFieldConfiguration; 040import org.opencms.search.fields.I_CmsSearchFieldMapping; 041import org.opencms.util.CmsStringUtil; 042import org.opencms.workplace.list.CmsListColumnAlignEnum; 043import org.opencms.workplace.list.CmsListColumnDefinition; 044import org.opencms.workplace.list.CmsListDefaultAction; 045import org.opencms.workplace.list.CmsListDirectAction; 046import org.opencms.workplace.list.CmsListItem; 047import org.opencms.workplace.list.CmsListItemDetails; 048import org.opencms.workplace.list.CmsListItemDetailsFormatter; 049import org.opencms.workplace.list.CmsListMetadata; 050import org.opencms.workplace.list.CmsListMultiAction; 051import org.opencms.workplace.list.CmsListOrderEnum; 052import org.opencms.workplace.tools.CmsToolDialog; 053 054import java.io.IOException; 055import java.util.ArrayList; 056import java.util.Collections; 057import java.util.HashMap; 058import java.util.Iterator; 059import java.util.List; 060import java.util.Map; 061 062import javax.servlet.ServletException; 063 064import org.apache.commons.logging.Log; 065 066/** 067 * A list that displays the fields of a request parameter given 068 * <code>{@link org.opencms.search.fields.CmsLuceneFieldConfiguration}</code> ("fieldconfiguration"). 069 * 070 * This list is no stand-alone page but has to be embedded in another dialog 071 * (see <code> {@link org.opencms.workplace.tools.searchindex.A_CmsEmbeddedListDialog}</code>. <p> 072 * 073 * @since 6.5.5 074 */ 075public class CmsFieldsList extends A_CmsEmbeddedListDialog { 076 077 /** Standard list button location. */ 078 public static final String ICON_FALSE = "list/multi_deactivate.png"; 079 080 /** Standard list button location. */ 081 public static final String ICON_TRUE = "list/multi_activate.png"; 082 083 /** list action id constant. */ 084 public static final String LIST_ACTION_EDIT = "ae"; 085 086 /** list action id constant. */ 087 public static final String LIST_ACTION_EXCERPT_FALSE = "aef"; 088 089 /** list action id constant. */ 090 public static final String LIST_ACTION_EXCERPT_TRUE = "aet"; 091 092 /** list action id constant. */ 093 public static final String LIST_ACTION_INDEX_FALSE = "aif"; 094 095 /** list action id constant. */ 096 public static final String LIST_ACTION_INDEX_TRUE = "ait"; 097 098 /** list action id constant. */ 099 public static final String LIST_ACTION_MAPPING = "am"; 100 101 /** list action id constant. */ 102 public static final String LIST_ACTION_OVERVIEW_FIELD = "aof"; 103 104 /** list action id constant. */ 105 public static final String LIST_ACTION_STORE_FALSE = "asf"; 106 107 /** list action id constant. */ 108 public static final String LIST_ACTION_STORE_TRUE = "ast"; 109 110 /** list column id constant. */ 111 public static final String LIST_COLUMN_BOOST = "cb"; 112 113 /** list column id constant. */ 114 public static final String LIST_COLUMN_DEFAULT = "cd"; 115 116 /** list column id constant. */ 117 public static final String LIST_COLUMN_DISPLAY = "cdi"; 118 119 /** list column id constant. */ 120 public static final String LIST_COLUMN_EDIT = "ced"; 121 122 /** list column id constant. */ 123 public static final String LIST_COLUMN_EXCERPT = "ce"; 124 125 /** list column id constant. */ 126 public static final String LIST_COLUMN_EXCERPT_HIDE = "ceh"; 127 128 /** list column id constant. */ 129 public static final String LIST_COLUMN_ICON = "ci"; 130 131 /** list column id constant. */ 132 public static final String LIST_COLUMN_INDEX = "cx"; 133 134 /** list column id constant. */ 135 public static final String LIST_COLUMN_MAPPING = "cm"; 136 137 /** list column id constant. */ 138 public static final String LIST_COLUMN_NAME = "cn"; 139 140 /** list column id constant. */ 141 public static final String LIST_COLUMN_STORE = "cs"; 142 143 /** list column id constant. */ 144 public static final String LIST_COLUMN_STORE_HIDE = "csh"; 145 146 /** list item detail id constant. */ 147 public static final String LIST_DETAIL_FIELD = "df"; 148 149 /** list id constant. */ 150 public static final String LIST_ID = "lsfcf"; 151 152 /** list action id constant. */ 153 public static final String LIST_MACTION_DELETEFIELD = "mad"; 154 155 /** The path to the fieldconfiguration list icon. */ 156 protected static final String LIST_ICON_FIELD_EDIT = "tools/searchindex/icons/small/fieldconfiguration-editfield.png"; 157 158 /** The log object for this class. */ 159 private static final Log LOG = CmsLog.getLog(CmsFieldsList.class); 160 161 /** Stores the value of the request parameter for the search index source name. */ 162 private String m_paramFieldconfiguration; 163 164 /** 165 * Public constructor.<p> 166 * 167 * @param jsp an initialized JSP action element 168 */ 169 public CmsFieldsList(CmsJspActionElement jsp) { 170 171 this(jsp, LIST_ID, Messages.get().container(Messages.GUI_LIST_FIELDS_NAME_0)); 172 } 173 174 /** 175 * Public constructor.<p> 176 * 177 * @param jsp an initialized JSP action element 178 * @param listId the id of the list 179 * @param listName the list name 180 */ 181 public CmsFieldsList(CmsJspActionElement jsp, String listId, CmsMessageContainer listName) { 182 183 this(jsp, listId, listName, LIST_COLUMN_NAME, CmsListOrderEnum.ORDER_ASCENDING, null); 184 } 185 186 /** 187 * Public constructor.<p> 188 * 189 * @param jsp an initialized JSP action element 190 * @param listId the id of the displayed list 191 * @param listName the name of the list 192 * @param sortedColId the a priory sorted column 193 * @param sortOrder the order of the sorted column 194 * @param searchableColId the column to search into 195 */ 196 public CmsFieldsList( 197 CmsJspActionElement jsp, 198 String listId, 199 CmsMessageContainer listName, 200 String sortedColId, 201 CmsListOrderEnum sortOrder, 202 String searchableColId) { 203 204 super(jsp, listId, listName, sortedColId, sortOrder, searchableColId); 205 206 } 207 208 /** 209 * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions() 210 */ 211 @Override 212 public void executeListMultiActions() { 213 214 CmsSearchManager searchManager = OpenCms.getSearchManager(); 215 if (getParamListAction().equals(LIST_MACTION_DELETEFIELD)) { 216 // execute the delete multiaction 217 Iterator<CmsListItem> itItems = getSelectedItems().iterator(); 218 CmsListItem listItem; 219 CmsLuceneField field; 220 List<CmsSearchField> deleteFields = new ArrayList<CmsSearchField>(); 221 List<CmsSearchField> fields = searchManager.getFieldConfiguration(m_paramFieldconfiguration).getFields(); 222 Iterator<CmsSearchField> itFields; 223 224 while (itItems.hasNext()) { 225 listItem = itItems.next(); 226 itFields = fields.iterator(); 227 while (itFields.hasNext()) { 228 String item = (String)listItem.get(LIST_COLUMN_NAME); 229 CmsLuceneField curField = (CmsLuceneField)itFields.next(); 230 String fieldName = curField.getName(); 231 if (item.equals(fieldName)) { 232 deleteFields.add(curField); 233 } 234 } 235 236 } 237 238 itFields = deleteFields.iterator(); 239 while (itFields.hasNext()) { 240 field = (CmsLuceneField)itFields.next(); 241 searchManager.removeSearchFieldConfigurationField( 242 searchManager.getFieldConfiguration(m_paramFieldconfiguration), 243 field); 244 } 245 246 refreshList(); 247 if (checkWriteConfiguration(fields)) { 248 writeConfiguration(false); 249 } 250 } 251 listSave(); 252 } 253 254 /** 255 * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions() 256 */ 257 @Override 258 public void executeListSingleActions() throws ServletException, IOException { 259 260 String field = getSelectedItem().getId(); 261 Map<String, String[]> params = new HashMap<String, String[]>(); 262 String action = getParamListAction(); 263 264 I_CmsSearchFieldConfiguration fieldConfig = OpenCms.getSearchManager().getFieldConfiguration( 265 m_paramFieldconfiguration); 266 Iterator<CmsSearchField> itFields = fieldConfig.getFields().iterator(); 267 CmsLuceneField fieldObject = null; 268 while (itFields.hasNext()) { 269 CmsLuceneField curField = (CmsLuceneField)itFields.next(); 270 if (curField.getName().equals(field)) { 271 fieldObject = curField; 272 } 273 } 274 275 params.put(A_CmsFieldDialog.PARAM_FIELD, new String[] {field}); 276 params.put(A_CmsFieldDialog.PARAM_FIELDCONFIGURATION, new String[] {m_paramFieldconfiguration}); 277 params.put(PARAM_ACTION, new String[] {DIALOG_INITIAL}); 278 params.put(PARAM_STYLE, new String[] {CmsToolDialog.STYLE_NEW}); 279 if (action.equals(LIST_ACTION_EDIT)) { 280 // forward to the edit indexsource screen 281 getToolManager().jspForwardTool( 282 this, 283 "/searchindex/fieldconfigurations/fieldconfiguration/field/edit", 284 params); 285 } else if (action.equals(LIST_ACTION_MAPPING)) { 286 // forward to the new mapping screen 287 getToolManager().jspForwardTool( 288 this, 289 "/searchindex/fieldconfigurations/fieldconfiguration/field/newmapping", 290 params); 291 } else if (action.equals(LIST_ACTION_OVERVIEW_FIELD)) { 292 // forward to the field configuration overview screen 293 getToolManager().jspForwardTool(this, "/searchindex/fieldconfigurations/fieldconfiguration/field", params); 294 } else if (action.equals(LIST_ACTION_EXCERPT_FALSE)) { 295 // execute the excerpt false action 296 if (fieldObject != null) { 297 fieldObject.setInExcerpt(true); 298 writeConfiguration(true); 299 } 300 } else if (action.equals(LIST_ACTION_INDEX_FALSE)) { 301 // execute the excerpt false action 302 if (fieldObject != null) { 303 fieldObject.setIndexed(true); 304 writeConfiguration(true); 305 } 306 } else if (action.equals(LIST_ACTION_STORE_FALSE)) { 307 // execute the excerpt false action 308 if (fieldObject != null) { 309 fieldObject.setStored(true); 310 writeConfiguration(true); 311 } 312 } else if (action.equals(LIST_ACTION_EXCERPT_TRUE)) { 313 // execute the excerpt false action 314 if (fieldObject != null) { 315 fieldObject.setInExcerpt(false); 316 writeConfiguration(true); 317 } 318 } else if (action.equals(LIST_ACTION_INDEX_TRUE)) { 319 // execute the excerpt false action 320 if (fieldObject != null) { 321 fieldObject.setIndexed(false); 322 writeConfiguration(true); 323 } 324 } else if (action.equals(LIST_ACTION_STORE_TRUE)) { 325 // execute the excerpt false action 326 if (fieldObject != null) { 327 fieldObject.setStored(false); 328 writeConfiguration(true); 329 } 330 } 331 listSave(); 332 } 333 334 /** 335 * Returns the request parameter "fieldconfiguration".<p> 336 * 337 * @return the request parameter "fieldconfiguration" 338 */ 339 public String getParamFieldconfiguration() { 340 341 return m_paramFieldconfiguration; 342 } 343 344 /** 345 * Sets the request parameter "fieldconfiguration". <p> 346 * 347 * Method intended for workplace-properietary automatic filling of 348 * request parameter values to dialogs, not for manual invocation. <p> 349 * 350 * @param fieldconfiguration the request parameter "fieldconfiguration" to set 351 */ 352 public void setParamFieldconfiguration(String fieldconfiguration) { 353 354 m_paramFieldconfiguration = fieldconfiguration; 355 } 356 357 /** 358 * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String) 359 */ 360 @Override 361 protected void fillDetails(String detailId) { 362 363 // get content 364 List<CmsListItem> items = getList().getAllContent(); 365 Iterator<CmsListItem> itItems = items.iterator(); 366 CmsListItem item; 367 while (itItems.hasNext()) { 368 item = itItems.next(); 369 if (detailId.equals(LIST_DETAIL_FIELD)) { 370 fillDetailField(item, detailId); 371 } 372 } 373 } 374 375 /** 376 * @see org.opencms.workplace.list.A_CmsListDialog#getListItems() 377 */ 378 @Override 379 protected List<CmsListItem> getListItems() { 380 381 List<CmsListItem> result = new ArrayList<CmsListItem>(); 382 // get content 383 List<CmsSearchField> fields = getFields(); 384 Iterator<CmsSearchField> itFields = fields.iterator(); 385 CmsLuceneField field; 386 while (itFields.hasNext()) { 387 field = (CmsLuceneField)itFields.next(); 388 CmsListItem item = getList().newItem(field.getName()); 389 String defaultValue = field.getDefaultValue(); 390 if (defaultValue == null) { 391 defaultValue = "-"; 392 } 393 item.set(LIST_COLUMN_NAME, field.getName()); 394 item.set(LIST_COLUMN_DISPLAY, resolveMacros(field.getDisplayName())); 395 item.set(LIST_COLUMN_INDEX, field.getIndexed()); 396 item.set(LIST_COLUMN_EXCERPT_HIDE, Boolean.valueOf(field.isInExcerpt())); 397 item.set(LIST_COLUMN_STORE_HIDE, Boolean.valueOf(field.isStored())); 398 item.set(LIST_COLUMN_DEFAULT, defaultValue); 399 400 result.add(item); 401 } 402 return result; 403 } 404 405 /** 406 * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata) 407 */ 408 @Override 409 protected void setColumns(CmsListMetadata metadata) { 410 411 // create column for edit 412 CmsListColumnDefinition editCol = new CmsListColumnDefinition(LIST_COLUMN_EDIT); 413 editCol.setName(Messages.get().container(Messages.GUI_LIST_FIELD_COL_EDIT_NAME_0)); 414 editCol.setHelpText(Messages.get().container(Messages.GUI_LIST_FIELD_COL_EDIT_NAME_HELP_0)); 415 editCol.setWidth("20"); 416 editCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT); 417 editCol.setSorteable(false); 418 // add dummy icon 419 CmsListDirectAction editAction = new CmsListDirectAction(LIST_ACTION_EDIT); 420 editAction.setName(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_EDIT_NAME_0)); 421 editAction.setHelpText(Messages.get().container(Messages.GUI_LIST_FIELD_COL_EDIT_NAME_HELP_0)); 422 editAction.setIconPath(LIST_ICON_FIELD_EDIT); 423 editCol.addDirectAction(editAction); 424 // add it to the list definition 425 metadata.addColumn(editCol); 426 427 // create column for new mapping 428 CmsListColumnDefinition mappingCol = new CmsListColumnDefinition(LIST_COLUMN_MAPPING); 429 mappingCol.setName(Messages.get().container(Messages.GUI_LIST_FIELD_COL_MAPPING_0)); 430 mappingCol.setHelpText(Messages.get().container(Messages.GUI_LIST_FIELD_COL_MAPPING_HELP_0)); 431 mappingCol.setWidth("20"); 432 mappingCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT); 433 mappingCol.setSorteable(false); 434 // add mapping action 435 CmsListDirectAction mappingAction = new CmsListDirectAction(LIST_ACTION_MAPPING); 436 mappingAction.setName(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_MAPPING_0)); 437 mappingAction.setHelpText(Messages.get().container(Messages.GUI_LIST_FIELD_COL_MAPPING_HELP_0)); 438 mappingAction.setIconPath(ICON_ADD); 439 mappingCol.addDirectAction(mappingAction); 440 // add it to the list definition 441 metadata.addColumn(mappingCol); 442 443 // add column for name 444 CmsListColumnDefinition nameCol = new CmsListColumnDefinition(LIST_COLUMN_NAME); 445 nameCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT); 446 nameCol.setName(Messages.get().container(Messages.GUI_LIST_SEARCHINDEX_COL_NAME_0)); 447 nameCol.setSorteable(true); 448 nameCol.setWidth("45%"); 449 // add overview action 450 CmsListDefaultAction overviewAction = new CmsListDefaultAction(LIST_ACTION_OVERVIEW_FIELD); 451 overviewAction.setName(Messages.get().container(Messages.GUI_LIST_FIELD_COL_OVERVIEW_NAME_0)); 452 overviewAction.setHelpText(Messages.get().container(Messages.GUI_LIST_FIELD_COL_OVERVIEW_NAME_HELP_0)); 453 nameCol.addDefaultAction(overviewAction); 454 metadata.addColumn(nameCol); 455 456 // add column for display 457 CmsListColumnDefinition displayCol = new CmsListColumnDefinition(LIST_COLUMN_DISPLAY); 458 displayCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT); 459 displayCol.setName(Messages.get().container(Messages.GUI_LIST_FIELD_COL_DISPLAY_0)); 460 displayCol.setWidth("35%"); 461 metadata.addColumn(displayCol); 462 463 // add hide column for store 464 CmsListColumnDefinition storeHideCol = new CmsListColumnDefinition(LIST_COLUMN_STORE_HIDE); 465 storeHideCol.setVisible(false); 466 metadata.addColumn(storeHideCol); 467 468 // add hide column for excerpt 469 CmsListColumnDefinition excerptHideCol = new CmsListColumnDefinition(LIST_COLUMN_EXCERPT_HIDE); 470 excerptHideCol.setVisible(false); 471 metadata.addColumn(excerptHideCol); 472 473 // add column for store 474 CmsListColumnDefinition storeCol = new CmsListColumnDefinition(LIST_COLUMN_STORE); 475 storeCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 476 storeCol.setName(Messages.get().container(Messages.GUI_LIST_FIELD_COL_STORE_0)); 477 // true action 478 CmsListDirectAction storeTrueAction = new CmsListDirectAction(LIST_ACTION_STORE_TRUE) { 479 480 /** 481 * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible() 482 */ 483 @Override 484 public boolean isVisible() { 485 486 if (getItem() != null) { 487 return ((Boolean)getItem().get(LIST_COLUMN_STORE_HIDE)).booleanValue(); 488 } 489 return super.isVisible(); 490 } 491 }; 492 storeTrueAction.setName(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_TRUE_NAME_0)); 493 storeTrueAction.setHelpText(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_TRUE_HELP_0)); 494 storeTrueAction.setConfirmationMessage(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_TRUE_CONF_0)); 495 storeTrueAction.setIconPath(ICON_TRUE); 496 // false action 497 CmsListDirectAction storeFalseAction = new CmsListDirectAction(LIST_ACTION_STORE_FALSE) { 498 499 /** 500 * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible() 501 */ 502 @Override 503 public boolean isVisible() { 504 505 if (getItem() != null) { 506 return !((Boolean)getItem().get(LIST_COLUMN_STORE_HIDE)).booleanValue(); 507 } 508 return super.isVisible(); 509 } 510 }; 511 storeFalseAction.setName(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_FALSE_NAME_0)); 512 storeFalseAction.setHelpText(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_FALSE_HELP_0)); 513 storeFalseAction.setConfirmationMessage(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_FALSE_CONF_0)); 514 storeFalseAction.setIconPath(ICON_FALSE); 515 516 storeCol.addDirectAction(storeTrueAction); 517 storeCol.addDirectAction(storeFalseAction); 518 metadata.addColumn(storeCol); 519 520 // add colum for excerpt 521 CmsListColumnDefinition excerptCol = new CmsListColumnDefinition(LIST_COLUMN_EXCERPT); 522 excerptCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 523 excerptCol.setName(Messages.get().container(Messages.GUI_LIST_FIELD_COL_EXCERPT_0)); 524 // true action 525 CmsListDirectAction excerptTrueAction = new CmsListDirectAction(LIST_ACTION_EXCERPT_TRUE) { 526 527 /** 528 * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible() 529 */ 530 @Override 531 public boolean isVisible() { 532 533 if (getItem() != null) { 534 return ((Boolean)getItem().get(LIST_COLUMN_EXCERPT_HIDE)).booleanValue(); 535 } 536 return super.isVisible(); 537 } 538 }; 539 excerptTrueAction.setName(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_TRUE_NAME_0)); 540 excerptTrueAction.setHelpText(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_TRUE_HELP_0)); 541 excerptTrueAction.setConfirmationMessage(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_TRUE_CONF_0)); 542 excerptTrueAction.setIconPath(ICON_TRUE); 543 // false action 544 CmsListDirectAction excerptFalseAction = new CmsListDirectAction(LIST_ACTION_EXCERPT_FALSE) { 545 546 /** 547 * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#isVisible() 548 */ 549 @Override 550 public boolean isVisible() { 551 552 if (getItem() != null) { 553 return !((Boolean)getItem().get(LIST_COLUMN_EXCERPT_HIDE)).booleanValue(); 554 } 555 return super.isVisible(); 556 } 557 }; 558 excerptFalseAction.setName(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_FALSE_NAME_0)); 559 excerptFalseAction.setHelpText(Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_FALSE_HELP_0)); 560 excerptFalseAction.setConfirmationMessage( 561 Messages.get().container(Messages.GUI_LIST_FIELD_ACTION_FALSE_CONF_0)); 562 excerptFalseAction.setIconPath(ICON_FALSE); 563 564 excerptCol.addDirectAction(excerptTrueAction); 565 excerptCol.addDirectAction(excerptFalseAction); 566 metadata.addColumn(excerptCol); 567 568 // add column for index 569 CmsListColumnDefinition indexCol = new CmsListColumnDefinition(LIST_COLUMN_INDEX); 570 indexCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 571 indexCol.setName(Messages.get().container(Messages.GUI_LIST_FIELD_COL_INDEX_0)); 572 indexCol.setWidth("10%"); 573 metadata.addColumn(indexCol); 574 575 // add column for boost 576 CmsListColumnDefinition boostCol = new CmsListColumnDefinition(LIST_COLUMN_BOOST); 577 boostCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 578 boostCol.setName(Messages.get().container(Messages.GUI_LIST_FIELD_COL_BOOST_0)); 579 boostCol.setWidth("5%"); 580 metadata.addColumn(boostCol); 581 582 // add column for default 583 CmsListColumnDefinition defaultCol = new CmsListColumnDefinition(LIST_COLUMN_DEFAULT); 584 defaultCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 585 defaultCol.setName(Messages.get().container(Messages.GUI_LIST_FIELD_COL_DEFAULT_0)); 586 defaultCol.setWidth("5%"); 587 metadata.addColumn(defaultCol); 588 } 589 590 /** 591 * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata) 592 */ 593 @Override 594 protected void setIndependentActions(CmsListMetadata metadata) { 595 596 // add field configuration details 597 CmsListItemDetails configDetails = new CmsListItemDetails(LIST_DETAIL_FIELD); 598 configDetails.setAtColumn(LIST_COLUMN_NAME); 599 configDetails.setVisible(false); 600 configDetails.setShowActionName(Messages.get().container(Messages.GUI_LIST_FIELD_DETAIL_MAPPINGS_SHOW_0)); 601 configDetails.setShowActionHelpText( 602 Messages.get().container(Messages.GUI_LIST_FIELD_DETAIL_MAPPINGS_SHOW_HELP_0)); 603 configDetails.setHideActionName(Messages.get().container(Messages.GUI_LIST_FIELD_DETAIL_MAPPINGS_HIDE_0)); 604 configDetails.setHideActionHelpText( 605 Messages.get().container(Messages.GUI_LIST_FIELD_DETAIL_MAPPINGS_HIDE_HELP_0)); 606 configDetails.setName(Messages.get().container(Messages.GUI_LIST_FIELD_DETAIL_MAPPINGS_NAME_0)); 607 configDetails.setFormatter( 608 new CmsListItemDetailsFormatter(Messages.get().container(Messages.GUI_LIST_FIELD_DETAIL_MAPPINGS_NAME_0))); 609 metadata.addItemDetails(configDetails); 610 } 611 612 /** 613 * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata) 614 */ 615 @Override 616 protected void setMultiActions(CmsListMetadata metadata) { 617 618 // add add multi action 619 CmsListMultiAction deleteMultiAction = new CmsListMultiAction(LIST_MACTION_DELETEFIELD); 620 deleteMultiAction.setName(Messages.get().container(Messages.GUI_LIST_FIELD_MACTION_DELETEFIELD_NAME_0)); 621 deleteMultiAction.setHelpText( 622 Messages.get().container(Messages.GUI_LIST_FIELD_MACTION_DELETEFIELD_NAME_HELP_0)); 623 deleteMultiAction.setConfirmationMessage( 624 Messages.get().container(Messages.GUI_LIST_FIELD_MACTION_DELETEFIELD_CONF_0)); 625 deleteMultiAction.setIconPath(ICON_MULTI_DELETE); 626 metadata.addMultiAction(deleteMultiAction); 627 } 628 629 /** 630 * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters() 631 */ 632 @Override 633 protected void validateParamaters() throws Exception { 634 635 // will throw NPE if something wrong 636 OpenCms.getSearchManager().getFieldConfiguration(getParamFieldconfiguration()).getFields(); 637 } 638 639 /** 640 * Writes the updated search configuration back to the XML 641 * configuration file and refreshes the complete list.<p> 642 * 643 * @param refresh if true, the list items are refreshed 644 */ 645 protected void writeConfiguration(boolean refresh) { 646 647 // update the XML configuration 648 OpenCms.writeConfiguration(CmsSearchConfiguration.class); 649 if (refresh) { 650 refreshList(); 651 } 652 } 653 654 /** 655 * Checks the configuration to write.<p> 656 * 657 * @param fields list of fields of the current field configuration 658 * @return true if configuration is valid, otherwise false 659 */ 660 private boolean checkWriteConfiguration(List<CmsSearchField> fields) { 661 662 if (fields == null) { 663 return false; 664 } 665 Iterator<CmsSearchField> itFields = fields.iterator(); 666 while (itFields.hasNext()) { 667 CmsLuceneField curField = (CmsLuceneField)itFields.next(); 668 if (curField.getMappings().isEmpty()) { 669 return false; 670 } 671 } 672 return true; 673 } 674 675 /** 676 * Fills details of the field into the given item. <p> 677 * 678 * @param item the list item to fill 679 * @param detailId the id for the detail to fill 680 */ 681 private void fillDetailField(CmsListItem item, String detailId) { 682 683 StringBuffer html = new StringBuffer(); 684 // search for the corresponding A_CmsSearchIndex: 685 String idxFieldName = (String)item.get(LIST_COLUMN_NAME); 686 687 List<CmsSearchField> fields = OpenCms.getSearchManager().getFieldConfiguration( 688 m_paramFieldconfiguration).getFields(); 689 Iterator<CmsSearchField> itFields = fields.iterator(); 690 CmsLuceneField idxField = null; 691 while (itFields.hasNext()) { 692 CmsLuceneField curField = (CmsLuceneField)itFields.next(); 693 if (curField.getName().equals(idxFieldName)) { 694 idxField = curField; 695 } 696 } 697 698 if (idxField != null) { 699 html.append("<ul>\n"); 700 Iterator<I_CmsSearchFieldMapping> itMappings = idxField.getMappings().iterator(); 701 while (itMappings.hasNext()) { 702 CmsSearchFieldMapping mapping = (CmsSearchFieldMapping)itMappings.next(); 703 html.append(" <li>\n").append(" "); 704 html.append(mapping.getType().toString()); 705 if (CmsStringUtil.isNotEmpty(mapping.getParam())) { 706 html.append("=").append(mapping.getParam()).append("\n"); 707 } 708 html.append(" </li>"); 709 } 710 html.append("</ul>\n"); 711 } 712 item.set(detailId, html.toString()); 713 } 714 715 /** 716 * Returns the configured fields of the current field configuration. 717 * 718 * @return the configured fields of the current field configuration 719 */ 720 private List<CmsSearchField> getFields() { 721 722 CmsSearchManager manager = OpenCms.getSearchManager(); 723 I_CmsSearchFieldConfiguration fieldConfig = manager.getFieldConfiguration(getParamFieldconfiguration()); 724 List<CmsSearchField> result; 725 if (fieldConfig != null) { 726 result = fieldConfig.getFields(); 727 } else { 728 result = Collections.emptyList(); 729 if (LOG.isErrorEnabled()) { 730 LOG.error( 731 Messages.get().getBundle().key( 732 Messages.ERR_SEARCHINDEX_EDIT_MISSING_PARAM_1, 733 A_CmsFieldConfigurationDialog.PARAM_FIELDCONFIGURATION)); 734 } 735 } 736 return result; 737 } 738}