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.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 javax.servlet.http.HttpServletRequest; 041import javax.servlet.http.HttpServletResponse; 042import javax.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 * Creates the dialog HTML for all defined widgets of the named dialog (page).<p> 076 * 077 * This overwrites the method from the super class to create a layout variation for the widgets.<p> 078 * 079 * @param dialog the dialog (page) to get the HTML for 080 * @return the dialog HTML for all defined widgets of the named dialog (page) 081 */ 082 @Override 083 protected String createDialogHtml(String dialog) { 084 085 StringBuffer result = new StringBuffer(1024); 086 087 result.append(createWidgetTableStart()); 088 // show error header once if there were validation errors 089 result.append(createWidgetErrorHeader()); 090 091 if (dialog.equals(PAGES[0])) { 092 // create the widgets for the first dialog page 093 result.append(dialogBlockStart(key(Messages.GUI_LABEL_FIELD_BLOCK_SETTINGS_0))); 094 result.append(createWidgetTableStart()); 095 result.append(createDialogRowsHtml(0, 2)); 096 result.append(createWidgetTableEnd()); 097 result.append(dialogBlockEnd()); 098 } 099 100 result.append(createWidgetTableEnd()); 101 return result.toString(); 102 } 103 104 /** 105 * Creates the list of widgets for this dialog.<p> 106 */ 107 @Override 108 protected void defineWidgets() { 109 110 super.defineWidgets(); 111 112 // widgets to display 113 // new indexsource 114 addWidget( 115 new CmsWidgetDialogParameter(this, "type", PAGES[0], new CmsSelectWidget(getTypeWidgetConfiguration()))); 116 addWidget(new CmsWidgetDialogParameter(m_mapping, "param", "", PAGES[0], new CmsInputWidget(), 0, 1)); 117 addWidget(new CmsWidgetDialogParameter(m_mapping, "defaultValue", "", PAGES[0], new CmsInputWidget(), 0, 1)); 118 } 119 120 /** 121 * Sets the mapping type of the mapping.<p> 122 * 123 * @param type String value of the mapping type 124 */ 125 public void setType(String type) { 126 127 m_mapping.setType(type); 128 } 129 130 /** 131 * Returns the String value of the mapping type.<p> 132 * 133 * @return String value of the mapping type 134 */ 135 public String getType() { 136 137 if ((m_mapping != null) && (m_mapping.getType() != null)) { 138 return m_mapping.getType().toString(); 139 } 140 return ""; 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}