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, 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.search.fields; 029 030import org.opencms.util.A_CmsModeIntEnumeration; 031import org.opencms.util.CmsStringUtil; 032 033/** 034 * Describes a possible mapping type for a piece of content used in building a search index.<p> 035 * 036 * The mapping type is responsible to select which content from the OpenCms resource is used for 037 * a field.<p> 038 * 039 * @since 7.0.0 040 */ 041public final class CmsSearchFieldMappingType extends A_CmsModeIntEnumeration { 042 043 /** The "dynamic" mapping type, this is required if a special class is used to process the field mapping value. */ 044 public static final CmsSearchFieldMappingType ATTRIBUTE = new CmsSearchFieldMappingType(5); 045 046 /** The "content" mapping type, maps the content of the resource (no parameters required). */ 047 public static final CmsSearchFieldMappingType CONTENT = new CmsSearchFieldMappingType(0); 048 049 /** The "dynamic" mapping type, this is required if a special class is used to process the field mapping value. */ 050 public static final CmsSearchFieldMappingType DYNAMIC = new CmsSearchFieldMappingType(4); 051 052 /** The "item" mapping type, maps the selected content item of the content. */ 053 public static final CmsSearchFieldMappingType ITEM = new CmsSearchFieldMappingType(3); 054 055 /** The "property" mapping type, maps the selected property value of the resource. */ 056 public static final CmsSearchFieldMappingType PROPERTY = new CmsSearchFieldMappingType(1); 057 058 /** The "property-search" mapping type, maps the selected property value of the resource with search upwards. */ 059 public static final CmsSearchFieldMappingType PROPERTY_SEARCH = new CmsSearchFieldMappingType(2); 060 061 /** ID required for safe serialization. */ 062 private static final long serialVersionUID = 1959271063305411797L; 063 064 /** String constant for the "attribute" type. */ 065 private static final String STR_ATTRIBUTE = "attribute"; 066 067 /** String constant for the "content" type. */ 068 private static final String STR_CONTENT = "content"; 069 070 /** String constant for the "dynamic" type. */ 071 private static final String STR_DYNAMIC = "dynamic"; 072 073 /** String constant for the "item" type. */ 074 private static final String STR_ITEM = "item"; 075 076 /** String constant for the "property" type. */ 077 private static final String STR_PROPERTY = "property"; 078 079 /** String constant for the "property-search" type. */ 080 private static final String STR_PROPERTY_SEARCH = "property-search"; 081 082 /** 083 * Hides the public constructor.<p> 084 * 085 * @param mode the mode constant to use 086 */ 087 private CmsSearchFieldMappingType(int mode) { 088 089 super(mode); 090 } 091 092 /** 093 * Returns the matching field mapping type, or <code>null</code> if the given value is 094 * not a valid mapping type name.<p> 095 * 096 * @param value the name of the mapping type 097 * 098 * @return the matching field mapping type 099 */ 100 public static CmsSearchFieldMappingType valueOf(String value) { 101 102 if (CmsStringUtil.isEmptyOrWhitespaceOnly(value)) { 103 return null; 104 } 105 value = value.trim().toLowerCase(); 106 if (STR_CONTENT.equals(value)) { 107 return CONTENT; 108 } else if (STR_PROPERTY.equals(value)) { 109 return PROPERTY; 110 } else if (STR_PROPERTY_SEARCH.equals(value)) { 111 return PROPERTY_SEARCH; 112 } else if (STR_ITEM.equals(value)) { 113 return ITEM; 114 } else if (STR_DYNAMIC.equals(value)) { 115 return DYNAMIC; 116 } else if (STR_ATTRIBUTE.equals(value)) { 117 return ATTRIBUTE; 118 } 119 return null; 120 } 121 122 /** 123 * @see org.opencms.util.A_CmsModeIntEnumeration#toString() 124 */ 125 @Override 126 public String toString() { 127 128 switch (getMode()) { 129 case 1: 130 return STR_PROPERTY; 131 case 2: 132 return STR_PROPERTY_SEARCH; 133 case 3: 134 return STR_ITEM; 135 case 4: 136 return STR_DYNAMIC; 137 case 5: 138 return STR_ATTRIBUTE; 139 case 0: 140 default: 141 return STR_CONTENT; 142 } 143 } 144}