001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.search.fields.CmsSearchFieldMappingType; 032import org.opencms.widgets.CmsInputWidget; 033import org.opencms.widgets.CmsSelectWidget; 034import org.opencms.widgets.CmsSelectWidgetOption; 035import org.opencms.workplace.CmsWidgetDialogParameter; 036 037import java.util.ArrayList; 038import java.util.List; 039 040import jakarta.servlet.http.HttpServletRequest; 041import jakarta.servlet.http.HttpServletResponse; 042import jakarta.servlet.jsp.PageContext; 043 044/** 045 * 046 * Dialog to edit new or existing mapping in the administration view.<p> 047 * 048 * @since 6.5.5 049 */ 050public class CmsEditMappingDialog extends A_CmsMappingDialog { 051 052 /** 053 * Public constructor with JSP action element.<p> 054 * 055 * @param jsp the jsp action element 056 */ 057 public CmsEditMappingDialog(CmsJspActionElement jsp) { 058 059 super(jsp); 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 public CmsEditMappingDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 070 071 super(context, req, res); 072 } 073 074 /** 075 * Returns the String value of the mapping type.<p> 076 * 077 * @return String value of the mapping type 078 */ 079 public String getType() { 080 081 if ((m_mapping != null) && (m_mapping.getType() != null)) { 082 return m_mapping.getType().toString(); 083 } 084 return ""; 085 } 086 087 /** 088 * Sets the mapping type of the mapping.<p> 089 * 090 * @param type String value of the mapping type 091 */ 092 public void setType(String type) { 093 094 m_mapping.setType(type); 095 } 096 097 /** 098 * Creates the dialog HTML for all defined widgets of the named dialog (page).<p> 099 * 100 * This overwrites the method from the super class to create a layout variation for the widgets.<p> 101 * 102 * @param dialog the dialog (page) to get the HTML for 103 * @return the dialog HTML for all defined widgets of the named dialog (page) 104 */ 105 @Override 106 protected String createDialogHtml(String dialog) { 107 108 StringBuffer result = new StringBuffer(1024); 109 110 result.append(createWidgetTableStart()); 111 // show error header once if there were validation errors 112 result.append(createWidgetErrorHeader()); 113 114 if (dialog.equals(PAGES[0])) { 115 // create the widgets for the first dialog page 116 result.append(dialogBlockStart(key(Messages.GUI_LABEL_FIELD_BLOCK_SETTINGS_0))); 117 result.append(createWidgetTableStart()); 118 result.append(createDialogRowsHtml(0, 2)); 119 result.append(createWidgetTableEnd()); 120 result.append(dialogBlockEnd()); 121 } 122 123 result.append(createWidgetTableEnd()); 124 return result.toString(); 125 } 126 127 /** 128 * Creates the list of widgets for this dialog.<p> 129 */ 130 @Override 131 protected void defineWidgets() { 132 133 super.defineWidgets(); 134 135 // widgets to display 136 // new indexsource 137 addWidget( 138 new CmsWidgetDialogParameter(this, "type", PAGES[0], new CmsSelectWidget(getTypeWidgetConfiguration()))); 139 addWidget(new CmsWidgetDialogParameter(m_mapping, "param", "", PAGES[0], new CmsInputWidget(), 0, 1)); 140 addWidget(new CmsWidgetDialogParameter(m_mapping, "defaultValue", "", PAGES[0], new CmsInputWidget(), 0, 1)); 141 } 142 143 /** 144 * Returns a list of CmsSearchFieldMappingTypes for the type select box.<p> 145 * 146 * @return a list of CmsSearchFieldMappingTypes 147 */ 148 private List<CmsSelectWidgetOption> getTypeWidgetConfiguration() { 149 150 List<CmsSelectWidgetOption> result = new ArrayList<CmsSelectWidgetOption>(); 151 result.add(new CmsSelectWidgetOption(CmsSearchFieldMappingType.CONTENT.toString(), true)); 152 result.add(new CmsSelectWidgetOption(CmsSearchFieldMappingType.PROPERTY.toString(), false)); 153 result.add(new CmsSelectWidgetOption(CmsSearchFieldMappingType.PROPERTY_SEARCH.toString(), false)); 154 result.add(new CmsSelectWidgetOption(CmsSearchFieldMappingType.ITEM.toString(), false)); 155 return result; 156 } 157}