001/*
002 *  Copyright 2015 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.cms.search.model;
017
018import java.util.Locale;
019
020import org.ametys.cms.repository.Content;
021import org.ametys.cms.search.SearchField;
022
023/**
024 * Represents a Field to be returned by a search.
025 */
026public interface ResultField extends Field
027{
028    
029    /**
030     * Get the result field ID.
031     * @return the result field ID.
032     */
033    String getId();
034    
035    /**
036     * Get the value represented by this field in the given result content.
037     * @param content the result content.
038     * @param defaultLocale the default locale for localized value if the content's language is null
039     * @return the content field value (cast to the appropriate object).
040     */
041    Object getValue(Content content, Locale defaultLocale);
042    
043    /**
044     * Get the value represented by this field in the given result content.
045     * @param content the result content.
046     * @param defaultLocale the default locale for localized value if the content's language is null
047     * @return the content field value (cast to the appropriate object).
048     */
049    default Object getFullValue(Content content, Locale defaultLocale)
050    {
051        // Defaults to the same value.
052        return getValue(content, defaultLocale);
053    }
054    
055    /**
056     * Get the {@link SearchField} representing this result field.
057     * @return The {@link SearchField} representing this result field.
058     */
059    SearchField getSearchField();
060}